# HTTP requests and functions

**URL:** <https://discourse.nodered.org/t/http-requests-and-functions/33494>\
**Category:** General\
**Created:** [29 September 2020 08:45 UTC](https://discourse.nodered.org/t/http-requests-and-functions/33494 "2020-09-29T08:45:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![chloroquine](https://avatars.discourse-cdn.com/v4/letter/c/dec6dc/32.png) [@chloroquine](https://discourse.nodered.org/u/chloroquine)\
**Post date:** [29 September 2020 08:45 UTC](https://discourse.nodered.org/t/http-requests-and-functions/33494/1 "2020-09-29T08:45:36Z")

</div>

Hello!

I use the following code inside a function:

```auto
var url = msg.payload.url;
var urlEncoded = encodeURIComponent(url);
var requestUrl = 'https://opengraph.io/api/1.1/site/' + urlEncoded + '?accept_lang=auto&cache_ok=false&use_proxy=true&app_id=XXX';
msg.payload.requestUrl = requestUrl;
return msg;

```

before calling an api using a http request with

```auto
Method: Get
URL: {{msg.payload.requestUrl}}
Payload: ignore

```

However, I am always presented with an error:

> "No url specified"

although the log shows a requestUrl `https://opengraph.io/api/1.1/site/http%3A%2F%2Fgoogle.com?accept_lang=auto&cache_ok=false&use_proxy=true&app_id=XXX` which works in the terminal. So I guess the error does not appear whilst generating the URL but rather when calling it; any idea how to fix this?

Any help much appreciated!

---

<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:** [29 September 2020 08:48 UTC](https://discourse.nodered.org/t/http-requests-and-functions/33494/2 "2020-09-29T08:48:30Z")

</div>

Hi @chloroquine

I suspect you need to use `{{payload.requestUrl}}` in the URL field - without the `msg` prefix.

However you could also leave that field blank and set the `msg.url` property rather than `msg.payload.requestUrl` - as the node will use that if provided.

---

<div class="post-metadata">

**Author:** ![chloroquine](https://avatars.discourse-cdn.com/v4/letter/c/dec6dc/32.png) [@chloroquine](https://discourse.nodered.org/u/chloroquine)\
**Post date:** [29 September 2020 08:50 UTC](https://discourse.nodered.org/t/http-requests-and-functions/33494/3 "2020-09-29T08:50:39Z")

</div>

> [@knolleary](#):
>
> payload.requestUrl

Hi @knolleary! Thanks! However:

Using `{{payload.requestUrl}}` leads to the following:

> Error: getaddrinfo ENOTFOUND https : [http://https](http://https)://opengraph.io/api/1.1/site/http%3A%2F%[2Fgoogle.com?accept\_lang](http://2Fgoogle.com?accept_lang)=auto&cache\_ok=false&use\_proxy=true&app\_id=XXX

Changing to msg.url shows:

> Warning: msg properties can no longer override set node properties. See bit.ly/nr-override-msg-props

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [29 September 2020 08:53 UTC](https://discourse.nodered.org/t/http-requests-and-functions/33494/4 "2020-09-29T08:53:26Z")

</div>

As Nick says, use the msg.url property instead. Then you can put everything in the function node and leave the url blank in the request.

---

<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:** [28 November 2020 08:53 UTC](https://discourse.nodered.org/t/http-requests-and-functions/33494/5 "2020-11-28T08:53:30Z")

</div>

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