Extract any data from dashboard though api

Hello,

I want to check if it is possible to get any data from any dashboard through the http api of grafana.

Currently, I can get all the metadata json for a dashboard with a curl :

curl -k -H "Content-Type: application/json" -H "Authorization: Bearer ${GRAFANA_TOKEN}" -X GET https://${GRAFANA_URL}/api/dashboards/uid/${DASHBOARD_UID}

But I need to apply a timerange to this dashboard and just check there is any data.

I can’t use the grafana interface, because I need to automate this test. Do you know how it is possible ?

Thanks !

That API gives you only dashboard model (not data), so you need to parse that model find which datasources are used, build the queries and then you can run those queries via datasource api:

OK, thanks ! So I will do as you say, thank you.

hey @pbourit ,

were you able to get data using the datasource api?
I am trying to do the same, but getting error and not sure how to go about further

Curl command below -

curl --location --request POST ‘https:/api/ds/query’
–header ‘Content-Type: application/json’
–header ‘Accept: application/json’
–header ‘Authorization: Bearer <>’
–data-raw ‘{
“from”:“now-5m”,
“to”:“now”,
“queries”:[
{
“refId”:“A”,
“query”:“count(kube_namespace)”,
“datasource”:{
“uid”:“PBFA97CFB590B2093”
}
}
]
}’

Grafana version - 9.5.3
Datasource: Prometheus

Error:

{
“results”: {
“A”: {
“error”: “bad_data: 1:1: parse error: no expression found in input”,
“status”: 500,
“frames”:
}
}
}

any help in above issue will be greatly appreciated.

will you be able to help on my issue above?

  1. open dev console in your browser
  2. Go to network tab
  3. Clear current network data
  4. Open a dashboard that uses the specific datasource you want to grab data from using api

Then see what it does in network tab
in below case it is querying a ms sql datasource.

  1. Use View Source to see what it does, implement in your curl
1 Like

perfect thanks, this was helpful