Node-RED – Example – Add flow from commandline
It is possible to add a flow in Node-red from the commandline using CURL and POST commands: https://nodered.org/docs/api/admin/methods/post/flow/
Append flow from plain commandline
use this commandline with JSON object to import a flow into Node-red:
1 |
curl -X POST http://localhost:1880/flow -H 'content-type: application/json' -d '{"id": "91ad451.f6e52b8", "label": "Sheet 1", "nodes": [ ], "configs": [ ]}' |
you will recieve an flow ID code back when all went ok: {"id":"9d987943.ad2448"}
On the dashboard you will get the message:
Wich you can then merge with your existing flows:
Example to replace all flows with the one stored in a json file:
1 |
<div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><div class="crayon-line" id="urvanov-syntax-highlighter-6741620994b8e373607133-1"><span class="crayon-v">curl</span><span class="crayon-h"> </span><span class="crayon-o">-</span><span class="crayon-i">X</span><span class="crayon-h"> </span><span class="crayon-e">POST </span><span class="crayon-v">http</span><span class="crayon-o">:</span><span class="crayon-c">//localhost:1880/flows -H "Content-Type: application/json" --data "@myflow.json" |
Example to add a flow stored in a json file:
you need to put in nodes:”;[ ] tags…
1 |
<span class="crayon-v">curl</span><span class="crayon-h"> </span><span class="crayon-o">-</span><span class="crayon-i">X</span><span class="crayon-h"> </span><span class="crayon-e">POST </span><span class="crayon-v">http</span><span class="crayon-o">:</span><span class="crayon-c">//localhost:1880/flow -H "Content-Type: application/json" --data "@myflow.json" |
Append flow from a file
Create a file in your homefolder named: addflow
With JSON contents:
1 2 3 4 5 6 |
{ "id": "91ad451.f6e52b8", "label": "Sheet 1", "nodes": [ ], "configs": [ ] } |
Then use this commandline to add it to nodered:
1 |
curl -X POST http://localhost:1880/flow -H 'content-type: application/json' -d @addflow |
you will recieve an flow ID code back when all went ok: {"id":"9d987943.ad2448"}
With pwd (print working directory) command:
1 |
curl -X POST http://localhost:1880/flow -H 'content-type: application/json' -d @$(pwd)/addflow |
Replace all flows from a file
Note: this is exactly the exported flow format of Node-red
Posting to /flows
replaces the entire flow configuration.
Create a file in your homefolder named: flows
With JSON contents:
1 |
[{"id":"bed4fb91.f40858","type":"tab","label":"Sheet 1","disabled":false,"info":""},{"id":"3bcc44ce.14cafc","type":"inject","z":"bed4fb91.f40858","name":"Trigger","topic":"","payload":"","payloadType":"date","repeat":"3","crontab":"","once":false,"onceDelay":0.1,"x":340,"y":140,"wires":[[]]}] |
Then use this commandline to add it to nodered:
1 |
curl -X POST http://localhost:1880/flows -H 'content-type: application/json' -d @flows |
you will recieve an flow ID code back when all went ok: {"id":"9d987943.ad2448"}
With pwd (print working directory) command:
1 |
curl -X POST http://localhost:1880/flows -H 'content-type: application/json' -d @$(pwd)/flows |