How to configure json datasource in Grafana

I have installed json plugin for Grafana on my Mac system per link. Now I am configuring the newly installed json plugin with new relic Graphql API endpoint that returns json data. I need to use custom header with API-Key for that end-point and Content-Type: application/json along with the --data-binary “query to fetch the data”. I have tested this new relic endpoint with curl command on my local machine which is returning right json data. But when I am configuring this in the Grafana and then click save & test I am getting error HTTP error Bad Request. Please can you let me know how I should be configuring the json plugin as data source with API end point and custom headers and data load that has query as input parameter?

  • What Grafana version and what operating system are you using?
    8.1.1

  • What are you trying to achieve?
    Configuring json as Grafana data source

  • How are you trying to achieve it?

  • What happened?
    Http Bad error. All described above

  • What did you expect to happen?
    Data source should get configured and return data

  • Can you copy/paste the configuration(s) that you are having problems with?

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.
    I received error in Grafana UI while configuring and saving & testing

  • Did you follow any online instructions? If so, what is the URL?
    Yes. Configuration | JSON API for Grafana

I suggest you edit your post to include your CURL example (hide keys etc) as well as specify exactly what parameters you have in your datasource config and panel config. e.g. What are your Datasource settings and panel Params / Headers / Body data you have tried so far?

Without seeing what you are doing it’s likely to be impossible to say why you are getting the error.

The curl command returns json data on my local mac laptop. Here is command where I have replaced API-Key etc with dummy values:-“curl https://api.newrelic.com/graphql
-H ‘Content-Type: application/json’
-H ‘API-Key: XXXXXXXXXX’
–data-binary '{“query”:”{\n actor {\n account(id: nnnnnnnn) {\n nrql(query: “SELECT uniqueCount(column-name) FROM Transaction WHERE appName IN (\App_Name\u0027) AND clientId=\u0027Client_Id\u0027 since 30 days ago TIMESERIES”, timeout: 30) {\n results\n }\n }\n}\n}\n", “variables”:""}’
"
Below is screenshot where I am entring the values.

Are you adding any query string into the datasource? As your screenshot does not show that. Update your post with exactly the text of the query or show the screenshot showing the entire query.

HTTP error Bad Request suggests an HTTP 400 error which suggests the contents of the request are malformed. If you are sending query data then it is likely the cause of the problem, maybe due to special characters and quotes not escaped properly. It may be correct for CURL but not for the API. Your CURL example (at least how it is shown above) includes unicode codes, newlines and all sorts of different quotes: single quotes, double quotes (both straight in places and right/left (curled) in other places).

Ya. I have also tried with the query string with Header as data-binary and value as exactly here–> '{“query”:”{\n actor {\n account(id: nnnnnnnn) {\n nrql(query: “SELECT uniqueCount(column-name) FROM Transaction WHERE appName IN (\App_Name\u0027) AND clientId=\u0027Client_Id\u0027 since 30 days ago TIMESERIES”, timeout: 30) {\n results\n }\n }\n}\n}\n", “variables”:""}’
Received same error.

This topic was automatically closed after 365 days. New replies are no longer allowed.