Access Dataverse Web API with Server-to-Server connection

Kiki van R 0 Reputation points
2024-09-16T09:16:39.5033333+00:00

Hi,

I am trying to read data from certain tables in MS Dataverse using the Dynamics CRM API. I completed the following steps:

  1. Register application in Microsoft Entra ID
  2. Allow API permissions for Dynamics CRM API
  3. Grant admin consent for the API permissions
  4. Add Application User in Power Platform Admin Console
    1. I assigned the role "System Administrator" to make sure I have sufficient priviliges, however I intend to create a custom role in the future if everything works
  5. Add registered application to the Application User

I am able to read data by authenticating with my own personal account using the Azure CLI. However, I need to be able to read the data by authenticating with the Application User (Server-to-Server). For the API call I do the folIowing:

-----Request access token by authenticating through client credentials:

DATAVERSE_URL = "https://<organisation>.crm4.dynamics.com"

url = f'https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token'

data = {

"client_id": <client_id>,

"client_secret": <client_secret>,

"scope": DATAVERSE_URL + "/.default",

"grant_type": "client_credentials",

}

-----Call Dataverse Web API:

headers = {

'Authorization': f'Bearer {access_token}',

'Content-Type': 'application/json'

}

api_url = DATAVERSE_URL + "/api/data/v9.2/accounts"

I keep getting the same error:

"The user is not a member of the organization."

I feel like I am missing a step here. I hope you can point me in the right direction. 

Thanks in advance!

Community Center Not monitored
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.