简体   繁体   English

D365 Business Central,我们需要使用C#代码将记录创建到Items中

[英]D365 Business Central, we need to create records into Items using C# code

We need a requirement to create our own C# WebAPI project that will connect Business Central and inserts/updates data into Items.After doing a search, we found that this is possible using Business Central APIs like given in the link below.https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-develop-connect-apps我们需要创建我们自己的 C# WebAPI 项目,该项目将连接 Business Central 并将数据插入/更新到 Items 中。搜索后,我们发现可以使用如下链接中给出的 Business Central API 实现。https:// learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-develop-connect-apps

Here, we are not able to understand,在这里,我们无法理解,

  • How should we connect to Business Central?我们应该如何连接到 Business Central?
  • How can we call items API and what the parameters are?我们如何调用项目 API 以及参数是什么?
  • How can we see list of available APIs?我们如何查看可用 API 列表?
  • Why do we need to create other connect apps?为什么我们需要创建其他连接应用程序?

If somebody has the C# code snippet/example please share with us, it will be really helpful for us.如果有人有 C# 代码片段/示例,请与我们分享,这对我们非常有帮助。

OR Are there any SDKs available same as like CRM SDKs?或者是否有与 CRM SDK 相同的可用 SDK?

How should we connect to Business Central?我们应该如何连接到 Business Central?

If you are talking about connecting it to BC using code then you will need the Username and Web Access key of the Business Central user, which is different from the AAD user credentials.如果您正在谈论使用代码将其连接到 BC,那么您将需要 Business Central 用户的用户名和 Web 访问密钥,这与 AAD 用户凭据不同。

How can we call items API and what the parameters are?我们如何调用项目 API 以及参数是什么?

Please find the below sample code which might help you to understand how to call APIs请找到以下示例代码,这可能有助于您了解如何调用 API

    string url = "https://api.businesscentral.dynamics.com/v2.0/<<Your Environment Name>>/api/v1.0/companies(<<GUID of the company for which item/items needs to be retrieved/added/updated>>)/items";
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
    HttpClient httpClient = new HttpClient();

    String username = "<<UserName>>";
    String password = "<<WebAccessKey>>";
    String encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password));

    //Get Request for all Items
    HttpRequestMessage readRequest = new HttpRequestMessage(HttpMethod.Get, url);
    readRequest.Headers.Add("Authorization", "Basic " + encoded);
    HttpResponseMessage readResponse = httpClient.SendAsync(readRequest).Result;
    string content = string.Empty;

    using (StreamReader stream = new StreamReader(readResponse.Content.ReadAsStreamAsync().Result))
    {
        content = stream.ReadToEnd();
    }

    //Get Request for a specific Item

    string specificItemURl = url + "(<<Guid of the item to be reteieved>>)";
    HttpRequestMessage readSpecificRequest = new HttpRequestMessage(HttpMethod.Get, specificItemURl);
    readSpecificRequest.Headers.Add("Authorization", "Basic " + encoded);
    HttpResponseMessage readSpecificResponse = httpClient.SendAsync(readSpecificRequest).Result;
    string specificItem = string.Empty;

    using (StreamReader streamSpecificItem = new StreamReader(readSpecificResponse.Content.ReadAsStreamAsync().Result))
    {
        specificItem = streamSpecificItem.ReadToEnd();
    }

    //Create Request
    string jsonObject = "{'number':'18962-S','displayName':'ATHENS Desk 3','type':'Inventory','itemCategoryId':'6d4e5f4d-8ad1-ea11-bb85-000d3a2a9e6e','itemCategoryCode':'TABLE','blocked':false,'baseUnitOfMeasureId':'354f6647-8ad1-ea11-bb85-000d3a2a9e6e','gtin':'','unitPrice':1000.8,'priceIncludesTax':false,'unitCost':780.7,'taxGroupId':'fc4c5f4d-8ad1-ea11-bb85-000d3a2a9e6e','taxGroupCode':'FURNITURE','baseUnitOfMeasure':{'code':'PCS','displayName':'Piece','symbol':null,'unitConversion':null}}";
    HttpRequestMessage createRequest = new HttpRequestMessage(HttpMethod.Post, url);  
    createRequest.Content = new StringContent(jsonObject, Encoding.UTF8, "application/json");
    createRequest.Headers.Add("Authorization", "Basic " + encoded);
    HttpResponseMessage createResponse = httpClient.SendAsync(createRequest).Result;

How can we see list of available APIs?我们如何查看可用 API 列表?

You will need to login into the Business Central instance with a user who has Administration role.您将需要使用具有管理角色的用户登录到 Business Central 实例。 After logging in Click on Services from the ribbon and then select Web Services.登录后单击功能区中的服务,然后单击 select Web 服务。 You should able to view all the api endpoints.您应该能够查看所有 api 端点。

Hope this helps you in what you are trying to acheive.希望这可以帮助您实现目标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 D365 C#-检索多个并且更新非常慢 - D365 C# - Retrieve Multiple and Updating Very Slow 如何通过 C# 连接到 Azure D365 Odata - How to connect to Azure D365 Odata via C# 使用 Rest 在 Dynamics 365 Business Central 中创建项目 API - Create Item in Dynamics 365 Business Central using Rest API 将现有实体记录(竞争对手)关联到新记录(机会)crm d365 On create message - Associate existing entity records (competitor) to new record (opportunity) crm d365 On create message 在业务流程变更上触发插件(D365 / 9.1) - Trigger Plugin on Business Process flow Change (D365/9.1) 从相交实体 D365 C# 获取相关实体 - Getting related entities from intersect entity D365 C# 无法在无头模式下将文件上传到 D365 Selenium C# - Cannot upload file to D365 in headless mode Selenium C# c# OdataClient:DataServiceActionQuery,如何执行Microsoft Dynamics 365 Business Central 的功能? - c# OdataClient: DataServiceActionQuery, how to execute a function Microsoft Dynamics 365 Business Central? 如何使用C#在Office 365 / OneDrive for Business中创建Word文档 - How can I create a Word document in office 365 / 'OneDrive for Business' using c# 使用 C# 代码从 DYNAMICS 365 crm 检索/获取记录 - Retrieve/fetch records from DYNAMICS 365 crm using C# code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM