# cURL in Node red

**URL:** https://discourse.nodered.org/t/curl-in-node-red/58628
**Category:** General
**Created:** [18 February 2022 23:27 UTC](https://discourse.nodered.org/t/curl-in-node-red/58628 "2022-02-18T23:27:07Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Chaos](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chaos/32/107061_2.png) [@Chaos](https://discourse.nodered.org/u/Chaos)
#### Post date: [18 February 2022 23:27 UTC](https://discourse.nodered.org/t/curl-in-node-red/58628/1 "2022-02-18T23:27:07Z")

</div>

I have this simple cUrl command that i want to implement into node red but can't get to work. i have tried a couple of examples, but just cant get the data required. the command works ok in terminal to retrieve location data of an ip address:  
curl [ipinfo.io/8.8.8.8?token=1234567890](http://ipinfo.io/8.8.8.8?token=1234567890)  
i am wanting to be able to put the ip address in as msg.payload. I create a JSON object, and send it into a http post node, but don't get the message header thing ???  
latest non working function.....

```auto
//original curl format:  
//
//curl ipinfo.io/8.8.8.8?token=1 **********

/*returns
{
  "ip": "8.8.8.8",
  "hostname": "dns.google",
  "anycast": true,http://192.168.0.20:1880/#func-tab-finalize
  "city": "Mountain View",
  "region": "California",
  "country": "US",
  "loc": "37.4056,-122.0775",
  "org": "AS15169 Google LLC",
  "postal": "94043",
  "timezone": "America/Los_Angeles"
}
*/

msg.method = "post";
msg.url = "http://ipinfo.io/";
msg.payload = "8.8.8.8";
msg.token = "my-token-here";
msg.headers = null;
msg.cookies = null;

return msg;

```

---

<div class="post-metadata">

### Author: ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)
#### Post date: [18 February 2022 23:49 UTC](https://discourse.nodered.org/t/curl-in-node-red/58628/2 "2022-02-18T23:49:59Z")

</div>

Hello Chris,

Are you sure the request method is POST ?  
by reading the [Docs](https://ipinfo.io/developers#ip-address-parameter) of the API and the Curl examples i think its GET

**Try this example flow :**

```auto
[{"id":"8a486b8a2e60185e","type":"function","z":"54efb553244c241f","name":"prepare request","func":"let ip = \"8.8.8.8\"\nlet token = \"my-token-here\"\n\nmsg.url = `http://ipinfo.io/${ip}?token=${token}`\nmsg.method = \"GET\"\nmsg.headers = { \"Accept\": \"application/json\" }\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":520,"y":1200,"wires":[["d7cbcea04e8d4b03"]]},{"id":"b912d6d1d162a261","type":"inject","z":"54efb553244c241f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":320,"y":1200,"wires":[["8a486b8a2e60185e"]]},{"id":"e70e5832f7612077","type":"debug","z":"54efb553244c241f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":890,"y":1200,"wires":[]},{"id":"d7cbcea04e8d4b03","type":"http request","z":"54efb553244c241f","name":"","method":"use","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":710,"y":1200,"wires":[["e70e5832f7612077"]]}]

```

---

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [19 February 2022 06:53 UTC](https://discourse.nodered.org/t/curl-in-node-red/58628/3 "2022-02-19T06:53:31Z")

</div>

Just in case it helps - here is a link to a recent thread about converting curl to http request - might hel - might not

> [@Translation of Curl command to HTTP Request](https://discourse.nodered.org/t/translation-of-curl-command-to-http-request/52101):
>
> Hi, Looking for some help, Trying to talk to a GL.iNet Router and having problems. I am just not grasping this - it should be so simple!! I have been trying to convert a Curl command (which does work) to an HTTP Request for the last few days and am rapidly losing my fingerprints! POST gets me a 200 response, but the password is not being read (among other diagnostics) "{"code":-1,"msg":"Token is null"}" curl \<IPADDRESS\>/api/router/login -d "pwd=XXYYZZAABB" Would really be grateful for some…

---

<div class="post-metadata">

### Author: ![Chaos](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chaos/32/107061_2.png) [@Chaos](https://discourse.nodered.org/u/Chaos)
#### Post date: [19 February 2022 08:12 UTC](https://discourse.nodered.org/t/curl-in-node-red/58628/4 "2022-02-19T08:12:50Z")

</div>

Thank You, Works a treat!

---

<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: [20 April 2022 08:13 UTC](https://discourse.nodered.org/t/curl-in-node-red/58628/5 "2022-04-20T08:13:42Z")

</div>

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