API request returns text/html and not a json object

Per @sam’s wonderful guide, I’ve found the proper endpoint for my desired request:

https://domain.com/admin/reports/bulk?reports[dau_by_mau][facets][]=prev_period&reports[dau_by_mau][start_date]=2022-07-27&reports[dau_by_mau][end_date]=2022-08-28&reports[dau_by_mau][limit]=50

I found no form-headers to be present, and I assumed there were none needed. This request in Dev Tools results in a JSON response, exactly the one I want/need. I’m trying to make a python get request:

url = "https://domain.com/admin/reports/bulk?reports[dau_by_mau][facets][]=prev_period&reports[dau_by_mau][start_date]=2022-07-27&reports[dau_by_mau][end_date]=2022-08-28&reports[dau_by_mau][limit]=50.json"
headers = CaseInsensitiveDict()
headers["Content-Type"] = "multipart/form-data"
headers["Content-Type"] = "application/json"
headers["Api-Key"] = SECRET.API
headers["Api-Username"] = "system"

resp = requests.get(url, headers=headers)

print(resp.status_code)
print(resp.headers)

I do get a 200, but it returns with a 'Content-Type': 'text/html, and not a JSON (which is what I want). And I’m not even sure the text it returns is the text version of desired data.

Didn’t help either.

So what am I doing wrong?

1 Like

You have a duplicate header:

Content-Type is about what you send, and Accept is about what you want in return.
So you’ll need to change this to

headers["Content-Type"] = "multipart/form-data"
headers["Accept"] = "application/json"
5 Likes

Sorry, it’s an unrelated relict. I had an issue without the second header.

This one does work. Thank you!

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.