Trigger NodeRed flow from postman

I am new to NodeRED and I'm testing out the APIs. I am trying to Post/trigger a flow on nodeRED through postman.

According to the api documentation, something like this should work:

curl --location --request POST 'http://localhost:1880/flows' \
--header 'Content-Type: application/json' \
--header 'Node-RED-Deployment-Type: full' \
--data-raw 
[
    {
        "id": "01ef5ccf5a7ea370",
        "type": "tab",
        "label": "Flow 2",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "58ffae9d.a7005",
        "type": "debug",
        "z": "01ef5ccf5a7ea370",
        "name": "",
        "active": true,
        "complete": false,
        "x": 550,
        "y": 180,
        "wires": []
    },
    {
        "id": "17626462.e89d9c",
        "type": "inject",
        "z": "01ef5ccf5a7ea370",
        "name": "",
        "repeat": "",
        "once": false,
        "topic": "",
        "payload": "",
        "x": 150,
        "y": 180,
        "wires": [
            [
                "2921667d.d6de9a"
            ]
        ]
    },
    {
        "id": "2921667d.d6de9a",
        "type": "function",
        "z": "01ef5ccf5a7ea370",
        "name": "Format timestamp",
        "func": "// Create a Date object from the payload\nvar date = new Date(msg.payload);\n// Change the payload to be a formatted Date string\nmsg.payload = date.toString();\n// Return the message so it can be sent on\nreturn msg;",
        "outputs": 1,
        "x": 350,
        "y": 180,
        "wires": [
            [
                "58ffae9d.a7005"
            ]
        ]
    }
]

But when I send this on postman, I get a 204 No Content response. And on NodeRED UI, I get the notification:

The flows on the server have been updated.

And i am asked to review changes.
What I want is to trigger the flow from postman. I can't see anything that allows that in the documentation or perhaps, I am missing something.

That means you have to do a deploy. So do the deploy and try again.

Also,

  1. you need to seperate the 'curl' statement from the flow in your post or it will not import
  2. the flow you provided only has an inject and debug node.
  3. when posting a flow, put it between three back tic's like
    ```
    your flow
    ```

You can edit your first post and see the changes I made for you.

Doesn't the POST to /flow do a deploy?

If so then should @Ihum just refresh the browser rather than deploy?

The 204 no content message, however, suggests that the POST is not correctly formatted.

Also if you want the flow to trigger after deploy, the you would need to set the inject to trigger once after 0.1 seconds

Ahh, I didn't notice that when the curl and flow were all as one before I edited the post. Should have reread it with fresh eyes :roll_eyes:

I have edited my flow in original question to a basic flow that prints the date. And on Postman I am posting to http://localhost:1880/flow. But I am getting the error:

{
    "code": "unexpected_error",
    "message": "missing nodes property"
}

What does that mean? What do you mean by the post not being properly formatted? Also, how can I automate the triggering of a flow from postman?

Thank you. I have edited the flow to include inject, debug and a function. I have also changed it to [POST/flow](https://nodered.org/docs/api/admin/methods/post/flow), but I am getting the error:

{
    "code": "unexpected_error",
    "message": "missing nodes property"
}

Hi @Ihum

You mixing together two different actions.

The requests to /flows or /flow are used to change what flows are currently deployed in the runtime. The payload format used by /flow is different to /flows - which is why you are getting an error. The docs cover the details of the required format.

However, if you already have the flow deployed in the runtime and you want to be able to trigger it using Postman, then you should modify you flow to start with the HTTP In node - so that it can receive an HTTP request from postman.

The cookbook explains how to create HTTP endpoints in Node-RED: Create an HTTP Endpoint : Node-RED

That said, the Inject node does expose an HTTP endpoint to the editor (which is how the button on the Inject node is able to trigger it). If you use the browser developer tools you should be able to see the request the editor makes when you click the button. If you go that route, you need to know that the Inject node's endpoint is secured using adminAuth. So if you have properly secured the editor, then postman won't be able to trigger it.

1 Like

Quick question: If I don't already have the flow deployed in the runtime and I want to be able to deploy and trigger at the same time using Postman, would a HTTP In node handle both the deployment and the triggering?

No, they are completely separate actions.

If you want to trigger a flow whenever it gets deployed, then you should follow the advise @E1cid gave you earlier today - Trigger NodeRed flow from postman - #4 by E1cid

1 Like

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