Solutions

Sending Data to InfluxDB Using REST API Integrations : Walk-through

5min
pre requisite download the helper template from central portal, and upload it to your litmusedge write data with the influxdb api (v1 x) a recommended reference to review when writing data using influxdb apis is located here the below example is extracted from the template file that was shared with the solution it is a raw api call with a sample piece of data that is being sent to the database sending a post request to the influxdb that is running on tsdata ip address is http //10 17 9 53 and the port is 8087 the u is followed by username\ password the information in the url consists of the database and the precision database is tsdata and precision is seconds data binary is the measurement (mymeas in the example) and the key/value pairs that are being sent ( in this format key=value) note if there are no timestamps with the data, the database will publish the timestamp that it receives the data at curl i xpost u litmus\ example\@123 "http //10 17 9 53 8087/write?db=tsdata\&precision=s" data binary 'mymeas,mytag=1 myfield=90,myfield2=123' this can be further explored in this flow to further understand the payload that needs to be sent via nats, see the explanation below related to the flow shown below note nodes 1 5 are preparing the data schema bring in all the tags from device sim03 convert string to object start preparing the schema by having key=value send a msg complete to the join node put this as repeating on a regular interval (once per second) to send the data compiled through every second join the key/value pairs into one payload with commas separated add the measurement name to the payload send the data to a topic once the data is published to a topic, you will be ready for the next step (preparing the integrations) method choose post endpoint http //\<ip address> /write headers (key value pair) authorization basic username\ password (converted to base 64, eg litmus\ example\@123 converted to base 64) the following information could be either in the params or in the topic of the integrations db (database that your system is set up with, eg tsdata) precision (s for seconds, ns for nanoseconds) note alternatively you can input the information in the remote topic of the integrations the topic can be set up as follows http //\<ip address> /write?db=litmus\&precision=s you are now set up to send data to influxdb v1 x via api calls! write data with the influxdb api (v2 x) a recommended reference to review when writing data using influxdb apis is located here the below example (extracted from the template that was shared under the files and references section), is a raw api call with a sample piece of data that is being sent to the database the information is as follows sending a post request to the influxdb that is running on tsdata ip address is http //10 17 9 53 and the port is 8087 the org is litmus , bucket is litmus and precision is nano seconds header carries the authorization, content type and formating accepted data binary is the measurement (airsensors) and the key/value pairs that are being sent note if there are no timestamps with the data, the database will publish the timestamp that it receives the data at curl request post "http //10 17 9 53 8087/api/v2/write?org=litmus\&bucket=litmus\&precision=ns" header "authorization token cr9hozahrm8j vd2nk6o6bwrneubsz1kftad0znx4nmrgfhgfrsgn1ybf6ylv41fo82k6jxcmrdxksao42wamg==" header "content type text/plain; charset=utf 8" header "accept application/json" data binary 'airsensors,sensor id=tlm0201 temperature=73 97038159354763,humidity=35 23103248356096,co=0 48445310567793615' this can be further explored in this flow to further understand the payload that needs to be sent via nats, see the explanation below related to the flow shown below note that nodes 1 5 are preparing the data schema bring in all the tags from device sim03 convert string to object start preparing the schema by having key=value send a msg complete to the join node put this as repeating on a regular interval (once per second) to send the data compiled through every second join the key/value pairs into one payload with commas separated add the measurement name to the payload send the data to a topic once the data is published to a topic, you will be ready for the next step (preparing the integrations) method choose post endpoint http //\<ip address> \<port>/api/v2/write headers (key value pair) accept application/json authorization token your api token content type text/plain; charset=utf 8 the following information could be either in the params or in the topic of the integrations bucket (bucket that your system is set up with, eg plc data) org (org name that your influxdb is set up with, eg litmus) precision (s for seconds, ns for nanoseconds) note alternatively you can input the information in the remote topic of the integrations the topic can be set up as follows http //\<ip address> \<port>/api/v2/write?org=litmus\&bucket=plc data\&precision=s you are now set up to send data to influxdb v2 x via api calls!