web
You’re offline. This is a read only version of the page.
close
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

I have the same question (0)
  • Suggested answer
    Ryan Spain Profile Picture
    52 on at

    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans