cURL in Node red

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
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.....

//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;

Hello Chris,

Are you sure the request method is POST ?
by reading the Docs of the API and the Curl examples i think its GET

Try this example flow :

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

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

Thank You, Works a treat!

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