Attempting to update template selections using API POST

I utilize the GET/POST functionality very heavily to update queries, alerting criteria and thresholds for my dashboards. I’m finding a very interesting issue specific to templating though. I am attempting to simply change the selected value of a template and grafana seems to ignore my POST even though I receive a 200 response. Here is my methodology:

  1. Python script monitors a consul key-value pair, upon seeing a change in value it will trigger my grafana update logic

  2. Python script performs a GET against my dashboard

  3. Reads the current selection for my template:
    -CurrentColor = json_data_string[‘dashboard’][‘templating’][‘list’][k][‘current’][‘value’]

  4. Performs a simple bit of logic to replace the entire template string with the newly updated one
    -RedQuery = ‘{“allValue”:null,“current”:{“selected”:false,“tags”:[],“text”:“red”,“value”:“red”},“hide”:0,“includeAll”:false,“label”:null,“multi”:false,“name”:“ATP”,“options”:[{“selected”:true,“text”:“red”,“value”:“red”},{“selected”:false,“text”:“black”,“value”:“black”}],“query”:“red, black”,“type”:“custom”}’
    -BlackQuery = ‘{“allValue”:null,“current”:{“selected”:false,“tags”:[],“text”:“black”,“value”:“black”},“hide”:0,“includeAll”:false,“label”:null,“multi”:false,“name”:“ATP”,“options”:[{“selected”:false,“text”:“red”,“value”:“red”},{“selected”:true,“text”:“black”,“value”:“black”}],“query”:“red, black”,“type”:“custom”}’

  5. Python POST’s back to Grafana with the response data as the payload.

Few caveats: There are more elegant ways to replace the above data but i’ve been reduced to simplifying to the very basics to validate I am matching the strings exactly, and I can confirm that I am.
My POSTS actually include other updates which take effect, so I can guarantee that they are landing with grafana without error.
My template is simply a custom template with values of: red, black (in this case)
We are running Grafana 4.4.3 and my datasources are both Graphite and Influx

I’m hoping someone can either confirm they experience the same type of issue/spot a flow in my logic or if there is just a more direct/better way of going about this.

No there is no other way to update dashboard template variables than to update the dashboard

Thanks torkel, I feel like as a feature that would be really nice, a POST specific to updating a template but I went back and dug through the jsons again and I found my problem. It appears we upgraded versions while i’ve been working on this and the json format for template went from using “tags” to “selected” as the first option in the “current” block resulting in my replaces simply not finding what I was looking for.

Another justification for a more dynamic approach rather than hardcoding the expected data!

Wondering if you can help me one more time, i’m having a hard time creating a logic that predicts what this value “selected” under current actually represents. It seems to change to true or false based on some behavior I can’t recognize.

Json for a simple template:
{“allValue”:null,“current”:{"selected":false,“tags”:[],“text”:“black”,“value”:“black”},“hide”:0,“includeAll”:false,“label”:null,“multi”:false,“name”:“ATP”,“options”:[{“selected”:false,“text”:“red”,“value”:“red”},{“selected”:true,“text”:“black”,“value”:“black”}],“query”:“red, black”,“type”:“custom”}

Looks wrong, selected is just true or false.