With over 150 nodes, n8n saves countless hours by automating repetitive tasks. But what happens when n8n doesn’t have a node for a tool you love?
Enter the HTTP Request node. This node can send any type of HTTP request, making it useful to talk to any RESTful API. This makes the HTTP Request node one of the most versatile and powerful nodes in the n8n ecosystem.
In this article, we are going to explore three examples to showcase how the HTTP Request node can be used in your workflow to automate tasks:
Setting up n8n
This tutorial assumes that you already have n8n set up and running. In case you don’t, you can install with npm:
npm install n8n -g
After the installation, start n8n by typing:
n8n start --tunnel
Note: This is only meant for local development and testing. For information on how to deploy n8n in a production environment, please refer to the n8n setup guide.
For this example, I’ll be retrieving the homepage of Hackernoon and extracting the names and URLs of all the articles.
You can also follow along this example by copying the workflow from n8n.io and making appropriate changes at each step.
Add a new HTTP Request node by clicking the + button at the top right of the Editor UI and selecting the HTTP Request node from the list. Then, select the GET option for Request Method.
Enter
as the URL. Set the Response Format to ‘String’ and then click on Execute Node. You’ll see that the source code of the page has been retrieved by n8n.https://hackernoon.com
Next, add a HTML Extract node and connect it to the HTTP Request node. Select ‘JSON’ for Source Data. Set a Key of your choice — this is the name under which the extracted titles will be saved. Next, enter the CSS class name of the element you want to extract data from. In our case, all the blog titles are
h2
elements, so I put h2
as the CSS Selector. Select ‘HTML’ as the Return Value and set Return Array to ‘True’ (make the slider green).Add another HTML Extract node and connect it to the previous HTML Extract node. Select ‘JSON’ for Source Data. Click Add Value under the ‘Extraction Values’ section and add a value with the Key as
title
, CSS Selector as a
, and the Return Value as ‘Text’. Similarly, add another entry in the Extraction Values section, with the Key as url
, CSS Selector as a
, the Return Value as ‘Attribute’, and Attribute as href
.Now click on Execute Node and you will see the titles and URLs of each blog post.
Here’s a GIF of me following the steps above.
For this example, we will be creating a cloud instance on DigitalOcean, a leading web hosting provider.
You can also follow along this example by copying the workflow from n8n.io and making appropriate changes at each step.
DigitalOcean’s API allows the creation of new droplets via a POST Request, which we will be using, in conjunction with the HTTP Request node.
First, sign up for an account on DigitalOcean’s website. Then, once you’re logged in, generate and copy your ‘Personal access token’ from the API section. This is what we will use to authenticate against the API in n8n.
Now, head over to n8n and create a new workflow. Next, add a HTTP Request node and select POST as the Request Method. Type in
as the URL. Set the Response Format to ‘JSON’. Add a Body Content Type option and select ‘JSON’.https://api.digitalocean.com/v2/droplets
It’s time to add Body Parameters to the request. These parameters tell DigitalOcean what kind of a droplet to create. I chose to add four basic parameters, but you can add several different parameters (Refer: DigitalOcean docs).
You can add a parameter by clicking the Add Parameter button and adding in the names and values as shown below.
┌────────┬──────────────────┐
│ Name │ Value │
├────────┼──────────────────┤
│ name │ n8n-rocks │
│ region │ blr1 │
│ size │ s-1vcpu-1gb │
│ image │ ubuntu-20-04-x64 │
└────────┴──────────────────┘
Next, we will add the authorization header. Scroll down to the Headers section and add a new Header with the name ‘Authorization’ and the value as
Bearer {your_DO_token}
.Now click ‘Execute Node’ and head over to your DigitalOcean console. You should see that a new droplet with the name
n8n-rocks
has been created.Here’s a GIF of me following the steps above.
For this example, we will converting speech to text from audio files using Wit.ai. We will send audio files and receive the detected text via the HTTP API.
You can also follow along this example by copying the workflow from n8n.io and this audio sample, making appropriate changes at each step.
First, sign up for an account on Wit.ai. Create a New App. Then, head over to Settings and copy your ‘Server Access Token’. We will use this later when setting up the node credentials in n8n.
Now, head over to n8n and create a new workflow. Add a Read Binary File node. Then, enter the File Path to your audio sample and choose a Property Name.
Then, add a new HTTP Request node and connect both nodes. Select ‘POST’ as the Request Method. Type in
as the URL. Then, select ‘JSON’ as the Response Format. Select JSON/RAW Parameters as ‘True’ (make the slider green). Next, add a Body Content Type option, selecting ‘RAW/Custom’. https://api.wit.ai/speech?v=20200513
Select Send Binary Data as ‘True’ and enter the property name that you picked earlier. In the Headers section, enter the following, replacing
{your_token_goes_here}
with the ‘Server Access Token’ you copied from Wit.ai.{{JSON.parse('{"Authorization":"Bearer {your_token_goes_here}", "Content-Type":"audio/wav"}')}}
Now click ‘Execute Node’ and in a couple of seconds, you should see the detected text returned from Wit.ai.
Here’s a GIF of me following the steps above.
Since most of the internet functions on HTTP requests; you can use n8n to integrate any platform that supports a RESTful API using a similar set of steps (consult the documentation) for the appropriate settings.
You can also use n8n to automate cross-platform tasks, by integrating several platforms into your workflow.
For example, the data extracted from the webpage could be saved to a Google Sheet by adding a node to the workflow. The text detected using Wit.ai could be connected to Google’s Translate API using the HTTP Request node and translated to a different languages!
In this tutorial, we learnt to use the HTTP Request node to extract information from the web, create a cloud server and convert speech to text. We also discussed the possibility of using the HTTP Request node with other RESTful APIs and the versatility in doing so, most of the web functions on HTTP requests.
Much like people, technology works better as a collective. n8n enables you to integrate a tool with any other tool, enabling cross-platform workflows like never before. The possibilities are endless. What will you automate?
In case you’ve run into an issue while following the tutorial, feel free to reach out to me on LinkedIn or ask for help on our forum 💙
Previously published at https://medium.com/n8n-io/http-request-node-the-swiss-army-knife-b14e22283383