web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Access Dynamics CRM AP...
Power Apps
Suggested Answer

Access Dynamics CRM API with Service Principal

(1) ShareShare
ReportReport
Posted on by 2
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.  
I have the same question (0)
  • Suggested answer
    MichaelFP Profile Picture
    1,847 Super User 2025 Season 2 on at
    Hi!
     
    You must acquire the token login in the tenant before start to use the Dataverse web api. You can do that using OAuth flow
     
     
     
  • bscarlavai33 Profile Picture
    752 Super User 2025 Season 2 on at
    The error seems like that app user isn't a part of the environment or doesn't have a role. Did you verify you added the app user to the correct environment when using the Admin Portal?
  • Shashank Bhide Profile Picture
    942 Moderator on at
    DefaultAzureCredentials class follows the below chain (in same order) to get a token and stops when one of the classes supplies the token, which one have you configured? I guess none, so create a managed identity (MI) and then give that MI rights in Dataverse like you did, and then use "ManagedIdentityCredential" or "DefaultAzureCredentials" to get the token, then you need to add the token to the request (like yo did) and then send it.
     
     
     

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 721 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 320 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard