{"Error":"Invalid JSON syntax at offset 2"} - receiving this error while trying to get everflow report

Viewed 826

I need to get a report from Everflow, a marketing platform.

The idea behind the code is pretty straightforward - I make a POST request:

url = "https://api.eflow.team/v1/affiliates/reporting/daily"
headers = {'x-eflow-api-key': '*MY*API*KEY', 'Content-Type': 'application/json',}
payload = '{ "from": "2020-09-01", "to": "2020-09-10", "timezone_id": 67, "currency_id": "USD"}'

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)

What I get as a result is:

{"Error":"Invalid JSON syntax at offset 2"}

As far as I understand, the problem might relate to the payload format, but no success with it so far after two days of trying.

Thanks for any help!

1 Answers

Can you try the below code?

import requests
import json
url = "https://api.eflow.team/v1/affiliates/reporting/daily"
headers = {"x-eflow-api-key": "*MY*API*KEY", "Content-type": "application/json"}
payload = {'from': '2020-09-01', 'to': '2020-09-10', 'timezone_id': 67, 'currency_id': 'USD'}
payload = json.dumps(payload)
response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)

But, from requests 2.4.2, the "json" parameter is supported. No need to specify "Content-Type" (in most cases).

requests.post('http://httpbin.org/post', json={'test': 'foo'})
Related