Zoho Assist API - python and requests library
I am using the following python code which results in an error 400. I setup the self-client and have received a clean token and can generate a new token via my refresh token.
- import requests
- import datetime
- import time
- import json
- api_url = 'https://assist.zoho.com/api/v2/reports'
- access_token = '1000.*****************************************************************'
- def dt():
- one_week_ago = datetime.datetime.now() - datetime.timedelta(weeks=3)
- fromdate = int(one_week_ago.timestamp())
- fromdate = fromdate * 1000
-
- todate = int(time.time())
- todate = todate * 1000
- return (fromdate, todate)
- #get unix from and to dtstamps and ensure they are longs per api spec
- getdate = dt()
- fromdate = int(getdate[0])
- todate = int(getdate[1])
- #set the report type per required argument
- type = 'rs'
- data = {
- 'type': type,
- 'fromdate': fromdate,
- 'todate': todate
- }
-
- headers = {
- 'Authorization': f'Zoho-oauthtoken {access_token}',
- 'Content-Type': 'application/json'
- }
- #send the api request
- response = requests.get(url=api_url, headers=headers, data=data)
- if response.status_code == 200:
- print (f'Status Code: {response.status_code}')
- try:
- json_response = response.json()
- print (json_response)
- except json.decoder.JSONDecodeError as e:
- print("JSON Descoding error:", e)
- else:
- print(f'API request failed with status code {response.status_code}')