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

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:

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:

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

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

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

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

The function code

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

return msg;

example flow

[{"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

[{"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.

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.

1 Like

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