How to access the InfluxDB API using the Node-RED request node
Introduction
With Node-RED, you can use the InfluxDB nodes. However, it’s also possible to query the InfluxDB v2 API using the HTTP Request node. This note provides a brief explanation of how it works.
As an example, I will delete a measurement via the API. The InfluxDB v2 API simplifies the process of removing a measurement. I have written another note on how this works using the terminal without using Node-RED.
Below, you will also find an example of a write request that can be used for bulk processing.
How To
Node-RED flow setup
- 
First create a new flow within Node-RED. In the menu choose
Flowsand thenAdd - 
Go to the menu again and choose
Import. Then theImport nodesscreen opens. Paste the JSON below into the text field and clickImport:[{"id":"6b0580dde8c9a5f5","type":"inject","z":"c05125d23d84e735","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":640,"y":240,"wires":[["c6a4fc2ecafa1940"]]},{"id":"c6a4fc2ecafa1940","type":"function","z":"c05125d23d84e735","name":"set payload and headers","func":"msg.payload = {\n \"start\": \"1970-01-01T00:00:00Z\",\n \"stop\": \"2025-12-31T23:59:00Z\",\n \"predicate\": \"_measurement=\\\"YOUR_MEASUREMENT\\\"\"\n}\nmsg.headers = {};\nmsg.headers['Authorization'] = 'Token YOUR_TOKEN';\nmsg.headers['Content-Type'] = 'application/json';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":870,"y":240,"wires":[["005b31a1e984701e"]]},{"id":"005b31a1e984701e","type":"http request","z":"c05125d23d84e735","name":"","method":"POST","ret":"txt","paytoqs":"ignore","url":"http://YOUR_IP:YOUR_PORT/api/v2/delete?org=YOUR_ORGANIZATION&bucket=YOUR_BUCKET","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":1110,"y":240,"wires":[["79d522108d85555d"]]},{"id":"79d522108d85555d","type":"debug","z":"c05125d23d84e735","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1290,"y":240,"wires":[]}]Now the following nodes are within the flow:

 - 
Double click on the
set payload and headersnode. This function node contains the following javascript:msg.payload = {"start": "1970-01-01T00:00:00Z","stop": "2025-12-31T23:59:00Z","predicate": "_measurement=\"YOUR_MEASUREMENT\""}msg.headers = {};msg.headers['Authorization'] = 'Token YOUR_TOKEN';msg.headers['Content-Type'] = 'application/json';return msg;// IMPORTANT: Please read the instructions belowInstructions:
- Required  Replace 
YOUR_MEASUREMENTwith the name of the measurement you want to delete - Required  Replace 
YOUR_TOKENwith your own token 
 - Required  Replace 
 - 
Click
Doneto close theEdit function nodescreen - 
Double click on the
http requestnode. Make sure the following is set:- Method: 
POST - URL: 
http://YOUR_IP:YOUR_PORT/api/v2/delete?org=YOUR_ORGANIZATION&bucket=YOUR_BUCKET 
Instructions:
- Required  Replace 
YOUR_IPandYOUR_PORTwith the IP address and port of InfluxDB. Usually port8086is used but my container is using port3004 - Required  Replace 
YOUR_ORGANIZATIONwith your own organization name. I used the name of my virtual machine for example - Required  Replace 
YOUR_BUCKETwith your own bucket name. Because data of Home Assistant is stored I usedhomeassistant 
 - Method: 
 - 
Click
Doneto close theEdit http request nodescreen - 
Deploythe flow and test by clicking theinjectnode. 
Write example
It is also possible to write time series data in much the same way. Make sure you have followed the steps above and then do the following:
- 
Double click on the
set payload and headersnode and follow the instructions belowmsg.payload = "YOUR_MEASUREMENT,sensor_id=TLM0201 temperature=73.97038159354763,humidity=35.23103248356096";msg.headers = {};msg.headers['Authorization'] = 'Token YOUR_TOKEN';msg.headers['Content-Type'] = 'text/plain; charset=utf-8';msg.headers['Accept'] = 'application/json';return msg;// IMPORTANT: Please read the instructions belowInstructions:
- Required  Replace 
YOUR_MEASUREMENTwith the name of the measurement you want to delete - Required  Replace 
YOUR_TOKENwith your own token - Required  The sensor 
sensor_id=TLM0201is an example of a tag andtemperature=73.97038159354763,humidity=35.23103248356096are examples of fields. Replace with your own tag and fields 
 - Required  Replace 
 - 
Click
Doneto close theEdit function nodescreen - 
Double click on the
http requestnode. Make sure the following is set:- Method: 
POST - URL: 
http://YOUR_IP:YOUR_PORT/api/v2/write?org=YOUR_ORGANIZATION&bucket=YOUR_BUCKET&precision=ms 
Instructions:
- Required  Replace 
YOUR_IPandYOUR_PORTwith the IP address and port of InfluxDB. Usually port8086is used but my container is using port3004 - Required  Replace 
YOUR_ORGANIZATIONwith your own organization name. I used the name of my virtual machine for example - Required  Replace 
YOUR_BUCKETwith your own bucket name. Because data of Home Assistant is stored I usedhomeassistant 
 - Method: 
 - 
Click
Doneto close theEdit http request nodescreen - 
Deploythe flow and test by clicking theinjectnode. 
I did quite a bit of testing and finally made the choice not to use the InfluxDB nodes because I feel like I have more control if I call the InfluxDB API in my own way. But that is a personal choice.
No comments found for this note.
Join the discussion for this note on Github. Comments appear on this page instantly.