# API request returns text/html and not a json object

**URL:** https://meta.discourse.org/t/api-request-returns-text-html-and-not-a-json-object/237407
**Category:** Support
**Created:** [August 28, 2022, 8:42pm UTC](https://meta.discourse.org/t/api-request-returns-text-html-and-not-a-json-object/237407 "2022-08-28T20:42:39Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![hiddenseal](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hiddenseal/32/284273_2.png) [@hiddenseal](https://meta.discourse.org/u/hiddenseal)
#### Post date: [August 28, 2022, 8:42pm UTC](https://meta.discourse.org/t/api-request-returns-text-html-and-not-a-json-object/237407/1 "2022-08-28T20:42:39Z")

</div>

Per @sam’s [wonderful guide](https://meta.discourse.org/t/how-to-reverse-engineer-the-discourse-api/20576), I’ve found the proper endpoint for my desired request:

```plaintext
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:

```python
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.

> [@Discourse API Reports](https://meta.discourse.org/t/discourse-api-reports/72383/5):
>
> Try adding `.json` to the end of the URL

Didn’t help either.

So what am I doing wrong?

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [August 28, 2022, 10:02pm UTC](https://meta.discourse.org/t/api-request-returns-text-html-and-not-a-json-object/237407/2 "2022-08-28T22:02:53Z")

</div>

> [@hiddenseal](#):
>
> So what am I doing wrong?

You have a duplicate header:

> [@hiddenseal](#):
>
> ```plaintext
> headers["Content-Type"] = "multipart/form-data"
> headers["Content-Type"] = "application/json"
> 
> ```

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

```plaintext
headers["Content-Type"] = "multipart/form-data"
headers["Accept"] = "application/json"

```

---

<div class="post-metadata">

### Author: ![hiddenseal](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hiddenseal/32/284273_2.png) [@hiddenseal](https://meta.discourse.org/u/hiddenseal)
#### Post date: [August 28, 2022, 11:09pm UTC](https://meta.discourse.org/t/api-request-returns-text-html-and-not-a-json-object/237407/3 "2022-08-28T23:09:40Z")

</div>

> [@RGJ](#):
>
> You have a duplicate header:

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

> [@RGJ](#):
>
> So you’ll need to change this to

This one does work. Thank you!

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [September 27, 2022, 11:09pm UTC](https://meta.discourse.org/t/api-request-returns-text-html-and-not-a-json-object/237407/4 "2022-09-27T23:09:43Z")

</div>

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