'How to generate access token for Dataverse APIs

I have a requirement to fetch the details from the Dataverse tables using the REST APIs and to do the same I need to generate the access token to send the valid Authorization header. I have gone through the Use OAuth authentication with Microsoft Dataverse and Register an app with Azure Active Directory and followed the steps. Now to generate the access token I am using the POST method with https://login.microsoftonline.com/{tenantId}/oauth2/v2.0/token endpoint with and passing the grant_type as client_credentials, resource as https://management.core.windows.net/ along with client id and client secret with content type as application/x-www-form-urlencoded. But I am getting AADSTS901002: The 'resource' request parameter is not supported.


EDIT

In the API Permission tab I have added the delegated permission.

enter image description here

In the Authentication tab, I haven't selected any type for flow, Do I need to change here?

enter image description here

Also please note that In the Token Configuration tab no claims or group has been added yet and Expose API tab no scope and authorized client application is added. Please let me know if I need to do any changes here.

enter image description here


UPDATE

When I do not pass the resource param and send the scope with https://{orgId}.crm5.dyanamics.com/.default along with client_id, client_secret and grant_type I am able to get the access token, but when I use this token to fetch the data using https://{orgId}.crm5.dyanamics.com/api/data/v9.0/accounts I am getting The user is not a member of the organization



Solution 1:[1]

The error AADSTS901002: The 'resource' request parameter is not supported indicates that the resource provided in the request is not correct.

As you are trying to generate access token for Dataverse API, the resource should be below:

https://admin.services.crm.dynamics.com/

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 RamaraoAdapa-MT