# Translation of Curl command to HTTP Request

**URL:** <https://discourse.nodered.org/t/translation-of-curl-command-to-http-request/52101>\
**Category:** General\
**Created:** [11 October 2021 18:30 UTC](https://discourse.nodered.org/t/translation-of-curl-command-to-http-request/52101 "2021-10-11T18:30:35Z")\
**Posts on this page:** 1\
**Showing post:** 14

<div class="post-metadata">

**Author:** ![mudwalker](https://avatars.discourse-cdn.com/v4/letter/m/47e85d/32.png) [@mudwalker](https://discourse.nodered.org/u/mudwalker)\
**Post date:** [14 October 2021 18:04 UTC](https://discourse.nodered.org/t/translation-of-curl-command-to-http-request/52101/14 "2021-10-14T18:04:12Z")

</div>

So, managed to get the information I was after from my GL.iNET Router.

Below is a flow that gets the Security Token and then you can GET or POST a URL to the router to obtain the client list and cell information. If it is of use to anyone, well, here it is...

```auto
[
    {
        "id": "0f814aab11ca6a59",
        "type": "inject",
        "z": "362ac6b30a7e45bc",
        "name": "Click me",
        "props": [],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payloadType": "str",
        "x": 140,
        "y": 320,
        "wires": [
            [
                "360590ca88c2741e"
            ]
        ]
    },
    {
        "id": "360590ca88c2741e",
        "type": "function",
        "z": "362ac6b30a7e45bc",
        "name": "Curl token",
        "func": "//original curl: \n//\n//curl http://1.2.3.4/api/router/login -d \"pwd=XXYYZZAABB\"\nmsg.headers = {}; \n\nmsg.method = \"post\";\nmsg.url = \"http://<IP_ADDRESS>/api/router/login\";\nmsg.payload = \"<PASSWORD>\";\nmsg.headers[\"Content-Type\"] = \"application/x-www-form-urlencoded\";\nmsg.cookies = null;\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 370,
        "y": 320,
        "wires": [
            [
                "af82bb868566726f"
            ]
        ]
    },
    {
        "id": "af82bb868566726f",
        "type": "http request",
        "z": "362ac6b30a7e45bc",
        "name": "",
        "method": "use",
        "ret": "txt",
        "paytoqs": "ignore",
        "url": "",
        "tls": "",
        "persist": false,
        "proxy": "",
        "authType": "",
        "credentials": {},
        "x": 550,
        "y": 320,
        "wires": [
            [
                "ea345df5628fa288"
            ]
        ]
    },
    {
        "id": "ea345df5628fa288",
        "type": "function",
        "z": "362ac6b30a7e45bc",
        "name": "global.curlToken",
        "func": "let curlToken = msg.payload;\nlet curlTest = msg.payload.slice(8, 9);\nmsg.test = curlTest;\n\nif (curlTest === \"0\"){\n curlToken = curlToken.slice(19, 51);\n global.set('curlToken', curlToken);\n msg.payload = \"Token OK\";\n} else {\n msg.payload = \"Token Error\";\n}\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 740,
        "y": 320,
        "wires": [
            [
                "c402da04521e4baa"
            ]
        ]
    },
    {
        "id": "7fa01b1b8e12231b",
        "type": "http request",
        "z": "362ac6b30a7e45bc",
        "name": "",
        "method": "use",
        "ret": "txt",
        "paytoqs": "ignore",
        "url": "http://<IP_ADDRESS>/{{{topic}}}",
        "tls": "",
        "persist": false,
        "proxy": "",
        "authType": "",
        "credentials": {
            "user": "",
            "password": ""
        },
        "x": 550,
        "y": 360,
        "wires": [
            [
                "78aa4714ee584214"
            ]
        ]
    },
    {
        "id": "c402da04521e4baa",
        "type": "debug",
        "z": "362ac6b30a7e45bc",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1030,
        "y": 360,
        "wires": []
    },
    {
        "id": "3995f987df0f97bc",
        "type": "inject",
        "z": "362ac6b30a7e45bc",
        "name": "",
        "props": [
            {
                "p": "topic",
                "vt": "str"
            },
            {
                "p": "method",
                "v": "get",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "api/client/list",
        "x": 130,
        "y": 360,
        "wires": [
            [
                "ea6f81fcf7ea3965"
            ]
        ]
    },
    {
        "id": "ea6f81fcf7ea3965",
        "type": "function",
        "z": "362ac6b30a7e45bc",
        "name": "Curl token",
        "func": "msg.headers = {}; \n\nlet curlToken = global.get('curlToken');\n\nmsg.headers[\"Content-Type\"] = 'application/x-www-form-urlencoded';\nmsg.headers[\"Authorization\"] = curlToken;\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 370,
        "y": 360,
        "wires": [
            [
                "7fa01b1b8e12231b"
            ]
        ]
    },
    {
        "id": "c4fb67c8a0f07f31",
        "type": "function",
        "z": "362ac6b30a7e45bc",
        "name": "Curl token",
        "func": "msg.headers = {}; \n\nlet curlToken = global.get('curlToken');\n\nmsg.headers[\"Content-Type\"] = \"application/x-www-form-urlencoded\";\nmsg.headers[\"Authorization\"] = curlToken;\nmsg.payload = \"modem_id=1&bus=1-1.2\";\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 370,
        "y": 400,
        "wires": [
            [
                "1220b9f446f8bb67"
            ]
        ]
    },
    {
        "id": "e09431020a17d4eb",
        "type": "inject",
        "z": "362ac6b30a7e45bc",
        "name": "",
        "props": [
            {
                "p": "topic",
                "vt": "str"
            },
            {
                "p": "method",
                "v": "post",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": true,
        "onceDelay": 0.1,
        "topic": "api/modem/cells/get",
        "x": 160,
        "y": 400,
        "wires": [
            [
                "c4fb67c8a0f07f31"
            ]
        ]
    },
    {
        "id": "78aa4714ee584214",
        "type": "json",
        "z": "362ac6b30a7e45bc",
        "name": "",
        "property": "payload",
        "action": "",
        "pretty": false,
        "x": 710,
        "y": 360,
        "wires": [
            [
                "c402da04521e4baa"
            ]
        ]
    },
    {
        "id": "1220b9f446f8bb67",
        "type": "http request",
        "z": "362ac6b30a7e45bc",
        "name": "",
        "method": "use",
        "ret": "txt",
        "paytoqs": "ignore",
        "url": "http://<IP_ADDRESS>/{{{topic}}}",
        "tls": "",
        "persist": false,
        "proxy": "",
        "authType": "",
        "credentials": {
            "user": "",
            "password": ""
        },
        "x": 550,
        "y": 400,
        "wires": [
            [
                "fcd29dc0e286e61e"
            ]
        ]
    },
    {
        "id": "fcd29dc0e286e61e",
        "type": "json",
        "z": "362ac6b30a7e45bc",
        "name": "",
        "property": "payload",
        "action": "",
        "pretty": false,
        "x": 710,
        "y": 400,
        "wires": [
            [
                "9c0b88b96b6039d3"
            ]
        ]
    },
    {
        "id": "9c0b88b96b6039d3",
        "type": "function",
        "z": "362ac6b30a7e45bc",
        "name": "",
        "func": "let rssi = msg.payload.cells[0].rssi\nmsg.payload = msg.payload.cells[0].rssi;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 860,
        "y": 400,
        "wires": [
            [
                "c402da04521e4baa"
            ]
        ]
    }
]

```

Thank you everyone for your help!

EDIT: Modified Flow with thanks to @UnborN and @E1cid for making it easier and less convoluted!!

---

_[View the full topic](https://discourse.nodered.org/t/translation-of-curl-command-to-http-request/52101)._
