I'm using Grafana with JSON API data source and I'd like to build a query that depends on the selected period of time selected in the upper right corner of the screen.
Is there any variable (or something like that), which I can send the selected time range form Grafana and receive it in my backend?
In other words, If I select 24hs in Grafana I'd like to use that in my query and return only data in this period.
I tried to get request from Grafana, which should contain the time range. However I got error: Failed to decode JSON object: Expecting value: line 1 column 1 (char 0)
.
It's possible that I misunderstood something and it doesn't work that way.
This is my /query
endpoint:
@app.route('/query', methods=['POST', 'GET'])
def query():
req = request.get_json() <- failed
range = req['request']['range']
json_data = get_from_database(range)
return json_data
Are there any other options, like sending the time range ( with these variables {__from}&to=${__to}) in URL?