# Doing http request with every msg.payload.id

**URL:** <https://discourse.nodered.org/t/doing-http-request-with-every-msg-payload-id/4506>\
**Category:** General\
**Created:** [2 November 2018 14:28 UTC](https://discourse.nodered.org/t/doing-http-request-with-every-msg-payload-id/4506 "2018-11-02T14:28:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![licccboeh](https://avatars.discourse-cdn.com/v4/letter/l/c2a13f/32.png) [@licccboeh](https://discourse.nodered.org/u/licccboeh)\
**Post date:** [2 November 2018 14:28 UTC](https://discourse.nodered.org/t/doing-http-request-with-every-msg-payload-id/4506/1 "2018-11-02T14:28:02Z")

</div>

Hello!

I'm new to using Node-Red and solving a problem step by step.

I'm trying to do Rest API query for each ID that i've got in "msg.payload.id". For example [https://website.com/api/](https://website.com/api/)\<msg.payload.id\>.

At the moment i'm getting all ID-s, which are available with http.request node, then I'm using "change" node to move payload.items to payload. Then I'm using split to break up array. And finally sort to select only those I'm interested in.

And now i'm stuck.

What is the best way to take every objects' unique ID and running http query with them? Setting a global variable won't help. If I could use http request in function node, then a simple for cycle would help.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [2 November 2018 14:46 UTC](https://discourse.nodered.org/t/doing-http-request-with-every-msg-payload-id/4506/2 "2018-11-02T14:46:33Z")

</div>

The HTTP Request node can be used to make the request. It lets you specify the url to request by passing in `msg.url`.

Does that help?

---

<div class="post-metadata">

**Author:** ![licccboeh](https://avatars.discourse-cdn.com/v4/letter/l/c2a13f/32.png) [@licccboeh](https://discourse.nodered.org/u/licccboeh)\
**Post date:** [2 November 2018 14:52 UTC](https://discourse.nodered.org/t/doing-http-request-with-every-msg-payload-id/4506/3 "2018-11-02T14:52:38Z")

</div>

So if i would make a function node, where I set url + id to msq.url to make query with http.request.node, will it run with every object automatically and I don't have to worry about using for cycles?

at the moment my last node, which is sort, outputs 30 msg.payload objects, which all have unique id's

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [2 November 2018 16:01 UTC](https://discourse.nodered.org/t/doing-http-request-with-every-msg-payload-id/4506/4 "2018-11-02T16:01:44Z")

</div>

> [@licccboeh](#):
>
> I don't have to worry about using for cycles?

If you have an array in msg.payload then you can feed that through a Split node and you will get a sequence of messages, one for each element of the array. You can then feed those into the http node.

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [3 November 2018 02:14 UTC](https://discourse.nodered.org/t/doing-http-request-with-every-msg-payload-id/4506/5 "2018-11-03T02:14:59Z")

</div>

If you just want to substitute fields from the incoming `msg` object into the url, you can use "mustache" syntax -- as mentioned in the `http request` node's info panel:

> When configured within the node, the URL property can contain [mustache-style](http://mustache.github.io/mustache.5.html) tags. These allow the url to be constructed using values of the incoming message. For example, if the url is set to `example.com/{{{topic}}}` , it will have the value of `msg.topic` automatically inserted. Using {{{...}}} prevents mustache from escaping characters like / & etc.

I'm doing this same thing right now... read in records from a csv file, split into individual msg objects, and set my url to use syntax like `https://{{{myserver}}}/api/users/{{payload.username}}`

The nice thing with this is that I can dynamically build any url string, even setting the target hostname, from the data i send in the msg. Note that I use the double braces on the incoming username so it gets url encoded properly, which I don't need with the server information...

---

<div class="post-metadata">

**Author:** ![licccboeh](https://avatars.discourse-cdn.com/v4/letter/l/c2a13f/32.png) [@licccboeh](https://discourse.nodered.org/u/licccboeh)\
**Post date:** [5 November 2018 08:51 UTC](https://discourse.nodered.org/t/doing-http-request-with-every-msg-payload-id/4506/6 "2018-11-05T08:51:46Z")

</div>

Thanks alot everybody for helping me to solve the problem!

Using mustache-style tags solved linking ID with URL using http request node. Colin answer made it clear I can just use split node and then using http request after rather than the need to use function node between.
