Get configuration with REST API with Node-Red

I am already trying different cook books to get information from the lora server like application list and device list per application. Till now I am still far from any success. Is there somewhere an example from a working Node-Red flow in combination with the brocaar server. I am not that experienced with REST API but a working example I can extend that I will have my needs.

1 Like

I still wondering how to get REST API working in Node-Red. It is probably not hard if you know how but till now I am still not successful to get it working. Who can help me with a simple working example export from Node-Red. That would really help me to get started.

I used the nodered code below to create my devices in Chirpstack from a CSV file. It uses the device API.

[{"id":"f3075d97.50e828","type":"tab","label":"Create Device API","disabled":false,"info":"Add new device to Chirpstack"},{"id":"6ef34cc5.21fa5c","type":"http request","z":"f3075d97.50e828","name":"api/devices","method":"POST","ret":"txt","paytoqs":false,"url":"http://localhost:8080/api/devices","tls":"","persist":false,"proxy":"","authType":"","x":710,"y":280,"wires":[["872d1c73.be45a"]]},{"id":"872d1c73.be45a","type":"debug","z":"f3075d97.50e828","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":950,"y":280,"wires":[]},{"id":"7b5108c7.a13d2","type":"function","z":"f3075d97.50e828","name":"createHeaders","func":"msg.headers = {};\nmsg.headers['Content-Type'] = 'application/json';\nmsg.headers['Accept'] = 'application/json';\nmsg.headers['Grpc-Metadata-Authorization'] = 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJjaGlycHN0YWNrLWFwcGxpY2F0aW9uLXNlcnZlciIsImV4cCI6MTU3OTQ5NTE4NCwiaXNzIjoiY2hpcnBzdGFjay1hcHBsaWNhdGlvbi1zZXJ2ZXIiLCJuYmYiOjE1Nzk0MDg3ODQsInN1YiI6InVzZXIiLCJ1c2VybmFtZSI6ImFkbWluIn0.JCzKz9jnOGkRvJyyP4QZk3f3oao9WCY4opowyhHvVRA'\nreturn msg;","outputs":1,"noerr":0,"x":480,"y":280,"wires":[["6ef34cc5.21fa5c"]]},{"id":"2119df93.67b16","type":"template","z":"f3075d97.50e828","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\n    \"device\": {\n        \"applicationID\": \"1\",\n        \"description\": \"{{desc}}\",\n        \"devEUI\": \"{{deveui}}\",\n        \"deviceProfileID\": \"82b4a8c3-2ba9-4292-a86d-348866784c77\",\n        \"name\": \"{{name}}\",\n        \"referenceAltitude\": 0,\n        \"skipFCntCheck\": true,\n        \"tags\": {},\n        \"variables\": {}\n    }\n}","output":"str","x":300,"y":280,"wires":[["7b5108c7.a13d2"]]},{"id":"522e4495.16a0e4","type":"function","z":"f3075d97.50e828","name":"","func":"msg.payload = \"\"\n//var myDesc = flow.get(\"desc\");\n//var myeui = flow.get(\"eui\");\n//var myname = flow.get(\"name\")\nmsg.deveui = flow.get(\"eui\")\nmsg.name = flow.get(\"name\")\nmsg.desc = flow.get(\"desc\")\nreturn msg;","outputs":1,"noerr":0,"x":130,"y":280,"wires":[["2119df93.67b16"]]},{"id":"47349348.f9681c","type":"file in","z":"f3075d97.50e828","name":"","filename":"/home/pi/Documents/nassauValveDetails.csv","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":280,"y":420,"wires":[["22beca23.25c5f6"]]},{"id":"22beca23.25c5f6","type":"csv","z":"f3075d97.50e828","name":"","sep":",","hdrin":true,"hdrout":"","multi":"one","ret":"\\n","temp":"","skip":"0","strings":true,"x":490,"y":420,"wires":[["1c69888b.4225a7"]]},{"id":"bfe0a597.f07418","type":"inject","z":"f3075d97.50e828","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":80,"y":360,"wires":[["47349348.f9681c"]]},{"id":"1c69888b.4225a7","type":"function","z":"f3075d97.50e828","name":"","func":"msg.name=msg.payload.Name\nmsg.deveui=msg.payload.Devid\nmsg.desc=\"Irrigation Valve\"\nreturn msg;","outputs":1,"noerr":0,"x":630,"y":420,"wires":[["2119df93.67b16"]]}]

berrySkies, thank you very much for this example, I had some other priorities in the mean time unfortunatly. I am now only struggling with getting the token. Because we are still using a very old brocaar server and it is managed by another team, I think I have a challenge to get this solved without an upgrade from the lora sever.