Use Canvas button to write data point to InfluxDB

Hello,

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 192.168.1.98.

I tried to repeat the first example in https://docs.influxdata.com/influxdb/v1/tools/api/#write-http-endpoint 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: http://192.168.1.98:8086/write
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":"http://192.168.1.98:8086/write?db=mydb&precision=s","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:
mymeas%2Cmytag%3D1%20myfield%3D90%201463683075

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”:“http://192.168.1.98:8086/write?db=foo&precision=s",“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
https://docs.influxdata.com/influxdb/v1/tools/api/#write-http-endpoint

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

Hi Experts…

I can confirm that even if you create the parameters as JSON, the payload works. But unfortunately an error message always appears as a popup. From the perspective of Grafana or Canvas, the payload does not appear to be API compliant. What options are there to possibly suppress or deactivate the displayed error message?

see here: Button at Canvas panel: Customizing API call result information popup message - #2 by ebabeshko

best regards denny