
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:
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"
}
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)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.
Hope this helps,
Ryan