HTTP Response based on action

Hi All,

I am working on nodered flow where I am receiving data from http post and publishing the data to MQTT. Now if data is successfully published I need to send the success response back otherwise the error response.

Please help if it is doable to send dynamic response. If I am not able to send the publish the data on mqtt, I want the error http response

Add a Complete node linked to the MQTT node. When the message has been sent by the MQTT node you will get a message from the Complete node.

Yes, Complete has output node, how will I link it to httpPost response node .

I don't understand the question. Just wire it up.

I want to send the response back when the data is successfully published on mqtt else error response.

[
    {
        "id": "39ed87cab5b6db6f",
        "type": "tab",
        "label": " Flow",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "de190da7d7f6c752",
        "type": "http in",
        "z": "39ed87cab5b6db6f",
        "name": "",
        "url": "/post",
        "method": "post",
        "upload": false,
        "swaggerDoc": "",
        "x": 180,
        "y": 200,
        "wires": [
            [
                "d11ecb377bfcb5a3",
                "21711cebf6bee721",
                "8bb6de24d9bf8ab4"
            ]
        ]
    },
    {
        "id": "d11ecb377bfcb5a3",
        "type": "function",
        "z": "39ed87cab5b6db6f",
        "name": "process F",
        "func": "\nreturn msg;",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 440,
        "y": 200,
        "wires": [
            [
                "153f26082a9cb0ef",
                "abf47028f6e7cb50"
            ]
        ]
    },
    {
        "id": "21711cebf6bee721",
        "type": "debug",
        "z": "39ed87cab5b6db6f",
        "name": "debug 31",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 440,
        "y": 260,
        "wires": []
    },
    {
        "id": "153f26082a9cb0ef",
        "type": "debug",
        "z": "39ed87cab5b6db6f",
        "name": "debug 32",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 620,
        "y": 260,
        "wires": []
    },
    {
        "id": "abf47028f6e7cb50",
        "type": "mqtt out",
        "z": "39ed87cab5b6db6f",
        "name": "",
        "topic": "",
        "qos": "",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "59ecab9cb8a349eb",
        "x": 630,
        "y": 200,
        "wires": []
    },
    {
        "id": "43142f98d5f780aa",
        "type": "http response",
        "z": "39ed87cab5b6db6f",
        "name": "http response",
        "statusCode": "202",
        "headers": {},
        "x": 660,
        "y": 140,
        "wires": []
    },
    {
        "id": "8bb6de24d9bf8ab4",
        "type": "function",
        "z": "39ed87cab5b6db6f",
        "name": "Http response F",
        "func": "msg.payload = 'success';\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 460,
        "y": 140,
        "wires": [
            [
                "43142f98d5f780aa"
            ]
        ]
    },
    {
        "id": "eaf1cd8c619efe5e",
        "type": "complete",
        "z": "39ed87cab5b6db6f",
        "name": "",
        "scope": [
            "abf47028f6e7cb50"
        ],
        "uncaught": false,
        "x": 270,
        "y": 340,
        "wires": [
            [
                "43142f98d5f780aa"
            ]
        ]
    },
    {
        "id": "59ecab9cb8a349eb",
        "type": "mqtt-broker",
        "name": "mqtt in",
        "broker": "test.mosquitto.org",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "autoUnsubscribe": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "userProps": "",
        "sessionExpiry": ""
    }
]

Your Http response Function node needs to be between the Complete node and the Http response node.
For the failure indication you can use a Trigger node to generate the fail message after a timeout, and reset the Trigger node when you get the Complete message.

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