Assistance Needed with Business Central API Authentication and Inventory Fetch

Paul Summers 0 Reputation points
2024-09-23T10:17:37.1266667+00:00

Hello,

I am working on retrieving inventory from Business Central to update the data for each SKU in our database. To begin, I attempted to obtain an access token using the following API: https://login.microsoftonline.com/{{tenantID}}/oauth2/v2.0/token

Here is the request:

for request refer to the attached image,

and the response I received from Azure is as follows: { "token_type": "Bearer", "expires_in": 3599, "ext_expires_in": 3599, "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Ikg5bmo1QU9Tc3dNcGhnMVNGeDdqYVYtbEI5dyIsImtpZCI6Ikg5bmo1QU9Tc3dNcGhnMVNGeDdqYVYtbEI5dyJ9.................................................." }

In the next step, I need to retrieve the company ID from Business Central using the following API: https://api.businesscentral.dynamics.com/v2.0/{{environment}}/api/microsoft/automation/v2.0/companies

I passed the Authorization header with the value Bearer {{accessToken}}. However, the response I received was: { "error": { "code": "Authentication_InvalidCredentials", "message": "The server has rejected the client credentials. CorrelationId: 794c8b3b-f5fc-4dca-a32d-761a6b0acceb." } }

Could you please assist me in resolving this authentication issue so that I can successfully retrieve the company ID?

Additionally, I would appreciate guidance on how to fetch inventory data from Business Central, specifically for items that may have changed in the last hour.

Thank you for your assistance.

Best regards, Rahmat

Windows 365 Business
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
22,244 questions
Dynamics 365 Training
Dynamics 365 Training
Dynamics 365: A Microsoft cloud-based business platform that provides customer relationship management and enterprise resource planning solutions.Training: Instruction to develop new skills.
154 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Akhilesh Vallamkonda 10,325 Reputation points Microsoft Vendor
    2024-09-27T18:52:05.6766667+00:00

    Hi @Paul Summers

    Thank you for reaching Microsoft Q&A!

    Based on the information you provided, it might be issue with the API permissions, kindly check the API permissions in App registrations and see if have added the Application permissions as per the below document which has explained how to call API which is similar to your issue.

    Reference: Service-to-service authentication for automation APIs in Business Central
    Service-to-service authentication for Automation APIs
    Hope this helps. Do let us know if you any further queries by responding in the comments section. Thanks,

    Akhilesh.

    ------------ If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.