# Retrieve HTTP POST cUrl data on node-red

**URL:** <https://discourse.nodered.org/t/retrieve-http-post-curl-data-on-node-red/64266>\
**Category:** General\
**Tags:** http-request\
**Created:** [23 June 2022 07:20 UTC](https://discourse.nodered.org/t/retrieve-http-post-curl-data-on-node-red/64266 "2022-06-23T07:20:21Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![samirovic](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@samirovic](https://discourse.nodered.org/u/samirovic)\
**Post date:** [23 June 2022 07:20 UTC](https://discourse.nodered.org/t/retrieve-http-post-curl-data-on-node-red/64266/1 "2022-06-23T07:20:21Z")

</div>

Hello,  
I am new to node-red. I would like to know how I can recover HTTP Post Curl data on node red. I leave you the example:  
`curl -H "Content-Type:application/x-www-form-urlencoded" -c ./cookie.txt -X POST --data '{"id":"1","execute":1,"core" :"user","function":"login","values":[{"username":"admin","password":"sI/7ewBCeWunDs6JXXtSHg=="}]}' http://192.168.45.106/ cgi`

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [23 June 2022 07:34 UTC](https://discourse.nodered.org/t/retrieve-http-post-curl-data-on-node-red/64266/2 "2022-06-23T07:34:03Z")

</div>

Hi and Welcome to the forums!

Not sure I follow completely.  
are you using curl to send data to Node RED?

or are you wishing to make a request from within Node RED to a resource and capture the response?

---

<div class="post-metadata">

**Author:** ![samirovic](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@samirovic](https://discourse.nodered.org/u/samirovic)\
**Post date:** [23 June 2022 07:48 UTC](https://discourse.nodered.org/t/retrieve-http-post-curl-data-on-node-red/64266/3 "2022-06-23T07:48:38Z")

</div>

the goal is to retrieve data from a router using this Curl line.  
yes I would like to make a request from Node RED to a resource and capture the response.

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [23 June 2022 07:50 UTC](https://discourse.nodered.org/t/retrieve-http-post-curl-data-on-node-red/64266/4 "2022-06-23T07:50:48Z")

</div>

This should get you going (import it)

```auto
[{"id":"be09724a5e928145","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"158ae5b9d074d506","type":"http request","z":"be09724a5e928145","name":"","method":"POST","ret":"txt","paytoqs":"ignore","url":"http://192.168.45.106/cgi","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"credentials":{},"x":570,"y":340,"wires":[["95d5415bcb2a2157"]]},{"id":"95d5415bcb2a2157","type":"debug","z":"be09724a5e928145","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":750,"y":420,"wires":[]},{"id":"0a039e922c5778a9","type":"function","z":"be09724a5e928145","name":"Format Request","func":"const Message = {\n \"payload\": {\n \"id\": \"1\",\n \"execute\": 1,\n \"core\": \"user\",\n \"function\": \"login\",\n \"values\": [{\n \"username\": \"admin\",\n \"password\": \"sI/7ewBCeWunDs6JXXtSHg==\"\n }]\n },\n \"headers\": {\n \"Content-Type\": \"application/x-www-form-urlencoded\"\n }\n}\n\nreturn Message","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":420,"y":280,"wires":[["158ae5b9d074d506"]]},{"id":"6607ecc1878dccb0","type":"inject","z":"be09724a5e928145","name":"Trigger","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":250,"y":220,"wires":[["0a039e922c5778a9"]]}]

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/2/92c413fc694121742b6b9b7242eecf4eebbb00e3.png)

EDIT:  
Depending on the expected response content type.  
you can change the return type on the request node.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/a/daf326922d2d5da6d40d0cf489dce3d0aa1ff9f7.png)

you might need to tweak the `payload` especially `values` - i.e single quote the object.

```auto
const Message = {
    "payload": {
        "id": "1",
        "execute": 1,
        "core": "user",
        "function": "login",
        "values": '[{"username": "admin", "password": "sI/7ewBCeWunDs6JXXtSHg==" }]'
    },
    "headers": {
        "Content-Type": "application/x-www-form-urlencoded"
    }
}

return Message

```

---

<div class="post-metadata">

**Author:** ![samirovic](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@samirovic](https://discourse.nodered.org/u/samirovic)\
**Post date:** [23 June 2022 08:44 UTC](https://discourse.nodered.org/t/retrieve-http-post-curl-data-on-node-red/64266/5 "2022-06-23T08:44:57Z")

</div>

I did the same thing as you, but I got an error message.

![node-red1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/d/0d9b1d146c5fc17d5511c1e149c54f3cfc042926.png)

 ![node-red2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/b/3bb0d1491f5b78515ed86e2f7c8d47c84c86a4b8.png)

 ![node-red3](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/7/b7cb3b0c42b5f6f0d36877c1412a1f39208c4cea.png)

I have a question what is it for, do I have to add it somewhere

 ![node-red.](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/5/25392a12023ab628a90389d74758c0e36b07ed63.png)

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [23 June 2022 08:49 UTC](https://discourse.nodered.org/t/retrieve-http-post-curl-data-on-node-red/64266/6 "2022-06-23T08:49:10Z")

</div>

> I have a question what is it for, do I have to add it somewhere

Its a flow that should achieve what you need

Copy this text (I have corrected the payload)

```auto
[{"id":"be09724a5e928145","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"158ae5b9d074d506","type":"http request","z":"be09724a5e928145","name":"","method":"POST","ret":"txt","paytoqs":"ignore","url":"http://localhost:1880/cgi","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":570,"y":340,"wires":[["95d5415bcb2a2157"]]},{"id":"95d5415bcb2a2157","type":"debug","z":"be09724a5e928145","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":730,"y":420,"wires":[]},{"id":"0a039e922c5778a9","type":"function","z":"be09724a5e928145","name":"Format Request","func":"const Message = {\n \"payload\": {\n \"id\": \"1\",\n \"execute\": 1,\n \"core\": \"user\",\n \"function\": \"login\",\n \"values\": '[{\"username\": \"admin\", \"password\": \"sI/7ewBCeWunDs6JXXtSHg==\" }]'\n },\n \"headers\": {\n \"Content-Type\": \"application/x-www-form-urlencoded\"\n }\n}\n\nreturn Message","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":420,"y":280,"wires":[["158ae5b9d074d506"]]},{"id":"6607ecc1878dccb0","type":"inject","z":"be09724a5e928145","name":"Trigger","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":250,"y":220,"wires":[["0a039e922c5778a9"]]}]

```

and then import it.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/6/46fdfcf7452293aeaf661d4e1ae72c0fb36e794d.png)

of course, editing anything necessary (like the URL in the request node)

---

<div class="post-metadata">

**Author:** ![samirovic](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@samirovic](https://discourse.nodered.org/u/samirovic)\
**Post date:** [23 June 2022 09:04 UTC](https://discourse.nodered.org/t/retrieve-http-post-curl-data-on-node-red/64266/7 "2022-06-23T09:04:03Z")

</div>

When I change the ip address I get this error message :  
 ![node-red4](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/5/05c0d16b18dbe87453f2885aea66302911b3525c.png)

To explain things to you the objective is to read the cellular data usage as below.  
Access Cookie：

**curl -H "Content-Type:application/x-www-form-urlencoded" -c ./cookie.txt -X POST --data '{"id":"1","execute":1,"core":"user","function":"login","values":[{"username":"admin","password":"sI/7ewBCeWunDs6JXXtSHg=="}]}' [http://192.168.45.106/cgi](http://192.168.45.106/cgi%C2%A0)**

Inquiry data usage:

**curl -H "Content-Type:application/x-www-form-urlencoded" -b ./cookie.txt -X POST --data '{"id":7,"execute":1,"core":"yruo\_status","function":"get","values":[{"base":"yruo\_celluar"}]}' [http://192.168.45.106/cgi](http://192.168.45.106/cgi%C2%A0)**

Then you can get like below:

 ![7shJeLkHq2--APGErLjdLQagPMg46Pvj7g](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/1/818a092e34d03defe656165677d776c84d0728be.png)

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [23 June 2022 09:08 UTC](https://discourse.nodered.org/t/retrieve-http-post-curl-data-on-node-red/64266/8 "2022-06-23T09:08:11Z")

</div>

Ok - the response might be of an old HTTP version, and may not be supported by NodeJS.

give me a minute.  
we can try executing curl from Node RED.

---

<div class="post-metadata">

**Author:** ![samirovic](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@samirovic](https://discourse.nodered.org/u/samirovic)\
**Post date:** [23 June 2022 09:10 UTC](https://discourse.nodered.org/t/retrieve-http-post-curl-data-on-node-red/64266/9 "2022-06-23T09:10:38Z")

</div>

Okay take your time.

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [23 June 2022 09:28 UTC](https://discourse.nodered.org/t/retrieve-http-post-curl-data-on-node-red/64266/10 "2022-06-23T09:28:52Z")

</div>

try this - its using the exec node to call curl

```auto
[{"id":"be09724a5e928145","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"8b03ba66b044c3d7","type":"exec","z":"be09724a5e928145","command":"/usr/bin/curl ","addpay":"payload","append":"","useSpawn":"false","timer":"2","winHide":false,"oldrc":false,"name":"Curl","x":570,"y":320,"wires":[["570c1643b0bde49f"],[],[]]},{"id":"f454c6183b821c86","type":"inject","z":"be09724a5e928145","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":180,"y":240,"wires":[["8fa43d6b7c972b98"]]},{"id":"8fa43d6b7c972b98","type":"function","z":"be09724a5e928145","name":"Pass Args","func":"msg.payload = '-H \"Content-Type:application/x-www-form-urlencoded\" -c ./cookie.txt -X POST --data \\'{\"id\":\"1\",\"execute\":1,\"core\" :\"user\",\"function\":\"login\",\"values\":[{\"username\":\"admin\",\"password\":\"sI/7ewBCeWunDs6JXXtSHg==\"}]}\\' http://192.168.45.106/cgi'\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":360,"y":320,"wires":[["8b03ba66b044c3d7"]]},{"id":"570c1643b0bde49f","type":"debug","z":"be09724a5e928145","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":530,"y":180,"wires":[]}]

```

I think the error you was getting, was due to some response format not being accepted by the NodeJS runtime - i.e an old HTTP Version or something like that.

---

<div class="post-metadata">

**Author:** ![samirovic](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@samirovic](https://discourse.nodered.org/u/samirovic)\
**Post date:** [23 June 2022 09:48 UTC](https://discourse.nodered.org/t/retrieve-http-post-curl-data-on-node-red/64266/11 "2022-06-23T09:48:08Z")

</div>

Great, it's working fine. thank you for your help.

---

<div class="post-metadata">

**Author:** ![samirovic](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@samirovic](https://discourse.nodered.org/u/samirovic)\
**Post date:** [23 June 2022 11:47 UTC](https://discourse.nodered.org/t/retrieve-http-post-curl-data-on-node-red/64266/12 "2022-06-23T11:47:15Z")

</div>

I have a small question, how can I do to keep just the value that is in yellow

![node-red4](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/c/6c1ef1ed204902122876e548a6aa2cd63c8232d1.png)

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [23 June 2022 12:11 UTC](https://discourse.nodered.org/t/retrieve-http-post-curl-data-on-node-red/64266/13 "2022-06-23T12:11:30Z")

</div>

Can you paste the result as a JSON string here?  
its really difficult to engineer from a screenshot

remove/change anything that is of sensitive data of course

---

<div class="post-metadata">

**Author:** ![samirovic](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@samirovic](https://discourse.nodered.org/u/samirovic)\
**Post date:** [23 June 2022 12:17 UTC](https://discourse.nodered.org/t/retrieve-http-post-curl-data-on-node-red/64266/14 "2022-06-23T12:17:01Z")

</div>

I want to get the value in bold

{"id":7,"model":"UR32","pn":"L04EU2211110FR0000000000","oem":"0000","rtver":"32.3.0.5","status":0,"result":[{"get":[{"type":"yruo\_cell\_status","index":0,"value":{"modem":{"modem\_status":"No SIM Card","model":"EC25","version":"EC25EUXGAR08A03M1G","cur\_sim":"SIM1","signal":"0asu (-113dBm)","register":"Not registered","imsi":"","iccid":"","net\_provider":"","net\_type":"","plmnid":"","lac":"0","cellid":"0","imei":"862506049149928"},"network":{"status":"Disconnected","ip":"0.0.0.0","netmask":"0.0.0.0","gate":"0.0.0.0","dns":"0.0.0.0","time":"0 days, 00:00:00","speed":"RX: 1.13Kb, TX: 0b","ipv6":"::","gatev6":"::","dnsv6":"::"},"statistics":{"sim1":"RX: 0.0 MiB TX: 0.0 MiB ALL: 0.0 MiB","sim2":"RX: 180.4 MiB TX: 146.6 MiB ALL: **327.1** MiB"}}}]}]}

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [23 June 2022 12:17 UTC](https://discourse.nodered.org/t/retrieve-http-post-curl-data-on-node-red/64266/15 "2022-06-23T12:17:15Z")

</div>

give me a minute

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [23 June 2022 12:22 UTC](https://discourse.nodered.org/t/retrieve-http-post-curl-data-on-node-red/64266/16 "2022-06-23T12:22:53Z")

</div>

Replace the `inject`, with the output of the `exec` node.  
I used `inject` to emulate the output of the `exec`

if you debug the output of the `json` node you will see how it is achieved.

```auto
[{"id":"be09724a5e928145","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"570c1643b0bde49f","type":"debug","z":"be09724a5e928145","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":710,"y":160,"wires":[]},{"id":"d387737a4805a52b","type":"inject","z":"be09724a5e928145","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"id\":7,\"model\":\"UR32\",\"pn\":\"L04EU2211110FR0000000000\",\"oem\":\"0000\",\"rtver\":\"32.3.0.5\",\"status\":0,\"result\":[{\"get\":[{\"type\":\"yruo_cell_status\",\"index\":0,\"value\":{\"modem\":{\"modem_status\":\"No SIM Card\",\"model\":\"EC25\",\"version\":\"EC25EUXGAR08A03M1G\",\"cur_sim\":\"SIM1\",\"signal\":\"0asu (-113dBm)\",\"register\":\"Not registered\",\"imsi\":\"\",\"iccid\":\"\",\"net_provider\":\"\",\"net_type\":\"\",\"plmnid\":\"\",\"lac\":\"0\",\"cellid\":\"0\",\"imei\":\"862506049149928\"},\"network\":{\"status\":\"Disconnected\",\"ip\":\"0.0.0.0\",\"netmask\":\"0.0.0.0\",\"gate\":\"0.0.0.0\",\"dns\":\"0.0.0.0\",\"time\":\"0 days, 00:00:00\",\"speed\":\"RX: 1.13Kb, TX: 0b\",\"ipv6\":\"::\",\"gatev6\":\"::\",\"dnsv6\":\"::\"},\"statistics\":{\"sim1\":\"RX: 0.0 MiB TX: 0.0 MiB ALL: 0.0 MiB\",\"sim2\":\"RX: 180.4 MiB TX: 146.6 MiB ALL: 327.1 MiB\"}}}]}]}","payloadType":"str","x":130,"y":160,"wires":[["1a0f1b39ed29c446"]]},{"id":"1a0f1b39ed29c446","type":"json","z":"be09724a5e928145","name":"","property":"payload","action":"","pretty":false,"x":310,"y":160,"wires":[["7d91ea0434ed7c7a"]]},{"id":"7d91ea0434ed7c7a","type":"function","z":"be09724a5e928145","name":"","func":"const Value = msg.payload.result[0].get[0].value.statistics.sim2\nmsg.payload = Value.split(\":\")[3].trim()\n\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":520,"y":160,"wires":[["570c1643b0bde49f"]]}]

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/1/91278282dd4f43bc1a27cadf4b25fe1d7bae76b3.png)

There are other ways, but this is good NR learning for you 😉  
thankfully the output was a JSON string - so we could use a built in node to parse it

---

<div class="post-metadata">

**Author:** ![samirovic](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@samirovic](https://discourse.nodered.org/u/samirovic)\
**Post date:** [23 June 2022 13:31 UTC](https://discourse.nodered.org/t/retrieve-http-post-curl-data-on-node-red/64266/17 "2022-06-23T13:31:49Z")

</div>

I replaced the inject, with the output of the exec node it works perfectly  
I thank you infinitely 👍 👍

---

<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:** [7 July 2022 13:32 UTC](https://discourse.nodered.org/t/retrieve-http-post-curl-data-on-node-red/64266/18 "2022-07-07T13:32:35Z")

</div>

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