Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Getting "HTTP Error 401 - Unauthorized: Access is denied" while trying to access Dynamics 365 Online resource using Client Credentials

(0) ShareShare
ReportReport
Posted on by

I am trying to get Dynamics 365 online data using access token received on successful authentication by using client credentials for an Web app / API application . However getting 401 always.

Here is what I am doing:

  1. Authentication

    Request URL:
    POST https://login.microsoftonline.com/tenantId/oauth2/token

    Request Headers:
    Content-Type: application/x-www-form-urlencoded
    Accept: application/json

    Request Body:
    client_id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx
    resource: domain.crm.dynamics.com
    grant_type: client_credentials
    client_secret: xxxxxxxxxxxxxxxxxxxxxxxxxxxxx=

    Response Status: 200 OK
    Response Body (Sample):
    {
    "token_type": "Bearer",
    "expires_in": "3599",
    "ext_expires_in": "0",
    "expires_on": "1524644921",
    "not_before": "1524641021",
    "resource": "domain.crm.dynamics.com",
    "access_token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    }

  2. Request a Dynamics resource using the received access_token

    Request URL:
    GET https://domain.crm.dynamics.com/api/data/v8.2/accounts?$select=name

    Request Headers:
    Accept: application/json
    OData-MaxVersion: 4.0
    OData-Version: 4.0
    Authorization: Bearer {{access_token}}

    Response Status: 401 Unauthorized
    Response Body: HTTP Error 401 - Unauthorized: Access is denied
    Response Headers:
    WWW-Authenticate: Bearer authorization_uri=https://login.windows.net/tenantId/oauth2/authorize, resource_id=domain.crm.dynamics.com

*This post is locked for comments

  • Suggested answer
    Ryan Spain Profile Picture
    Ryan Spain 52 on at
    RE: Getting "HTTP Error 401 - Unauthorized: Access is denied" while trying to access Dynamics 365 Online resource using Client Credentials

    Hi Suvasish,

    Three things worth checking here given the error response:

     

    1. Required Permissions

    Add permissions to the App Registration to access Dynamics CRM Online(see item 1 in screenshot below). Then use the "Grant permissions" button.

    2. Application User
    Ensure that an Application User in setup in Dynamics using the Client ID(see item 2 in screenshot below) from the App Registration in Azure.

    3. Security Role
    Ensure that a custom security role is assigned to the above Application User. You can just do a copy of System Administrator or similar.

    3666.Screenshot_5F00_45.png

    Hope this helps,

    Ryan

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,436 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans