HTTP requests and functions

Hello!

I use the following code inside a function:

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

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!

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://https://opengraph.io/api/1.1/site/http%3A%2F%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

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.

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