JSON API Data Source : 404 error

Greetings humans! I have a simple task: read an JSON API on another server and display the data in Grafana.

In the three images I do the following on a Grafana instance at, say, https://mygrafanaserver.com/.

  1. Install JSON API and set the URL (e.g. http://coolapi.com/api/v1/). API is on a different server.
  2. Create a panel and specify that datasource. I expect it to read http://coolapi.com/api/v1/devices. I set the fields to (e.g.) “name”. Go! But the response is from my Grafana server (all that html guff), not coolapi.com
  3. I check ‘network’ and see, yes, it’s requesting https://mygrafanaserver/api/v1.

I’m clearly an idiot: where am I going wrong?

Thanks!

ps. I must misunderstannd dataproxy as I expect the browser to ask /dataproxy/uid/… to make this request (i.e. from Grafana backend). But I see the request to the API in the browser.

pps. I’ve also tried checking CORS, different JSON datasources (infinity), removing auth p(I use a Token auth, but I think it’s not related)

Step 1


Step 2

Step 3

Forgot to add: Grafana Version 9.5.3 (commit: 916d9793aa, branch: HEAD)

It’s a slash. Yeah, that’s right:

  • /api/cool/device/1/ OK
  • /api/cool/device/1 FAIL

I don’t know the whole story, but note

  • It’s a NGINX related thing: NGINX is proxy_pass and returning a 301 redirect to a URL with the slash. Reference
  • Postman works fine on the API. I guess it can handle the 301 and re-request. The JSON datasource, I guess, doesn’t do this.
  • The difficult to work out error messages are (guessing) related to dataproxy in Grafana displaying a 404, when it actually received a 301 from the API. Other errors (e.g. 500) from the server are also shown as 404.

The simple solution is to add a trailing slash to queries, so NGINX doesn’t send a 301.

( A better solution would be to stop ngnix adding the slash. That’s homework.)

2 Likes