Fixed – 401 Unauthorized error while calling Dynamics 365 Web API


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..

Advertisements

Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

4 thoughts on “Fixed – 401 Unauthorized error while calling Dynamics 365 Web API”

Please share your thoughts

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.