# Using flow variable in change node to set HTTP request URL

**URL:** <https://discourse.nodered.org/t/using-flow-variable-in-change-node-to-set-http-request-url/48378>\
**Category:** General\
**Created:** [13 July 2021 18:01 UTC](https://discourse.nodered.org/t/using-flow-variable-in-change-node-to-set-http-request-url/48378 "2021-07-13T18:01:35Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nathan](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nathan/32/44875_2.png) [@Nathan](https://discourse.nodered.org/u/Nathan)\
**Post date:** [13 July 2021 18:01 UTC](https://discourse.nodered.org/t/using-flow-variable-in-change-node-to-set-http-request-url/48378/1 "2021-07-13T18:01:36Z")

</div>

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!

---

<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:** [13 July 2021 18:19 UTC](https://discourse.nodered.org/t/using-flow-variable-in-change-node-to-set-http-request-url/48378/2 "2021-07-13T18:19:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [13 July 2021 18:23 UTC](https://discourse.nodered.org/t/using-flow-variable-in-change-node-to-set-http-request-url/48378/3 "2021-07-13T18:23:16Z")

</div>

> [@Nathan](#):
>
> flow.set(sendURL,"[https://myURL.com/api/](https://myURL.com/api/)");

Is sendURL a variable set to "myVar"?

---

<div class="post-metadata">

**Author:** ![Nathan](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nathan/32/44875_2.png) [@Nathan](https://discourse.nodered.org/u/Nathan)\
**Post date:** [13 July 2021 19:12 UTC](https://discourse.nodered.org/t/using-flow-variable-in-change-node-to-set-http-request-url/48378/4 "2021-07-13T19:12:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Nathan](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nathan/32/44875_2.png) [@Nathan](https://discourse.nodered.org/u/Nathan)\
**Post date:** [13 July 2021 19:14 UTC](https://discourse.nodered.org/t/using-flow-variable-in-change-node-to-set-http-request-url/48378/5 "2021-07-13T19:14:46Z")

</div>

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

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

---

<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:** [13 July 2021 19:18 UTC](https://discourse.nodered.org/t/using-flow-variable-in-change-node-to-set-http-request-url/48378/6 "2021-07-13T19:18:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [13 July 2021 19:21 UTC](https://discourse.nodered.org/t/using-flow-variable-in-change-node-to-set-http-request-url/48378/7 "2021-07-13T19:21:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Nathan](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nathan/32/44875_2.png) [@Nathan](https://discourse.nodered.org/u/Nathan)\
**Post date:** [13 July 2021 19:26 UTC](https://discourse.nodered.org/t/using-flow-variable-in-change-node-to-set-http-request-url/48378/8 "2021-07-13T19:26:39Z")

</div>

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

```auto
[
    {
        "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": []
    }
]

```

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [13 July 2021 19:29 UTC](https://discourse.nodered.org/t/using-flow-variable-in-change-node-to-set-http-request-url/48378/9 "2021-07-13T19:29:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Nathan](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nathan/32/44875_2.png) [@Nathan](https://discourse.nodered.org/u/Nathan)\
**Post date:** [13 July 2021 20:05 UTC](https://discourse.nodered.org/t/using-flow-variable-in-change-node-to-set-http-request-url/48378/10 "2021-07-13T20:05:22Z")

</div>

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!

```auto
[
    {
        "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": []
    }
]

```

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [13 July 2021 20:36 UTC](https://discourse.nodered.org/t/using-flow-variable-in-change-node-to-set-http-request-url/48378/11 "2021-07-13T20:36:02Z")

</div>

> [@Nathan](#):
>
> HTML response also - I had no idea.

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.

---

<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:** [27 July 2021 20:36 UTC](https://discourse.nodered.org/t/using-flow-variable-in-change-node-to-set-http-request-url/48378/12 "2021-07-27T20:36:19Z")

</div>

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