Acumatica提供了两种不同的编程接口,分别为Acumatica API和OData。
Acumatica API是Acumatica独有的API,其使用SOAP和XML格式进行通信。以下是使用Acumatica API从销售订单模块中获取数据的示例代码:
SalesOrder salesOrder = new SalesOrder();
salesOrder.OrderNbr = new StringSearch();
salesOrder.OrderNbr.Value = "SO00000001";
SalesOrder salesOrderResult = context.salesorder.Get(salesOrder);
OData是一种开放标准,可与多个数据源(如Microsoft Dynamics 365、Salesforce等)进行通信。以下为使用OData从Acumatica获取所有销售订单的示例代码:
string url = "https://myacumaticasite.com/entity/Default/18.200.001/SalesOrder/";
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(url);
client.DefaultRequestHeaders.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = await client.GetAsync(url);
if (response.IsSuccessStatusCode)
{
string data = await response.Content.ReadAsStringAsync();
JObject resultObject = JObject.Parse(data);
JArray results = (JArray)resultObject["value"];
foreach (JObject result in results)
{
Console.WriteLine(result["OrderNbr"].ToString());
}
}
Acumatica API和OData都有其优缺点,开发人员可以根据自己的需求来选择使用哪种接口。