Using flow variable in change node to set HTTP request URL

Hi there,

I'm trying to set a URL dynamically by:

  1. Setting a flow variable in a function: flow.set(sendURL,"https://myURL.com/api/");
  2. Accessing the variable in the Change node: Set msg.url to flow.myVar
  3. Passing that to my Request node with an empty URL: [FUNCTION]--->[CHANGE]--->[REQUEST]

...however, I keep getting the error "No url specified"

I have been trying to figure this out for ages, and I feel like I must be missing something obvious. I'd appreciate any input!

You can set msg.url in the previous node (leave the URL field in the HTTP request node empty)

This is documented in the HTTP request node built in help.

Is sendURL a variable set to "myVar"?

This is what I'm doing, but I'm not having much success just now.

Sorry, (and well spotted) this is what I should have said:

  • flow.set("myVar","https://myURL.com/api/");
  • Set msg.url to flow.myVar

Add a debug node (set to show full message) before the HTTP request. You will see if .url is present in the msg

Ok, are the function and change node in the same flow tab?

I'm getting no output from the debug following the change node. Here is the flow:

[
    {
        "id": "3be8a6ad.f8ce72",
        "type": "tab",
        "label": "Wekan => Habitica",
        "disabled": false,
        "info": ""
    },
    {
        "id": "74c92fd1.11f2a8",
        "type": "function",
        "z": "3be8a6ad.f8ce72",
        "name": "Build create task request",
        "func": "const text = msg.payload[\"card\"];\nconst alias = msg.payload[\"cardId\"];\nconst act = msg.payload[\"description\"];\n\nflow.set(\"sendURL\",`https://habitica.com/api/v3/tasks/user`);\n\nif (act == \"act-createCard\") {\n    return {\n        \"text\": text,\n        \"type\": \"todo\",\n        \"alias\": alias,\n        \"priority\": 1.5\n }; \n} else {\n    return console.error(\"Action type incorrect\")\n}",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 550,
        "y": 340,
        "wires": [
            [
                "eb20f0e.813eb1"
            ]
        ]
    },
    {
        "id": "a1b11756.5b4078",
        "type": "http request",
        "z": "3be8a6ad.f8ce72",
        "name": "Send request",
        "method": "POST",
        "ret": "obj",
        "paytoqs": "ignore",
        "url": "",
        "tls": "",
        "persist": false,
        "proxy": "",
        "authType": "basic",
        "x": 910,
        "y": 320,
        "wires": [
            [
                "a90f5c3d.9bc81"
            ]
        ]
    },
    {
        "id": "43f3f104.5d08b",
        "type": "switch",
        "z": "3be8a6ad.f8ce72",
        "name": "Case: Move, Create",
        "property": "payload[\"description\"]",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "act-moveCard",
                "vt": "str"
            },
            {
                "t": "neq",
                "v": "act-moveCard",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 320,
        "y": 320,
        "wires": [
            [
                "6b34ac29.132b54"
            ],
            [
                "74c92fd1.11f2a8"
            ]
        ]
    },
    {
        "id": "6b34ac29.132b54",
        "type": "function",
        "z": "3be8a6ad.f8ce72",
        "name": "Build score task request",
        "func": "const alias = msg.payload[\"cardId\"];\nconst act = msg.payload[\"description\"];\nconst list = msg.payload[\"listId\"];\n\nflow.set(\"sendURL\",`https://habitica.com/api/v3/tasks/${alias}/score/up`);\n\nif (act == \"act-moveCard\") {\n    return {\n        \"alias\": alias,\n }; \n} else {\n    return console.error(\"Action type or list ID incorrect.\")\n}",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 550,
        "y": 300,
        "wires": [
            [
                "eb20f0e.813eb1"
            ]
        ]
    },
    {
        "id": "a90f5c3d.9bc81",
        "type": "debug",
        "z": "3be8a6ad.f8ce72",
        "name": "Log msg.payload",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1070,
        "y": 320,
        "wires": []
    },
    {
        "id": "49944a52.270dc4",
        "type": "debug",
        "z": "3be8a6ad.f8ce72",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 290,
        "y": 360,
        "wires": []
    },
    {
        "id": "806df73d.223c28",
        "type": "http in",
        "z": "3be8a6ad.f8ce72",
        "name": "Receive Wekan POST",
        "url": "/POSTcards",
        "method": "post",
        "upload": false,
        "swaggerDoc": "",
        "x": 100,
        "y": 320,
        "wires": [
            [
                "43f3f104.5d08b",
                "49944a52.270dc4"
            ]
        ]
    },
    {
        "id": "eb20f0e.813eb1",
        "type": "change",
        "z": "3be8a6ad.f8ce72",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "url",
                "pt": "msg",
                "to": "SENDurl",
                "tot": "flow"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 750,
        "y": 320,
        "wires": [
            [
                "a1b11756.5b4078",
                "606a4a71.0544f4"
            ]
        ]
    },
    {
        "id": "606a4a71.0544f4",
        "type": "debug",
        "z": "3be8a6ad.f8ce72",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 900,
        "y": 280,
        "wires": []
    }
]

