# What is it I don't understand about HTTP request?

**URL:** <https://discourse.nodered.org/t/what-is-it-i-dont-understand-about-http-request/81099>\
**Category:** General\
**Created:** [7 September 2023 08:54 UTC](https://discourse.nodered.org/t/what-is-it-i-dont-understand-about-http-request/81099 "2023-09-07T08:54:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mastiff](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@Mastiff](https://discourse.nodered.org/u/Mastiff)\
**Post date:** [7 September 2023 08:54 UTC](https://discourse.nodered.org/t/what-is-it-i-dont-understand-about-http-request/81099/1 "2023-09-07T08:54:59Z")

</div>

I want to send this, only with a payload as the Playlist number:

`192.168.1.4:16008/MCWS/v1/Playback/PlayPlaylist?Zone=0&ZoneType=Index&Playlist=2&PlaylistType=Path`

Putting that in a HTTP request node works, both on GET and PUT. To get the playlist from the payload I input 2 from an injection node and run it through a function node:

```plaintext
URL1 = "/MCWS/v1/Playback/PlayPlaylist?Zone=0&ZoneType=Index&Playlist=";`
URL2 = "&PlaylistType=Path";
msg.payload = URL1+playlist+URL2;
return msg;

```

And then use this as the URL:  
`http://192.168.1.4:16008`

But that doesn't work at all. I tried setting the append to query string parameters, but that just gave me "invalid payload". But the payload seems to be what I wanted to input:

`"/MCWS/v1/Playback/PlayPlaylist?Zone=0&ZoneType=Index&Playlist=2&PlaylistType=Path"`

Or should there not be quotes there? If I try that, it fails in the function node.

Can somebody please tell me how do I do this in a working way? Here is the full flow:

```auto
[
    {
        "id": "a53bb1e6.a39fc8",
        "type": "inject",
        "z": "b2be241794e49f01",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "2",
        "payloadType": "num",
        "x": 90,
        "y": 80,
        "wires": [
            [
                "67893714e22c6c1a"
            ]
        ]
    },
    {
        "id": "e14bd1af.2df488",
        "type": "http request",
        "z": "b2be241794e49f01",
        "name": "Playlist to JRMC",
        "method": "GET",
        "ret": "txt",
        "paytoqs": "query",
        "url": "http://192.168.1.4:16008",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 420,
        "y": 80,
        "wires": [
            [
                "b3e62b5a.039c7"
            ]
        ]
    },
    {
        "id": "b3e62b5a.039c7",
        "type": "debug",
        "z": "b2be241794e49f01",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 670,
        "y": 80,
        "wires": []
    },
    {
        "id": "67893714e22c6c1a",
        "type": "function",
        "z": "b2be241794e49f01",
        "name": "function 1",
        "func": "playlist = msg.payload;\nURL1 = \"/MCWS/v1/Playback/PlayPlaylist?Zone=0&ZoneType=Index&Playlist=\";\nURL2 = \"&PlaylistType=Path\";\nmsg.payload = URL1+playlist+URL2;\nreturn msg;\n\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 240,
        "y": 80,
        "wires": [
            [
                "e14bd1af.2df488",
                "7288245b173f7193"
            ]
        ]
    },
    {
        "id": "7288245b173f7193",
        "type": "debug",
        "z": "b2be241794e49f01",
        "name": "debug 7",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 360,
        "y": 140,
        "wires": []
    }
]

```

---

<div class="post-metadata">

**Author:** ![Mastiff](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@Mastiff](https://discourse.nodered.org/u/Mastiff)\
**Post date:** [7 September 2023 09:21 UTC](https://discourse.nodered.org/t/what-is-it-i-dont-understand-about-http-request/81099/2 "2023-09-07T09:21:43Z")

</div>

Never mind! I findally found it, using a change node and having the full URL in the function node.

---

<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:** [7 September 2023 09:45 UTC](https://discourse.nodered.org/t/what-is-it-i-dont-understand-about-http-request/81099/3 "2023-09-07T09:45:45Z")

</div>

Just for info  
For GET you can set the url in http request node  
and append msg.payload as the query string.  
The payload would be

```auto
{
  "Zone":0,
  "ZoneType":"Index",
  "Playlist":2
  ,"PlaylistType":"Path"
}

```

The function code

```auto
msg.payload = {
    Zone: 0,
    ZoneType: "Index",
    Playlist: msg.payload,
    PlaylistType: "Path"
}

return msg;

```

example flow

```auto
[{"id":"a53bb1e6.a39fc8","type":"inject","z":"b9860b4b9de8c8da","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"2","payloadType":"num","x":470,"y":120,"wires":[["67893714e22c6c1a"]]},{"id":"67893714e22c6c1a","type":"function","z":"b9860b4b9de8c8da","name":"function 1","func":"\nmsg.payload = {\n Zone: 0,\n ZoneType: \"Index\",\n Playlist: msg.payload,\n PlaylistType: \"Path\"\n}\n\nreturn msg;\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":120,"wires":[["e14bd1af.2df488","7288245b173f7193"]]},{"id":"e14bd1af.2df488","type":"http request","z":"b9860b4b9de8c8da","name":"Playlist to JRMC","method":"GET","ret":"txt","paytoqs":"query","url":"http://192.168.1.4:16008","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"credentials":{"user":"","password":""},"x":800,"y":120,"wires":[["b3e62b5a.039c7"]]},{"id":"7288245b173f7193","type":"debug","z":"b9860b4b9de8c8da","name":"debug 7","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":740,"y":180,"wires":[]},{"id":"b3e62b5a.039c7","type":"debug","z":"b9860b4b9de8c8da","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1050,"y":120,"wires":[]}]

```

For put example

```auto
[{"id":"a53bb1e6.a39fc8","type":"inject","z":"b9860b4b9de8c8da","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"2","payloadType":"num","x":470,"y":120,"wires":[["67893714e22c6c1a"]]},{"id":"67893714e22c6c1a","type":"function","z":"b9860b4b9de8c8da","name":"function 1","func":"let playlist = msg.payload;\nlet URL1 = \"http://192.168.1.4:16008/MCWS/v1/Playback/PlayPlaylist?Zone=0&ZoneType=Index&Playlist=\";\nlet URL2 = \"&PlaylistType=Path\";\nmsg.url = URL1+playlist+URL2;\nreturn msg;\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":120,"wires":[["e14bd1af.2df488","7288245b173f7193"]]},{"id":"e14bd1af.2df488","type":"http request","z":"b9860b4b9de8c8da","name":"Playlist to JRMC","method":"PUT","ret":"txt","paytoqs":"query","url":"http://192.168.1.4:16008","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"credentials":{},"x":800,"y":120,"wires":[["b3e62b5a.039c7"]]},{"id":"7288245b173f7193","type":"debug","z":"b9860b4b9de8c8da","name":"debug 7","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":740,"y":180,"wires":[]},{"id":"b3e62b5a.039c7","type":"debug","z":"b9860b4b9de8c8da","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1050,"y":120,"wires":[]}]

```

PUT function code which will work for get also.

```auto
let playlist = msg.payload;
let URL1 = "http://192.168.1.4:16008/MCWS/v1/Playback/PlayPlaylist?Zone=0&ZoneType=Index&Playlist=";
let URL2 = "&PlaylistType=Path";
msg.url = URL1+playlist+URL2;
return msg;

```

Also you need to declare your variables in the JS code. const, let, var.

---

<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:** [21 September 2023 09:46 UTC](https://discourse.nodered.org/t/what-is-it-i-dont-understand-about-http-request/81099/4 "2023-09-21T09:46:37Z")

</div>

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