[英]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,在这里,我们无法理解,
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.