sendURL is not SENDurl check your change node.

P.S. You need to add a http respnse node with the http in node or the request will hang.

I cannot believe that I missed that typo - thanks so much. Thanks for the info on the HTML response also - I had no idea. The flow below seems to be working!

[
    {
        "id": "3dc2e06f.e9ba8",
        "type": "tab",
        "label": "Wekan => Habitica",
        "disabled": false,
        "info": ""
    },
    {
        "id": "953f8efa.551c18",
        "type": "function",
        "z": "3dc2e06f.e9ba8",
        "name": "Build create task request",
        "func": "const text = msg.payload[\"card\"];\nconst alias = msg.payload[\"cardId\"];\nconst act = msg.payload[\"description\"];\n\nflow.set(\"sendURL\",`https://habitica.com/api/v3/tasks/user`);\n\nif (act == \"act-createCard\") {\n    return {\n        \"text\": text,\n        \"type\": \"todo\",\n        \"alias\": alias,\n        \"priority\": 1.5\n }; \n} else {\n    return console.error(\"Action type incorrect\")\n}",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 550,
        "y": 340,
        "wires": [
            [
                "322920ca.10b14"
            ]
        ]
    },
    {
        "id": "4d198882.5869e8",
        "type": "http request",
        "z": "3dc2e06f.e9ba8",
        "name": "Send request",
        "method": "POST",
        "ret": "obj",
        "paytoqs": "ignore",
        "url": "",
        "tls": "",
        "persist": false,
        "proxy": "",
        "authType": "basic",
        "x": 910,
        "y": 320,
        "wires": [
            [
                "e9c70b6d.5a0c88",
                "f8ee93f8.e10b6"
            ]
        ]
    },
    {
        "id": "59f5c229.32d94c",
        "type": "switch",
        "z": "3dc2e06f.e9ba8",
        "name": "Case: Move, Create",
        "property": "payload[\"description\"]",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "act-moveCard",
                "vt": "str"
            },
            {
                "t": "neq",
                "v": "act-moveCard",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 320,
        "y": 320,
        "wires": [
            [
                "d55fb99.a191548"
            ],
            [
                "953f8efa.551c18"
            ]
        ]
    },
    {
        "id": "d55fb99.a191548",
        "type": "function",
        "z": "3dc2e06f.e9ba8",
        "name": "Build score task request",
        "func": "const alias = msg.payload[\"cardId\"];\nconst act = msg.payload[\"description\"];\nconst list = msg.payload[\"listId\"];\n\nflow.set(\"sendURL\",`https://habitica.com/api/v3/tasks/${alias}/score/up`);\n\nif (act == \"act-moveCard\") {\n    return {\n        \"alias\": alias,\n }; \n} else {\n    return console.error(\"Action type or list ID incorrect.\")\n}",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 550,
        "y": 300,
        "wires": [
            [
                "322920ca.10b14"
            ]
        ]
    },
    {
        "id": "e9c70b6d.5a0c88",
        "type": "debug",
        "z": "3dc2e06f.e9ba8",
        "name": "Log msg.payload",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1110,
        "y": 320,
        "wires": []
    },
    {
        "id": "cb49b789.b5f0a8",
        "type": "debug",
        "z": "3dc2e06f.e9ba8",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 290,
        "y": 360,
        "wires": []
    },
    {
        "id": "1645ddfc.cbcfca",
        "type": "http in",
        "z": "3dc2e06f.e9ba8",
        "name": "Receive Wekan POST",
        "url": "/POSTcards",
        "method": "post",
        "upload": false,
        "swaggerDoc": "",
        "x": 100,
        "y": 320,
        "wires": [
            [
                "59f5c229.32d94c",
                "cb49b789.b5f0a8",
                "cafd75c0.f46778"
            ]
        ]
    },
    {
        "id": "322920ca.10b14",
        "type": "change",
        "z": "3dc2e06f.e9ba8",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "url",
                "pt": "msg",
                "to": "sendURL",
                "tot": "flow"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 750,
        "y": 320,
        "wires": [
            [
                "4d198882.5869e8",
                "915bd03e.9cd54"
            ]
        ]
    },
    {
        "id": "cafd75c0.f46778",
        "type": "http response",
        "z": "3dc2e06f.e9ba8",
        "name": "",
        "statusCode": "",
        "headers": {},
        "x": 270,
        "y": 400,
        "wires": []
    },
    {
        "id": "915bd03e.9cd54",
        "type": "debug",
        "z": "3dc2e06f.e9ba8",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 890,
        "y": 280,
        "wires": []
    },
    {
        "id": "f8ee93f8.e10b6",
        "type": "http response",
        "z": "3dc2e06f.e9ba8",
        "name": "",
        "statusCode": "",
        "headers": {},
        "x": 1070,
        "y": 360,
        "wires": []
    }
]

Every node has a help info, it's the book symbol at the top of the debug panel. Often there is very helpful info there.

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