Fixed – 401 Unauthorized error while calling Dynamics 365 Web API

Sending
User Review
0 (0 votes)

We were recently getting the below error while trying to call Dynamics 365 Web API through Postman.

“401 Unauthorized”

It turned out that we were using the incorrect Token.

To generate the correct token,

For OAuth 2.0 token endpoint (v1) Version 1

  • We need to specify resource with Dynamics 365 URL.


For OAuth 2.0 token endpoint (v2) Version 2

  • We need to specify scope with
    Dynamics 365 URL followed by .default instead of a resource.

The correct token results in the successful call to the Web API

References –

https://matthijs.hoekstraonline.net/2020/04/27/v1-and-v2-identity-and-access-tokens-with-azure-active-directory/

https://crmchap.co.uk/generating-oauth2-v2-0-endpoint-tokens-for-dynamics-365-the-common-data-service/

Hope it helps..