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
FetchError: invalid json response body at //url//
reason: Unexpected token < in JSON at position 0
Did a little fiddling and found:
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:
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.