我们应该如何连接到 Business Central?
如果您正在谈论使用代码将其连接到 BC,那么您将需要 Business Central 用户的用户名和 Web 访问密钥,这与 AAD 用户凭据不同。
我们如何调用items API以及参数是什么?
请找到下面的示例代码,它可能会帮助您了解如何调用 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;
我们如何查看可用 API 的列表?
您需要使用具有管理角色的用户登录到 Business Central 实例。登录后单击功能区中的服务,然后选择 Web 服务。您应该能够查看所有 api 端点。
希望这对您想要实现的目标有所帮助。