Use Canvas button to write data point to InfluxDB


Setup in use: Using latest Grafana 10.2.1 with Raspberry Pi OS 64-bit version, Debian 12 based. Raspberry Pi’s IP address is

I tried to repeat the first example in web page using the button element in the Canvas panel. The original example in the Influxdata web resource is as follows:

curl -i -XPOST "http://localhost:8086/write?db=mydb&precision=s" --data-binary 'mymeas,mytag=1 myfield=90 1463683075'

I tried to set the Canvas panel button options as follows:
API endpoint:
Method: POST
Content-Type: x-www-form-urlencoded
Query parameters:
db mydb
precision s
Header parameters: {none}
Payload: ‘mymeas,mytag=1 myfield=90 1463683075’

Grafana communicates OK with the InfluxDB, but it seems that the last single quote character is interpreted as part of the timestamp value and InfluxDB throws the following error after pressing the Test API button:

An error has occurred:

{"status":400,"statusText":"Bad Request","data":{"error":"unable to parse ''mymeas,mytag=1 myfield=90 1463683075'': bad timestamp","message":"unable to parse ''mymeas,mytag=1 myfield=90 1463683075'': bad timestamp"},"config":{"url":"","method":"POST","data":"'mymeas,mytag=1 myfield=90 1463683075'","headers":[["Content-Type","application/x-www-form-urlencoded"]],"retry":0,"hideFromInspector":false}}

I have tried many forms of the payload field, with double quotes, braces, brackets, escape characters, and with other values of Content-Type field: JSON, text etc
Please help me to finalize this. Http GET method is already working

1 Like

Did you try payload without any quotes?

Yes, in that case the error is:
An error has occurred:
{“data”:{“message”:“Unexpected error”}}

That is coming due to the space characters between tag, field and timestamp sets. Tried to replace the spaces with %20 or + chars, no success…

I guess you are claiming that payload is already urlencoded, so encode it properly. And use browser console to verify what browser is posting:

Yes, with payload set as follows:

The following error is displayed after pressing Test API button:

An error has occurred:
{“status”:400,“statusText”:“Bad Request”,“data”:{“error”:“unable to parse ‘mymeas%2Cmytag%3D1%20myfield%3D90%201463683075’: missing fields”,“message”:“unable to parse ‘mymeas%2Cmytag%3D1%20myfield%3D90%201463683075’: missing fields”},“config”:{“url”:“",“method”:“POST”,“data”:“mymeas%2Cmytag%3D1%20myfield%3D90%201463683075”,“headers”:[[“Content-Type”,“application/x-www-form-urlencoded”]],“retry”:0,"hideFromInspector”:false}}

Checked from Wireshark capture, now with the ASCII encoded chars, it seems the Value field has no content:

In case the curl command is given, the WS capture shows the following:

The case is now solved. Despite the following error message the data point is written to InfluxDB. I don’t know why I did not check the contents of InfluxDB earlier

An error has occurred:
{“data”:{“message”:“Unexpected error”}}

Referring to the original example in

just set the button parameters as follows and data is there in InfluxDB as inserted

1 Like

Do you have a try catch? Might help pinpoint fhe excat error