![](/img/trans.png)
[英]Create Item in Dynamics 365 Business Central using Rest API
[英]Authorize Dynamics 365 Business Central API
我想創建一個應該按計划運行的 Webjob。 Webjob 的目的基本上是檢查一些數據庫表,如果表中有新條目,則相應地在 Dynamics 365 BC 中創建項目。 在設計實現所有這些的方法時,第一步是驗證 API,以便我們可以進行POST
調用。 此處的文檔指定了不同的 API 端點,它們具有各自的身份驗證機制,即通過 Azure Active Directory(需要具有 Dynamics Business Central API 的Delegated
權限的應用程序注冊)或基本身份驗證。 我知道,我們可以使用客戶端 ID 和密碼從 Azure 活動目錄獲取訪問令牌:
ClientCredential clientCredential = new ClientCredential(clientId, clientSecret);
var authenticationContext = new AuthenticationContext(authorityUri, true);
AuthenticationResult authenticationResult = authenticationContext.AcquireTokenAsync(resource, clientCredential).GetAwaiter().GetResult();
accessToken = authenticationResult.AccessToken;
現在,由於我的 web 作業需要在后端運行而無需任何用戶交互,因此 Azure AD 身份驗證不適合此處,因為它需要用戶交互才能同意。 而基本認證不推薦用於生產場景。
請建議應該如何生成訪問令牌,以便它不需要用戶交互。
編輯
根據 Allen 的回復,基本身份驗證可用於此場景,但需要更新 Microsoft 文檔以支持此場景。 但是,在探索 API 端點https://api.businesscentral.dynamics.com/v1.0/<mydomain.com>/api/beta/companies
使用 Z6F061E1CAD5E2783CEA0B2976ED2F4C 時,我面臨以下身份驗證錯誤:
{
"error": {
"code": "Authentication_InvalidCredentials",
"message": "The server has rejected the client credentials. CorrelationId: 641ea3fd-19d6-4402-8e68-a70145eb6da3."
}
}
雖然我為我的業務中心用戶生成了 Web 服務訪問密鑰,並將其與用戶名一起用於基本身份驗證。 我確信我正在復制正確的網絡服務密鑰。 任何幫助將不勝感激。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.