Hello there,
I am trying to read data from a couple of tables stored in Microsoft Dataverse through the API. I've completed the following steps:
- Register application under App registrations in Microsoft Entra ID
- Allow access to "Dynamics CRM" under API Permissions, also made sure to select Grant admin consent for XXX
- Create new Application User in Power Platform Admin console (as described here: https://learn.microsoft.com/en-us/power-platform/admin/manage-application-users)
- Added the newly registered application in Entra ID to the Application User
- I added "System Administrator" Security Role for now, but intend to change this in the future. I only need to be able to read data, but I want to avoid having issues due to the insufficient priviliges
When I try to send a request to the api endpoint https://<organization>.crm4.dynamics.com/api/data/v9.2/<table> (url is directly from the power platform admin console) I keep getting the error
... "The user is not a member of the organization."}}
I am able to successfully complete the request when I authenticate using Azure CLI, however the error occurs when I try to authenticate with client ID, client secret & tenant ID (as received from the MS Entra ID app registration).
Code snippet (in Python) for performing the request:
---
import requests
from azure.identity import DefaultAzureCredential
DATAVERSE_URL = "https://<organization>.crm4.dynamics.com"
def get_token():
credential = DefaultAzureCredential()
token = credential.get_token(DATAVERSE_URL + '/.default')
return token.token
def send_request():
token = get_token()
headers = {
'Authorization': f'Bearer {token}',
'OData-MaxVersion': '4.0',
'OData-Version': '4.0',
'Accept': 'application/json',
}
url = f"{DATAVERSE_URL}/api/data/v9.2/<table>"
response = requests.get(url, headers=headers)
return response
---
I am hoping you can pinpoint what I am doing wrong here.
Thanks in advance.