I want to make a Web job that will execute on a set schedule. The main goal of the web job is to check a few database tables and, if new entries are found, to create the appropriate item(s) in Dynamics 365 BC. The first step in developing a strategy to accomplish all of this is to authenticate the API so that we can send POST requests. The document outlines various API endpoints with their corresponding authentication methods, such as Basic Authentication or Azure Active Directory (which requires an app registration with Delegated Permissions for Dynamics Business Central API). I am aware that we can obtain an Access token from Azure Active Directory by:
ClientCredential clientCredential = new ClientCredential(clientId, clientSecret);
var authenticationContext = new AuthenticationContext(authorityUri, true);
AuthenticationResult authenticationResult = authenticationContext.AcquireTokenAsync(resource, clientCredential).GetAwaiter().GetResult();
accessToken = authenticationResult.AccessToken;
The Azure AD authentication doesn't work in this situation because it requires user interaction for consent, and my web job needs to run in the background without any user interaction. Contrarily, production scenarios are not advised to use basic authentication.
Please provide a suggestion for the generation of the access token that doesn't involve user input.
EDIT
Basic authentication can be used in this scenario, according to Allen's response, though Microsoft documents must be updated to support it. But as you investigate the API endpoint
https://api.businesscentral.dynamics.com/v1.0/<mydomain.com>/api/beta/companies
I am experiencing the following error when using Postman and basic authentication:
{
"error": {
"code": "Authentication_InvalidCredentials",
"message": "The server has rejected the client credentials. CorrelationId: 641ea3fd-19d6-4402-8e68-a70145eb6da3."
}
}
For my business central user, I have generated a webservice access key, and I'm using that in addition to the username for basic authentication. I'm positive I'm copying the right webservice key. Any assistance
Here's a link that may help you.
API (V2.0) for Dynamics 365 Business Central - Business Central | Microsoft Learn