# Node Red returning nodes when accessing /flows in API

**URL:** <https://discourse.nodered.org/t/node-red-returning-nodes-when-accessing-flows-in-api/54625>\
**Category:** General\
**Tags:** node-red-dashboard\
**Created:** [2 December 2021 11:21 UTC](https://discourse.nodered.org/t/node-red-returning-nodes-when-accessing-flows-in-api/54625 "2021-12-02T11:21:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mmijoski](https://avatars.discourse-cdn.com/v4/letter/m/e56c9b/32.png) [@mmijoski](https://discourse.nodered.org/u/mmijoski)\
**Post date:** [2 December 2021 11:21 UTC](https://discourse.nodered.org/t/node-red-returning-nodes-when-accessing-flows-in-api/54625/1 "2021-12-02T11:21:40Z")

</div>

I tried to create a flow using the API. I submitted the data for a flow along with all nodes and their connections to POST /flows, but some error happened which caused the dashboard to show

```auto
Error adding flows

Cannot read properties of undefined (reading 'substring')

```

Now, when I access GET /flows it returns some flows that I already had implemented but the other problem is that it also returns a lot of nodes.  
For example, this is also returned in the list:

```auto
{
        "id": "baba6511.294428",
        "type": "mqtt-broker",
        "name": "...",
        "broker": "...",
        "port": "2884",
        "clientid": "3",
        "usetls": false,
        "compatmode": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "sessionExpiry": ""
    },

```

When I try to access GET /flows/baba6511.294428, it returns a not found error which I don't get. Because if this is returned in the list, it should be an actual flow.  
Any help is appreciated.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [2 December 2021 11:45 UTC](https://discourse.nodered.org/t/node-red-returning-nodes-when-accessing-flows-in-api/54625/2 "2021-12-02T11:45:05Z")

</div>

> [@mmijoski](#):
>
> Now, when I access GET /flows it returns some flows that I already had implemented but the other problem is that it also returns a lot of nodes

The `/flows` endpoint returns the complete flow configuration - its everything that is running, flows/subflows/nodes/config nodes/groups - everything.

> [@mmijoski](#):
>
> When I try to access GET /flows/baba6511.294428, it returns a not found error which I don't get. Because if this is returned in the list, it should be an actual flow.

The end point for an individual flow is `/flow/:id` not `/flows/:id`. See [GET /flow/:id : Node-RED](https://nodered.org/docs/api/admin/methods/get/flow/)

---

<div class="post-metadata">

**Author:** ![mmijoski](https://avatars.discourse-cdn.com/v4/letter/m/e56c9b/32.png) [@mmijoski](https://discourse.nodered.org/u/mmijoski)\
**Post date:** [2 December 2021 12:23 UTC](https://discourse.nodered.org/t/node-red-returning-nodes-when-accessing-flows-in-api/54625/3 "2021-12-02T12:23:54Z")

</div>

Thank you for the quick respone.  
The `/flows/:id` was a typo.  
Is there a reason why I'm getting the error above or is there a way to revert it? Unfortunately I don't have a backup of the flows and I'm not sure whether restarting the service would help?

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [2 December 2021 12:39 UTC](https://discourse.nodered.org/t/node-red-returning-nodes-when-accessing-flows-in-api/54625/4 "2021-12-02T12:39:01Z")

</div>

> [@mmijoski](#):
>
> Is there a reason why I'm getting the error above or is there a way to revert it?

We'd need a lot more detail on what you actually did to understand why you're hitting an error.

If you posted a new set of flows to `/flows` that will have replaced _everything_ that was there.

If you have not done anything post to /flows since, you may find a backup of your flows file in your user directory. If your normal flows file is called `flows.json` have a look for `.flows.json.backup`

---

<div class="post-metadata">

**Author:** ![mmijoski](https://avatars.discourse-cdn.com/v4/letter/m/e56c9b/32.png) [@mmijoski](https://discourse.nodered.org/u/mmijoski)\
**Post date:** [2 December 2021 13:01 UTC](https://discourse.nodered.org/t/node-red-returning-nodes-when-accessing-flows-in-api/54625/5 "2021-12-02T13:01:37Z")

</div>

The problem, I think, was that when I was sending the data in Python, the module didn't set the correct content type, i.e it did not send it as JSON.  
When I send the exact same data in Postman as JSON everything works normally.

This is my local flows.json file:

```auto
[
    {
        "id": "f6f2187d.f17ca8",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": ""
    },
    {
        "type": "tab",
        "label": "fdsfdsf",
        "id": "cad5fcf48ff2e192"
    },
    "id",
    "type",
    "name",
    "topic",
    "qos",
    "datatype",
    "broker",
    "nl",
    "rap",
    "x",
    "y",
    "wires",
    "id",
    "type",
    "name",
    "property",
    "action",
    "pretty",
    "x",
    "y",
    "wires",
    "id",
    "type",
    "name",
    "active",
    "tosidebar",
    "console",
    "tostatus",
    "complete",
    "targetType",
    "statusVal",
    "statusType",
    "x",
    "y",
    "wires",
    "id",
    "type",
    "name",
    "func",
    "outputs",
    "noerr",
    "initialize",
    "finalize",
    "libs",
    "x",
    "y",
    "wires",
    "id",
    "type",
    "name",
    "active",
    "tosidebar",
    "console",
    "tostatus",
    "complete",
    "statusVal",
    "statusType",
    "x",
    "y",
    "wires",
    "id",
    "type",
    "name",
    "topic",
    "qos",
    "retain",
    "respTopic",
    "contentType",
    "userProps",
    "correl",
    "expiry",
    "broker",
    "x",
    "y",
    "wires",
    "info"
]

```

Is there anything else that would help you in pointing me to where the problem lies and how to revert it?

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [2 December 2021 13:04 UTC](https://discourse.nodered.org/t/node-red-returning-nodes-when-accessing-flows-in-api/54625/6 "2021-12-02T13:04:26Z")

</div>

It seems we need to add some additional validation to those routes to handle badly formatted requests.

> [@mmijoski](#):
>
> Is there anything else that would help you in pointing me to where the problem lies and how to revert it?

Have you checked to see if the backup file exists? If not, then there's nothing else we can do.

If you're experimenting with programmatically changing things, you really should make sure you have a backup if/when it goes wrong.

---

<div class="post-metadata">

**Author:** ![mmijoski](https://avatars.discourse-cdn.com/v4/letter/m/e56c9b/32.png) [@mmijoski](https://discourse.nodered.org/u/mmijoski)\
**Post date:** [2 December 2021 13:55 UTC](https://discourse.nodered.org/t/node-red-returning-nodes-when-accessing-flows-in-api/54625/7 "2021-12-02T13:55:32Z")

</div>

Thank you for the help.

If anyone else stumbles upon this, I've fixed it by removing all unecessary inputs in the `flows.json` file i.e.

```auto
 "id",
    "type",
    "name",
    "topic",
    "qos",
    "datatype",
    "broker",
    "nl",
    "rap",
    "x",
    "y",
    "wires",
    "id",
    "type",
    "name",
    "property",
    "action",
    "pretty",
    "x",
    "y",
    "wires",
    "id",
    "type",
    "name",
    "active",
    "tosidebar",
    "console",
    "tostatus",
    "complete",
    "targetType",
    "statusVal",
    "statusType",
    "x",
    "y",
    "wires",
    "id",
    "type",
    "name",
    "func",
    "outputs",
    "noerr",
    "initialize",
    "finalize",
    "libs",
    "x",
    "y",
    "wires",
    "id",
    "type",
    "name",
    "active",
    "tosidebar",
    "console",
    "tostatus",
    "complete",
    "statusVal",
    "statusType",
    "x",
    "y",
    "wires",
    "id",
    "type",
    "name",
    "topic",
    "qos",
    "retain",
    "respTopic",
    "contentType",
    "userProps",
    "correl",
    "expiry",
    "broker",
    "x",
    "y",
    "wires",
    "info"

```

and then restarting `node-red`.

---

<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:** [31 January 2022 13:55 UTC](https://discourse.nodered.org/t/node-red-returning-nodes-when-accessing-flows-in-api/54625/8 "2022-01-31T13:55:40Z")

</div>

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