HTTP requests and functions


I use the following code inside a function:

var url = msg.payload.url;
var urlEncoded = encodeURIComponent(url);
var requestUrl = '' + 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

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

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.

Hi @knolleary! Thanks! However:

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

Error: getaddrinfo ENOTFOUND https : http://

Changing to msg.url shows:

Warning: msg properties can no longer override set node properties. See

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.