Is there any API service to generate(add) a Query on dashboard?

When I read documentation, I cannot find any API service that generates query such as Team or User. And then, I tried to explore that which API service is called while generating a query on UI dashboard. Then I realized that there is a service called as http://grafana.staged-by-discourse.com/api/tsdb/query and it takes
{
“from”:“1531968835588”,
“queries”:[
{
“datasourceId”:1,
“format”:“table”,
“intervalMs”:120000,
“maxDataPoints”:232,
“rawSql”: “EXECUTE GetTemperature 2”,
“refId” : “A”
}
],
“to”:“1531990435588”
}
object as a parameter but I cannot understand “from” and “to” properties. Finally, when I execute it on postman, I cannot see the query which is expected as auto generated.

In other words, I would like to generate a query which is described on Picture with API call .

Picture : https://ibb.co/np3rpJ

Best Regards,

/api/tsdb/query is internal point to get data from datasources,
the parameter from and to, are the limits of time.

i think that you need to get all dashboard and update with a new query
on dashbord json, you can see a “targets” field, you need add a new target

“targets”: [
{
“alias”: “”,
“dimensions”: {},
“format”: “table”,
“hide”: false,
“metricName”: “”,
“namespace”: “”,
“period”: “”,
“rawSql”: “Select * from mytable”,
“refId”: “A”,
“region”: “default”,
“statistics”: [
“Average”
]
}
],

1 Like

Thank you Daniel,

Your answer was exactly what I am looking for. “targets” fields solve my problem thank you again.

Best Regards,