How to add new flows to a running Node-RED instance with the admin API

I'm trying to use the Admin API to add flows to a running Node-RED instance. The flow files are downloaded/exported with the build in Node-RED editor.

I've tried using the POST /flows and it works adding the first flow, but when I want to add another one, the old flows disappear.

I've also tried using the POST /flow, but I'm not sure how I need to set-up the exported Flow JSON, so it can be added. I keep getting "Unexpected error : Missing nodes property".

I'd appreciate any tips on how I can get this to work.

Welcome to the forums @markoz

Is what you need to use to add an additional flow tab, flows replaces everything that you upload.

According to the guide.
it will be something like this.

{
  "id": "91ad451.f6e52b8",
  "label": "My New (additional) Flow",
  "nodes": [
    {
      "id": "abeb0d0dade32de5",
      "type": "inject",
      "z": "e3aa352edc6e5a3f",
      "name": "",
      "props": [
        {
          "p": "payload"
        },
        {
          "p": "topic",
          "vt": "str"
        }
      ],
      "repeat": "",
      "crontab": "",
      "once": false,
      "onceDelay": 0.1,
      "topic": "",
      "payload": "",
      "payloadType": "date",
      "x": 190,
      "y": 130,
      "wires": [
        [
          "4b3c5f62b2af4c96"
        ]
      ]
    },
    {
      "id": "4b3c5f62b2af4c96",
      "type": "debug",
      "z": "e3aa352edc6e5a3f",
      "name": "debug 2",
      "active": true,
      "tosidebar": true,
      "console": false,
      "tostatus": false,
      "complete": "false",
      "statusVal": "",
      "statusType": "auto",
      "x": 435,
      "y": 130,
      "wires": [
        
      ]
    }
  ],
  "configs": []
}

https://nodered.org/docs/api/admin/methods/post/flow/

Thank you for the answer. I tried it out with this way and it does work, but it doesn't post if I also try to add subflows. Is there a way to also add subflows?

I don't have much xp with the API directly.
But I believe it should support subflows when adding a new flow

{
  "id": "91ad451.f6e52b8",
  "label": "My New (additional) Flow",
  "nodes": [ ... ],
  "subflows": [ ... ], /* <-- HERE */
  "configs": [ ... ]
}

See : Types : Node-RED

I don't know how I missed that. Thank you for all the help.

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.