Hi Pablo,
Thanks for reply, I am using python code to fetch data from dynamics 365 CRM hosted on Azure, so its online.
I need to fetch all columns and all rows of the entire table , how could I do that , that is equivalent of select * from table name on RDBMS.
tried various combos in crmwebapiquery but not sure which one would be perfect fit , so help would be really appreciated.
The code is below :-
***************************************
import requests
import json
import msal
crmorg = 'https://*****.crm4.dynamics.com/' # base url for crm org
clientid = '******************' # application client id
username = '********@**************.global' # username
userpassword = '********************' # password
tokenendpoint = 'login.microsoftonline.com/.../token' # oauth token endpoint
tenant_id = '***********************1'
# set these values to query your crm data
crmwebapi = 'https://*****************.dynamics.com/api/data/v9.2/' # full path to web api endpoint
#crmwebapiquery = '/salesorderdetails?$top=3' # web api query (include leading /)
crmwebapiquery = '/salesorderdetails'
#crmwebapiquery = '/contacts?$select=fullname,contactid' # web api query (include leading /)
tokenpost = {
'client_id': clientid,
'resource': crmorg,
'username': username,
'password': userpassword,
'grant_type': 'password',
'tenant_id': tenant_id
}
# make the token request
tokenres = requests.post(tokenendpoint, data=tokenpost)
# set accesstoken variable to empty string
accesstoken = ''
# extract the access token
try:
accesstoken = tokenres.json()['access_token']
except(KeyError):
# handle any missing key errors
print('Could not get access token')
print(tokenres.json())
# if we have an accesstoken
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')