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

**URL:** <https://community.grafana.com/t/is-there-any-api-service-to-generate-add-a-query-on-dashboard/8953>\
**Category:** General\
**Created:** [July 19, 2018, 10:48am UTC](https://community.grafana.com/t/is-there-any-api-service-to-generate-add-a-query-on-dashboard/8953 "2018-07-19T10:48:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sercansensulungmail](https://avatars.discourse-cdn.com/v4/letter/s/46a35a/32.png) [@sercansensulungmail](https://community.grafana.com/u/sercansensulungmail)\
**Post date:** [July 19, 2018, 10:48am UTC](https://community.grafana.com/t/is-there-any-api-service-to-generate-add-a-query-on-dashboard/8953/1 "2018-07-19T10:48:14Z")

</div>

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](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](https://ibb.co/np3rpJ)

Best Regards,

---

<div class="post-metadata">

**Author:** ![danielgonzalez](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/danielgonzalez/32/7125_2.png) [@danielgonzalez](https://community.grafana.com/u/danielgonzalez)\
**Post date:** [July 19, 2018, 11:07am UTC](https://community.grafana.com/t/is-there-any-api-service-to-generate-add-a-query-on-dashboard/8953/2 "2018-07-19T11:07:34Z")

</div>

/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”  
> ]  
> }  
> ],

---

<div class="post-metadata">

**Author:** ![sercansensulungmail](https://avatars.discourse-cdn.com/v4/letter/s/46a35a/32.png) [@sercansensulungmail](https://community.grafana.com/u/sercansensulungmail)\
**Post date:** [July 19, 2018, 12:38pm UTC](https://community.grafana.com/t/is-there-any-api-service-to-generate-add-a-query-on-dashboard/8953/3 "2018-07-19T12:38:50Z")

</div>

Thank you Daniel,

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

Best Regards,
