API request returns text/html and not a json object

AI-generated summary

The discussion revolves around an API request that returns text/html instead of a JSON object. hiddenseal shared a Python GET request code that resulted in a 200 status code but with the wrong content type.

hiddenseal initially tried adding .json to the end of the URL, as suggested by David Taylor, but it didn’t solve the issue.

RJG pointed out that the issue lies in the duplicate Content-Type header and suggested changing it to Accept to specify the desired response format. hiddenseal confirmed that this solution works.

The corrected code should be:

headers["Accept"] = "application/json"

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?

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"

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

This one does work. Thank you!