Dynamics CRM is not currently supported here on QnA. The product group for Dynamics actively monitors questions over at
https://community.dynamics.com/crm
--please don't forget to upvote
and Accept as answer
if the reply is helpful--
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi ALl,
I am trying to fetch data via python code but getting below error not sure , what is missing ,
import requests
import json
crmorg = 'https://************.crm4.dynamics.com/' # base url for crm org
clientid = '**********************' # application client id
username = '**************@**********0af1.com' # username
userpassword = '****************************' # password
tokenendpoint = 'https://login.microsoftonline.com/**************/oauth2/v2.0/token' # oauth token endpoint
crmwebapiquery = '/contacts?$select=fullname,contactid' # web api query (include leading /)
tokenpost = {
'client_id': clientid,
'resource': crmorg,
'username': username,
'password': userpassword,
'grant_type': 'password'
}
tokenres = requests.post(tokenendpoint, data=tokenpost)
accesstoken = ''
try:
accesstoken = tokenres.json()['access_token']
except(KeyError):
# handle any missing key errors
print('Could not get access token')
if (accesstoken != ''):
# prepare the crm request headers
crmrequestheaders = {
'Authorization': 'Bearer ' + accesstoken,
'OData-MaxVersion': '4.0',
'OData-Version': '4.0',
'Accept': 'application/json',
'Content-Type': 'application/json; charset=utf-8',
'Prefer': 'odata.maxpagesize=500',
'Prefer': 'odata.include-annotations=OData.Community.Display.V1.FormattedValue'
}
# make the crm request
crmres = requests.get(crmwebapi + crmwebapiquery, headers=crmrequestheaders)
try:
# get the response json
crmresults = crmres.json()
print(crmresults)
except KeyError:
# handle any missing key errors
print('Could not parse CRM results')
Dynamics CRM is not currently supported here on QnA. The product group for Dynamics actively monitors questions over at
https://community.dynamics.com/crm
--please don't forget to upvote
and Accept as answer
if the reply is helpful--