# API Returning HTML Instead of JSON At Specific Routes?

**URL:** <https://meta.discourse.org/t/api-returning-html-instead-of-json-at-specific-routes/100691>\
**Category:** Development\
**Created:** [October 28, 2018, 5:25pm UTC](https://meta.discourse.org/t/api-returning-html-instead-of-json-at-specific-routes/100691 "2018-10-28T17:25:41Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![Wintermute](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/wintermute/32/127023_2.png) [@Wintermute](https://meta.discourse.org/u/Wintermute)\
**Post date:** [October 28, 2018, 5:25pm UTC](https://meta.discourse.org/t/api-returning-html-instead-of-json-at-specific-routes/100691/1 "2018-10-28T17:25:41Z")

</div>

> In Brief:

- calling a specific route returns HTML instead of json
- calling a different route with same code returns json as expected
- accessing the broken route from the Chrome browser returns json as expected

> Long:

I found an error with a URL with .json appended erroring with

```plaintext
FetchError: invalid json response body at //url// 
reason: Unexpected token < in JSON at position 0 

```

Did a little fiddling and found:

```plaintext
const request2 = 'https://{site-url}/u/{user}/activity.json?api_key={key}';

fetch(request2)
// .then(res => {console.log(res)}) // returns 200
.then(res => {return res.text()}) //.json was swapped for .text here
.then(res => {console.log(res)}) // returns html!

```

The output of the second console.log(), which we expect to be JSON, is HTML!

The odd thing:

Reusing the same code but a different route:

```plaintext
const request2 = 'https://{site-url}/u/{user}.json?api_key={key}'

```

returns json as expected. And even stranger, pasting the faulty URL into Chrome returns JSON as expected!

Any suggestions? Is this a discourse bug? Did I set something up wrong? I’m not the site admin but can request to get things fixed if it’s a site setup issue.

---

_[View the full topic](https://meta.discourse.org/t/api-returning-html-instead-of-json-at-specific-routes/100691)._
