import msal
import requests
client_id = "<your_client_id>"
client_secret = "<your_client_secret>"
tenant_id = "<your_tenant_id>"
authority = f"https://login.microsoftonline.com/{tenant_id}"
scope = ["https://your_org.crm.dynamics.com/.default"]
app = msal.ConfidentialClientApplication(client_id, authority=authority, client_credential=client_secret)
token_response = app.acquire_token_for_client(scopes=scope)
access_token = token_response['access_token']
headers = {
'Authorization': f'Bearer {access_token}',
'Content-Type': 'application/json',
'OData-MaxVersion': '4.0',
'OData-Version': '4.0'
}
url = "https://your_org.crm.dynamics.com/api/data/v9.2/accounts"
response = requests.get(url, headers=headers)
print(response.json())
Let me know if this helps, and please mark the response as helpful if it answered your question 😊
Best regards!