HTTP Request Function Node

Hi everyone,
I would like to know if it were possible to send HTTP requests (i.e. fetch) in function nodes in n8n cloud.
Thank you in advance.
Alberto

Hi @Alberto_Marzetta, welcome to the community!

To make HTTP Requests right inside the Function node when using n8n.cloud, you could use request-promise-native and run a snippet like this:

const request = require('request-promise-native');

const options = {
  uri: 'https://www.themealdb.com/api/json/v1/1/random.php',
  method: 'GET',
  json: true
}

let result = await request(options);

return [{
  json: result.meals[0]
}];

Is this what you had in mind?

Thank you! yes. I had to do some basic authentication which I managed with ‘Request’ module.Thanks again

1 Like

is there a way to do this on self hosted, this code produces “ERROR: Cannot find module ‘request-promise-native’ [Line 170]”

Is this still supposed to be possible? I’m on version 1.20 in n8n cloud starter and I’m getting this error:

The request library got deprecated a long time ago. You can use the built-in replacement (this.helpers.request(options)), which uses axios underneath the hood instead. This wrapper enables you to use the request syntax.

So the above example would look like this:

const options = {
  uri: 'https://www.themealdb.com/api/json/v1/1/random.php',
  method: 'GET',
  json: true
}

let result = await this.helpers.request(options);

return [{
  json: result.meals[0]
}];
2 Likes

@jan Let me know if this is documented somewhere—would be great to know! I am migrating from a self-hosted instance where I installed axios to n8n cloud, so I’m really glad to hear I can still use axios by just changing the syntax!

Yes, it is documented here:

Have fun!

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