# Issues on exporting / importing flows using the api

**URL:** <https://discourse.nodered.org/t/issues-on-exporting-importing-flows-using-the-api/84900>\
**Category:** General\
**Created:** [25 January 2024 08:57 UTC](https://discourse.nodered.org/t/issues-on-exporting-importing-flows-using-the-api/84900 "2024-01-25T08:57:52Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![msmthng](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/msmthng/32/87616_2.png) [@msmthng](https://discourse.nodered.org/u/msmthng)\
**Post date:** [25 January 2024 08:57 UTC](https://discourse.nodered.org/t/issues-on-exporting-importing-flows-using-the-api/84900/1 "2024-01-25T08:57:52Z")

</div>

i have two instances of node red running, i would like to copy a given flow from instance one to instance two.

flow\_id = '8429e42d5be21f50'  
handler.get\_flow(flow\_id)  
print(json.dumps(flow, indent=4))

provides:

```auto
{'disabled': False,
 'env': [],
 'id': '8429e42d5be21f50',
 'info': '',
 'label': 'Simple-Export',
 'nodes': [{'crontab': '',
            'id': '5f74a245600e657d',
            'name': '',
            'once': False,
            'onceDelay': 0.1,
            'payload': '',
            'payloadType': 'date',
            'props': [{'p': 'payload'}, {'p': 'topic', 'vt': 'str'}],
            'repeat': '',
            'topic': '',
            'type': 'inject',
            'wires': [['a009c29205ae3027']],
            'x': 500,
            'y': 260,
            'z': '8429e42d5be21f50'},
           {'action': '',
            'from': '',
            'id': 'a009c29205ae3027',
            'name': '',
            'property': '',
            'reg': False,
            'rules': [{'p': 'payload',
                       'pt': 'msg',
                       't': 'set',
                       'to': 'set',
                       'tot': 'str'}],
            'to': '',
            'type': 'change',
            'wires': [['aef6a32098eda1e8']],
            'x': 750,
            'y': 260,
            'z': '8429e42d5be21f50'},
           {'active': True,
            'complete': 'payload',
            'console': False,
            'id': 'aef6a32098eda1e8',
            'name': '',
            'statusType': 'auto',
            'statusVal': 'payload',
            'targetType': 'msg',
            'tosidebar': True,
            'tostatus': True,
            'type': 'debug',
            'wires': [],
            'x': 1010,
            'y': 260,
            'z': '8429e42d5be21f50'}]}

            "rules": [
                {
                    "t": "set",
                    "p": "payload",
                    "pt": "msg",
                    "to": "set",
                    "tot": "str"
                }
            ],
            "action": "",
            "property": "",
            "from": "",
            "to": "",
            "reg": false,
            "x": 750,
            "y": 260,
            "wires": [
                [
                    "aef6a32098eda1e8"
                ]
            ]
        },
        {
            "id": "aef6a32098eda1e8",
            "type": "debug",
            "z": "8429e42d5be21f50",
            "name": "",
            "active": true,
            "tosidebar": true,
            "console": false,
            "tostatus": true,
            "complete": "payload",
            "targetType": "msg",
            "statusVal": "payload",
            "statusType": "auto",
            "x": 1010,
            "y": 260,
            "wires": []
        }
    ]
}

```

after copying that one to the second instance using:

handler.copy\_flow(flow\_id)

i get:  
200  
{'id': '435a67050951dc8a'}

the code used for sending the flow was:  
r = requests.post('https://{destination}/flow'.format(destination=self.destination), data=flow, headers=self.headers)

in the node-red log i see:

```auto
25 Jan 09:52:12 - [info] Waiting for missing types to be registered:
25 Jan 09:52:12 - [info] - undefined
25 Jan 09:52:12 - [info] Adding flow: Simple-Export [435a67050951dc8a]

```

if i reload the flows in the destination installation of node red i get following error:

Cannot read properties of undefined (reading 'substring')

i don't have an idea where this undefined is comming from.

thanks for help!

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [25 January 2024 10:31 UTC](https://discourse.nodered.org/t/issues-on-exporting-importing-flows-using-the-api/84900/2 "2024-01-25T10:31:25Z")

</div>

Does the Node-red instance you are importing into have the cron node installed?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [25 January 2024 10:34 UTC](https://discourse.nodered.org/t/issues-on-exporting-importing-flows-using-the-api/84900/3 "2024-01-25T10:34:07Z")

</div>

> [@zenofmud](#):
>
> cron node installed?

Paul, you probably didnt notice the `type` property is `"inject"` (`crontab` is a property of the inject node)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [25 January 2024 10:37 UTC](https://discourse.nodered.org/t/issues-on-exporting-importing-flows-using-the-api/84900/4 "2024-01-25T10:37:09Z")

</div>

> [@msmthng](#):
>
> `'once': False,`

Somewhere in your code, you are trying to set a flow with a value of `False` by the looks of it (_false_ in JavaScript/JSON is `false` not `False`)

Are you processing via `python`?

---

<div class="post-metadata">

**Author:** ![msmthng](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/msmthng/32/87616_2.png) [@msmthng](https://discourse.nodered.org/u/msmthng)\
**Post date:** [25 January 2024 10:41 UTC](https://discourse.nodered.org/t/issues-on-exporting-importing-flows-using-the-api/84900/5 "2024-01-25T10:41:44Z")

</div>

yes iam using a python script for executing the api calls

---

<div class="post-metadata">

**Author:** ![msmthng](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/msmthng/32/87616_2.png) [@msmthng](https://discourse.nodered.org/u/msmthng)\
**Post date:** [25 January 2024 10:43 UTC](https://discourse.nodered.org/t/issues-on-exporting-importing-flows-using-the-api/84900/6 "2024-01-25T10:43:22Z")

</div>

crontab ist installed on the source system, but not yet on the destination system.  
iam installing only modules used (identified as used) by the source flow.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [25 January 2024 10:44 UTC](https://discourse.nodered.org/t/issues-on-exporting-importing-flows-using-the-api/84900/7 "2024-01-25T10:44:55Z")

</div>

> [@msmthng](#):
>
> crontab ist installed on the source system, but not yet on the destination system.

As explained above, `crontab` is not a node type.

> [@Steve-Mcl](#):
>
> the `type` property is `"inject"` (`crontab` is a property of the inject node)

A node type is defined by the `type` field!

---

<div class="post-metadata">

**Author:** ![msmthng](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/msmthng/32/87616_2.png) [@msmthng](https://discourse.nodered.org/u/msmthng)\
**Post date:** [25 January 2024 10:45 UTC](https://discourse.nodered.org/t/issues-on-exporting-importing-flows-using-the-api/84900/8 "2024-01-25T10:45:52Z")

</div>

flows.json before the import:

```auto
[
    {
        "id": "5c1bbfa9991b92e6",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "8e869e83530d854d",
        "type": "ui_base",
        "theme": {
            "name": "theme-light",
            "lightTheme": {
                "default": "#0094CE",
                "baseColor": "#0094CE",
                "baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif",
                "edited": true,
                "reset": false
            },
            "darkTheme": {
                "default": "#097479",
                "baseColor": "#097479",
                "baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif",
                "edited": false
            },
            "customTheme": {
                "name": "Untitled Theme 1",
                "default": "#4B7930",
                "baseColor": "#4B7930",
                "baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"
            },
            "themeState": {
                "base-color": {
                    "default": "#0094CE",
                    "value": "#0094CE",
                    "edited": false
                },
                "page-titlebar-backgroundColor": {
                    "value": "#0094CE",
                    "edited": false
                },
                "page-backgroundColor": {
                    "value": "#fafafa",
                    "edited": false
                },
                "page-sidebar-backgroundColor": {
                    "value": "#ffffff",
                    "edited": false
                },
                "group-textColor": {
                    "value": "#1bbfff",
                    "edited": false
                },
                "group-borderColor": {
                    "value": "#ffffff",
                    "edited": false
                },
                "group-backgroundColor": {
                    "value": "#ffffff",
                    "edited": false
                },
                "widget-textColor": {
                    "value": "#111111",
                    "edited": false
                },
                "widget-backgroundColor": {
                    "value": "#0094ce",
                    "edited": false
                },
                "widget-borderColor": {
                    "value": "#ffffff",
                    "edited": false
                },
                "base-font": {
                    "value": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"
                }
            },
            "angularTheme": {
                "primary": "indigo",
                "accents": "blue",
                "warn": "red",
                "background": "grey",
                "palette": "light"
            }
        },
        "site": {
            "name": "Node-RED Dashboard",
            "hideToolbar": "false",
            "allowSwipe": "false",
            "lockMenu": "false",
            "allowTempTheme": "true",
            "dateFormat": "DD.MM.YYYY",
            "sizes": {
                "sx": 48,
                "sy": 48,
                "gx": 6,
                "gy": 6,
                "cx": 6,
                "cy": 6,
                "px": 0,
                "py": 0
            }
        }
    }
]

```

after the import:

```auto
[
    {
        "id": "5c1bbfa9991b92e6",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "8e869e83530d854d",
        "type": "ui_base",
        "theme": {
            "name": "theme-light",
            "lightTheme": {
                "default": "#0094CE",
                "baseColor": "#0094CE",
                "baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif",
                "edited": true,
                "reset": false
            },
            "darkTheme": {
                "default": "#097479",
                "baseColor": "#097479",
                "baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif",
                "edited": false
            },
            "customTheme": {
                "name": "Untitled Theme 1",
                "default": "#4B7930",
                "baseColor": "#4B7930",
                "baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"
            },
            "themeState": {
                "base-color": {
                    "default": "#0094CE",
                    "value": "#0094CE",
                    "edited": false
                },
                "page-titlebar-backgroundColor": {
                    "value": "#0094CE",
                    "edited": false
                },
                "page-backgroundColor": {
                    "value": "#fafafa",
                    "edited": false
                },
                "page-sidebar-backgroundColor": {
                    "value": "#ffffff",
                    "edited": false
                },
                "group-textColor": {
                    "value": "#1bbfff",
                    "edited": false
                },
                "group-borderColor": {
                    "value": "#ffffff",
                    "edited": false
                },
                "group-backgroundColor": {
                    "value": "#ffffff",
                    "edited": false
                },
                "widget-textColor": {
                    "value": "#111111",
                    "edited": false
                },
                "widget-backgroundColor": {
                    "value": "#0094ce",
                    "edited": false
                },
                "widget-borderColor": {
                    "value": "#ffffff",
                    "edited": false
                },
                "base-font": {
                    "value": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"
                }
            },
            "angularTheme": {
                "primary": "indigo",
                "accents": "blue",
                "warn": "red",
                "background": "grey",
                "palette": "light"
            }
        },
        "site": {
            "name": "Node-RED Dashboard",
            "hideToolbar": "false",
            "allowSwipe": "false",
            "lockMenu": "false",
            "allowTempTheme": "true",
            "dateFormat": "DD.MM.YYYY",
            "sizes": {
                "sx": 48,
                "sy": 48,
                "gx": 6,
                "gy": 6,
                "cx": 6,
                "cy": 6,
                "px": 0,
                "py": 0
            }
        }
    },
    {
        "type": "tab",
        "label": "Simple-Export",
        "id": "916297197f476c45",
        "info": "",
        "disabled": "False"
    },
    "id",
    "type",
    "z",
    "name",
    "props",
    "repeat",
    "crontab",
    "once",
    "onceDelay",
    "topic",
    "payload",
    "payloadType",
    "x",
    "y",
    "wires",
    "id",
    "type",
    "z",
    "name",
    "rules",
    "action",
    "property",
    "from",
    "to",
    "reg",
    "x",
    "y",
    "wires",
    "id",
    "type",
    "z",
    "name",
    "active",
    "tosidebar",
    "console",
    "tostatus",
    "complete",
    "targetType",
    "statusVal",
    "statusType",
    "x",
    "y",
    "wires"
]

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [25 January 2024 10:50 UTC](https://discourse.nodered.org/t/issues-on-exporting-importing-flows-using-the-api/84900/9 "2024-01-25T10:50:09Z")

</div>

Where did you get these JSON from? From the flows file? from the API?

You do realise the 2nd JSON is completely invalid (from the POV of node-red)

> [@msmthng](#):
>
> ```auto
> },
> {
> "type": "tab",
> "label": "Simple-Export",
> "id": "916297197f476c45",
> "info": "",
> "disabled": "False"
> }, // <-- valid object/node-red node
> "id", // <-- invalid
> "type", // <-- invalid
> "z", // <-- invalid
> // etc, etc, etc until the end of the file 
> 
> ```

* * *

You need to capture to file (for later inspection) the following:

- what was retrieved from instance 1
- what was sent to instance 2
- what is in flows file of instance 2
  - before
  - after

Once you have this, you will see where your processing is being broken

---

<div class="post-metadata">

**Author:** ![msmthng](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/msmthng/32/87616_2.png) [@msmthng](https://discourse.nodered.org/u/msmthng)\
**Post date:** [25 January 2024 11:01 UTC](https://discourse.nodered.org/t/issues-on-exporting-importing-flows-using-the-api/84900/10 "2024-01-25T11:01:33Z")

</div>

yes understootd, i thought that maybe the property causes the issue because it is not installed in the desitnation system. i reduced the exported flow to 🙂

```auto
{
    "id": "8429e42d5be21f50",
    "label": "Simple-Export",
    "disabled": false,
    "info": "",
    "env": [],
    "nodes": [
        {
            "id": "a009c29205ae3027",
            "type": "change",
            "z": "8429e42d5be21f50",
            "name": "",
            "rules": [
                {
                    "t": "set",
                    "p": "payload",
                    "pt": "msg",
                    "to": "set",
                    "tot": "str"
                }
            ],
            "action": "",
            "property": "",
            "from": "",
            "to": "",
            "reg": false,
            "x": 750,
            "y": 260,
            "wires": [
                [
                    "aef6a32098eda1e8"
                ]
            ]
        },
        {
            "id": "aef6a32098eda1e8",
            "type": "debug",
            "z": "8429e42d5be21f50",
            "name": "",
            "active": true,
            "tosidebar": true,
            "console": false,
            "tostatus": true,
            "complete": "payload",
            "targetType": "msg",
            "statusVal": "payload",
            "statusType": "auto",
            "x": 1010,
            "y": 260,
            "wires": []
        }
    ]
}

```

i have still the same issue.

should it worl to use the api on instance one with get /flow/flowid and taking the result json and use it on instance two two with put /flow ?

---

<div class="post-metadata">

**Author:** ![msmthng](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/msmthng/32/87616_2.png) [@msmthng](https://discourse.nodered.org/u/msmthng)\
**Post date:** [25 January 2024 11:05 UTC](https://discourse.nodered.org/t/issues-on-exporting-importing-flows-using-the-api/84900/11 "2024-01-25T11:05:12Z")

</div>

> [@Steve-Mcl](#):
>
> You need to capture to file (for later inspection) the following:
> 
> - what was retrieved from instance 1
> - what was sent to instance 2
> - what is in flows file of instance 2
> - before
> - after
> 
> Once you have this, you will see where your processing is being broken

that's why i am wondering:  
the json from my last reply is what i have retreived from a as json and what i have sent to b as json

---

<div class="post-metadata">

**Author:** ![msmthng](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/msmthng/32/87616_2.png) [@msmthng](https://discourse.nodered.org/u/msmthng)\
**Post date:** [25 January 2024 11:23 UTC](https://discourse.nodered.org/t/issues-on-exporting-importing-flows-using-the-api/84900/12 "2024-01-25T11:23:27Z")

</div>

thx for the dumping hint, i found the issue - it was sent as get params.

wondering that there is no error thrown on the api call.

---

<div class="post-metadata">

**Author:** ![msmthng](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/msmthng/32/87616_2.png) [@msmthng](https://discourse.nodered.org/u/msmthng)\
**Post date:** [25 January 2024 11:35 UTC](https://discourse.nodered.org/t/issues-on-exporting-importing-flows-using-the-api/84900/13 "2024-01-25T11:35:05Z")

</div>

is there a way to "copy" a flow including their related config nodes like broker on the mqtt nodes?

---

<div class="post-metadata">

**Author:** ![Barbudor](https://avatars.discourse-cdn.com/v4/letter/b/4af34b/32.png) [@Barbudor](https://discourse.nodered.org/u/Barbudor)\
**Post date:** [5 March 2024 10:33 UTC](https://discourse.nodered.org/t/issues-on-exporting-importing-flows-using-the-api/84900/14 "2024-03-05T10:33:08Z")

</div>

Hello  
I'm in the same situation as @msmthng  
I would like to backup individual flows automatically in the same format as the "Export - current flow" menu does which mean including subflows and configuration nodes.

I have been able to use the API for individual flow: `GET /flow/:id` [GET /flow/:id : Node-RED](https://nodered.org/docs/api/admin/methods/get/flow/)  
But as you know, subflows and configuration nodes are not part of it

Is there a way to get that from a single API call ?  
Or must I go through the complete JSON with `GET /flows` or even reading the `flows.json` file and parse it myself ?

I haven't looked into node-red code, but I can do if you can point me to the part of the code that match the "Export - current flow" menu.

Thanks

---

<div class="post-metadata">

**Author:** ![gregorius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorius/32/73816_2.png) [@gregorius](https://discourse.nodered.org/u/gregorius)\
**Post date:** [5 March 2024 11:05 UTC](https://discourse.nodered.org/t/issues-on-exporting-importing-flows-using-the-api/84900/15 "2024-03-05T11:05:18Z")

</div>

This [code](https://github.com/node-red/node-red/blob/e8ddee24a9944e57d186f02b081295c56a45b67c/packages/node_modules/%40node-red/editor-client/src/js/ui/clipboard.js#L710-L723) might help - it's from the NR codebase and does an flow export in the client, not server. It generates the same format that export flow uses.

---

<div class="post-metadata">

**Author:** ![Barbudor](https://avatars.discourse-cdn.com/v4/letter/b/4af34b/32.png) [@Barbudor](https://discourse.nodered.org/u/Barbudor)\
**Post date:** [5 March 2024 19:44 UTC](https://discourse.nodered.org/t/issues-on-exporting-importing-flows-using-the-api/84900/16 "2024-03-05T19:44:07Z")

</div>

Thanks @gregorius  
I wouldn't event thought about looking in the client code base  
I will investigate that path

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [3 June 2024 19:44 UTC](https://discourse.nodered.org/t/issues-on-exporting-importing-flows-using-the-api/84900/17 "2024-06-03T19:44:54Z")

</div>

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