Zoho Assist API - python and requests library

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.

  1. import requests
  2. import datetime
  3. import time
  4. import json

  5. api_url = 'https://assist.zoho.com/api/v2/reports'

  6. access_token = '1000.*****************************************************************'

  7. def dt():
  8.     one_week_ago = datetime.datetime.now() - datetime.timedelta(weeks=3)
  9.     fromdate = int(one_week_ago.timestamp())
  10.     fromdate = fromdate * 1000
  11.     
  12.     todate = int(time.time())
  13.     todate = todate * 1000

  14.     return (fromdate, todate)

  15. #get unix from and to dtstamps and ensure they are longs per api spec
  16. getdate = dt()
  17. fromdate = int(getdate[0])
  18. todate = int(getdate[1])

  19. #set the report type per required argument
  20. type = 'rs'

  21. data = {
  22.     'type': type,
  23.     'fromdate': fromdate,
  24.     'todate': todate
  25. }
  26.   
  27. headers = {
  28.     'Authorization': f'Zoho-oauthtoken {access_token}',
  29.     'Content-Type': 'application/json'
  30. }

  31. #send the api request
  32. response = requests.get(url=api_url, headers=headers, data=data)

  33. if response.status_code == 200:
  34.     print (f'Status Code: {response.status_code}')
  35.     try:
  36.         json_response = response.json()
  37.         print (json_response)
  38.     except json.decoder.JSONDecodeError as e:    
  39.         print("JSON Descoding error:", e)
  40. else:
  41.     print(f'API request failed with status code {response.status_code}')