【发布时间】:2021-10-09 18:44:31
【问题描述】:
我正在尝试使用 Acumatia 21R1 中的新 OpenAPI 2.0 设置来创建采购订单收据。我已经测试过创建其他几种类型的记录(例如:StockItems),并且几乎相同的代码可以完美运行。此 Acumatica 实例有多个租户,但没有分支。
我还使用了相同的代码,将其指向具有一个租户和多个分支的 Acumatica 实例,只要我设置了分支,它就可以正常工作。
当我运行它时,我得到“curyid 不能为空”。这让我相信,不知何故,它没有正确确定分支或租户,但如果我使用相同的登录代码,我可以从这些租户中提取数据就好了。我也尝试过直接传递 json 并将 curyid 设置为 USD,但这具有相同的效果。
对我做错了什么有什么想法吗?
private createPOR()
{
string baseURL = "https://acumatica.[good url goes here].com/AcumaticaPWS";
string strLogin = baseURL + "/entity/auth/login";
var client = new RestClient(strLogin);
var request = new RestRequest(Method.POST);
request.AddHeader("Accept", "application/json");
request.AddHeader("Content-Type", "application/json");
string strBody = "{ \"name\": \"admin\", \"password\": \"[proper password]\", \"tenant\": \"PWS Milwaukee\", \"branch\": \"\"}";
request.AddJsonBody(strBody);
IRestResponse response = client.Execute(request);
txtResults.Text = response.Cookies.SingleOrDefault(x => x.Name == ".ASPXAUTH").Value.ToString();
RestResponseCookie sessionCookie = response.Cookies.SingleOrDefault(x => x.Name == ".ASPXAUTH");
// Create the new one for send the data.
string strItems = baseURL + "/entity/Default/20.200.001/PurchaseReceipt";
client = new RestClient(strItems);
request = new RestRequest(Method.PUT);
request.AddCookie(sessionCookie.Name, sessionCookie.Value);
request.AddHeader("Accept", "application/json");
request.AddHeader("Content-Type", "application/json");
PurchaseReceipt theRec = new PurchaseReceipt{ Type = new StringValue { Value = "Receipt" },
VendorID = new StringValue { Value = "V1002" }
};
// BaseCurrencyID = new StringValue { Value = "USD" },
// CurrencyID = new StringValue { Value = "USD" }
request.AddJsonBody(JsonConvert.SerializeObject(theRec));
response = client.Execute(request);
txtResults.Text += Environment.NewLine + "Response" + response.StatusCode.ToString();
// Setup to log out.
string strLogout = baseURL + "/entity/auth/logout";
client = new RestClient(strLogout);
request = new RestRequest(Method.POST);
request.AddHeader("Accept", "application/json");
request.AddHeader("Content-Type", "application/json");
response = client.Execute(request);
txtResults.Text += Environment.NewLine + response.StatusCode.ToString();
}
【问题讨论】:
-
尝试在登录时指定分支。库存项目实际上是在分支之间共享的,因此请求对它们有效也就不足为奇了。
-
我已经尝试将分支添加到登录 (
{\"name\":\"admin\",\"password\":\"*********\",\"tenant\":\"PWS Milwaukee\",\"branch\":\"PWMKE\"}) 和我要制作 PO 收据的请求正文中。我觉得这是正确的答案,但我不确定出了什么问题。这个特定的租户被设置为“没有分支机构”的公司类型,这就是我在登录时尝试使用和不使用它的原因。另外,如果我通过一个在登录时不存在的分支,我不会收到任何错误。