I'm trying to get all the records from a query to the Dynamics API, but I don't know how to break the default limit of 5000.
Currently my code looks like this:
LOGIN_URL = 'https://login.microsoftonline.com/xxxxxxxxxxxxxxxxxxxx/oauth2/token'
TENANT_ID = 'xxxxxxxxxxxxxxxxxxxxxx'
CLIENT_ID = 'xxxxxxxxxxxxxxxxxxxxxx'
GRANT_TYPE = 'client_credentials'
CLIENT_SECRET = 'xxxxxxxxxxxxxxxxxxxxxx'
RESOURCE = 'https://xxx.crmX.dynamics.com'
API_ACCOUNTS = "https://xxx.crmX.dynamics.com/api/data/v9.1/accounts
response = requests.post(LOGIN_URL, data={'tenant_id': TENANT_ID,
'client_id': CLIENT_ID,
'client_secret': CLIENT_SECRET,
'grant_type': GRANT_TYPE,
'resource': RESOURCE}).json()
try:
accesstoken = response['access_token']
except(KeyError):
print('Could not get access token')
customer_data = requests.get(API_ACCOUNTS, headers={
'Authorization': 'Bearer ' + accesstoken})
jsonData = customer_data.json()
jsonD = json.dumps(jsonData)
f = open("accounts.json", "w")
f.write(jsonD)
f.close()
But this way I only get the first 5000 records.Does anyone know what modifications I should make?
Thank you!
question from:
https://stackoverflow.com/questions/65908020/how-to-download-more-than-5000-records-from-dynamics-web-api-using-python 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…