How to Automate Any API with n8n

How to Automate Any API with n8n: The Ultimate HTTP Request Guide

One of the most powerful things about n8n is that you are never limited to built-in integrations. If a service has an API — and almost every modern service does — you can automate it with n8n’s HTTP Request node. No custom code needed, no waiting for someone to build a native integration.

I am Javier, a startup consultant in Chile, and I use n8n’s HTTP Request node almost every day. From pulling data out of obscure SaaS tools to building integrations with custom internal APIs, the HTTP Request node is the Swiss Army knife of automation. I have connected APIs that have no n8n node, handled complex pagination, managed rate limits, and built error-resilient flows that process thousands of API calls daily.

In this tutorial, I will teach you everything you need to know to automate any API with n8n. We will cover authentication methods, handling paginated responses, error management, rate limiting, and I will walk you through real examples of connecting APIs that do not have native n8n nodes.

Understanding the HTTP Request Node

The HTTP Request node is n8n’s universal API connector. It can make any HTTP request — GET, POST, PUT, PATCH, DELETE — to any URL, with any headers, query parameters, and body content.

If you have ever used tools like Postman or curl, the HTTP Request node will feel familiar. If you have not, do not worry — I will explain everything from scratch.

When to use the HTTP Request node

Use it when:

– The service you want to connect has no native n8n node
– The native node does not support the specific API endpoint you need
– You want to interact with your own custom APIs
– You need more control than the native node provides
– You are working with a webhook or REST API

Basic anatomy of an API request

Every API request has:

Method: What you want to do (GET = read, POST = create, PUT = update, DELETE = remove)
URL: The endpoint address (e.g., https://api.example.com/users)
Headers: Metadata like authentication tokens and content type
Query Parameters: Filters and options appended to the URL (e.g., ?page=1&limit=50)
Body: Data you are sending (for POST and PUT requests)

The HTTP Request node lets you configure all of these visually.

Setting Up Your First API Call

Let me walk you through a concrete example. We will connect to the JSONPlaceholder API (a free test API) to understand the basics before moving to real-world scenarios.

Step 1: Add the HTTP Request node

1. Open n8n and create a new workflow
2. Click the plus button to add a node
3. Search for “HTTP Request” and select it

Step 2: Configure a GET request

Set up the node:

Method: GET
URL: `https://jsonplaceholder.typicode.com/posts`
– Leave everything else as default

Click Test step. You should see a list of 100 posts returned from the API.

Step 3: Add query parameters

To filter results, add query parameters:

– Click Add Parameter under Query Parameters
Name: `userId`
Value: `1`

Now the request only returns posts by user 1. The URL becomes `https://jsonplaceholder.typicode.com/posts?userId=1`.

Step 4: Make a POST request

Change the method to POST and configure:

Method: POST
URL: `https://jsonplaceholder.typicode.com/posts`
Body Content Type: JSON
Body:

“`json
{
“title”: “My automated post”,
“body”: “This was created by n8n”,
“userId”: 1
}
“`

Click Test step. The API returns the created resource with an ID.

That is the foundation. Now let us get into the real-world stuff.

Authentication Methods

Most real APIs require authentication. n8n supports all common authentication methods through the HTTP Request node.

Method 1: API Key Authentication

API key authentication is the simplest and most common method. The API gives you a key, and you include it in your requests.

APIs accept keys in different places:

API Key in headers (most common):

1. In the HTTP Request node, go to Authentication
2. Select Generic Credential Type
3. Select Header Auth
4. Create a new credential:
Name: The header name (e.g., `X-API-Key`, `api-key`, or `Authorization`)
Value: Your API key

API Key in query parameters:

Some APIs want the key as a URL parameter. Configure this in Query Parameters:

Name: `api_key` (or whatever the API documentation specifies)
Value: Your API key

Example: Connecting to the OpenWeatherMap API

“`
Method: GET
URL: https://api.openweathermap.org/data/2.5/weather

Query Parameters:
q: Santiago,CL
appid: your_api_key_here
units: metric
“`

This returns current weather data for Santiago, Chile. The API key is passed as the `appid` query parameter.

Method 2: Bearer Token Authentication

Bearer tokens are used by many modern APIs, including social media platforms and SaaS tools.

1. In the HTTP Request node, go to Authentication
2. Select Generic Credential Type
3. Select Header Auth
4. Configure:
Name: `Authorization`
Value: `Bearer your_token_here`

Example: Connecting to the Notion API

“`
Method: GET
URL: https://api.notion.com/v1/databases/your_database_id/query

Headers:
Notion-Version: 2022-06-28

Authentication:
Header Auth
Name: Authorization
Value: Bearer secret_your_notion_token
“`

The `Bearer` prefix before the token is important — most APIs require it.

Method 3: OAuth2 Authentication

OAuth2 is used by Google, Microsoft, Twitter, and many enterprise APIs. It is more complex because it involves a multi-step authorization flow.

1. In the HTTP Request node, go to Authentication
2. Select OAuth2
3. Create a new OAuth2 credential:
Authorization URL: From the API documentation
Access Token URL: From the API documentation
Client ID: From your app registration
Client Secret: From your app registration
Scope: The permissions you need (from the API docs)

n8n handles the token refresh automatically, which is a huge time saver.

Setting up OAuth2 for a custom API:

1. Register an application with the API provider (e.g., create a Google Cloud project)
2. Get the Client ID and Client Secret
3. Set the redirect URI in the API provider to: `https://your-n8n-domain.com/rest/oauth2-credential/callback`
4. Configure the OAuth2 credential in n8n with these values
5. Click Sign in to authorize

Method 4: Basic Authentication

Some APIs (and many internal tools) use basic username/password authentication.

1. In the HTTP Request node, go to Authentication
2. Select Generic Credential Type
3. Select Basic Auth
4. Enter your username and password

n8n automatically encodes these in the proper Base64 format in the Authorization header.

Credential Security Best Practices

– Always use n8n’s credential system instead of hardcoding keys in expressions
– Use environment variables for sensitive values when self-hosting
– Create separate credentials for development and production
– Rotate API keys periodically
– Use the minimum required permissions/scopes

If you want to set up n8n quickly and start testing API integrations, n8n cloud handles credential encryption and storage for you out of the box.

Handling Paginated APIs

Most APIs do not return all results at once. They use pagination — returning results in pages of 50, 100, or whatever limit they set. Handling pagination correctly is crucial for pulling complete datasets.

Understanding Pagination Types

Offset-based pagination: Uses `page` and `limit` (or `offset` and `count`) parameters.

“`
GET /api/items?page=1&limit=50
GET /api/items?page=2&limit=50
GET /api/items?page=3&limit=50
“`

Cursor-based pagination: Uses a cursor token from the previous response to get the next page.

“`
GET /api/items?limit=50
GET /api/items?limit=50&cursor=abc123
GET /api/items?limit=50&cursor=def456
“`

Link-based pagination: The response includes URLs for the next page.

Method 1: Built-in Pagination (Recommended)

n8n’s HTTP Request node has built-in pagination support since version 1.x.

1. In the HTTP Request node, enable Pagination
2. Choose the pagination type:
Offset: Specify the parameter names and increment values
Response Contains Next URL: n8n reads the next page URL from the response
Response Contains Cursor: n8n reads a cursor value from the response

Example: Offset pagination with the HubSpot API

“`
Pagination Mode: Offset
Limit Parameter: limit
Limit Value: 100
Offset Parameter: after

Complete When:
Response has no more data
Look for: $.results
“`

n8n automatically loops through all pages until there are no more results.

Method 2: Loop with a Merge Node

For APIs with unusual pagination patterns, you can build a manual pagination loop:

1. HTTP Request node makes the first API call
2. IF node checks if there are more pages (e.g., does the response include a `next_page` token?)
3. If yes, loop back to the HTTP Request with the new cursor/page value
4. If no, continue the workflow with all collected data

The loop approach uses these nodes:

HTTP Request — Makes the API call
Code node — Extracts the pagination cursor from the response
IF node — Checks if more pages exist
Merge node — Combines results from all pages
Loop back to HTTP Request with the next cursor

Pagination Tips

– Always set a reasonable page size (50 to 100 items per page is common)
– Add a maximum page limit to prevent infinite loops
– Some APIs have rate limits that kick in during rapid pagination — add delays if needed
– Monitor memory usage when pulling large datasets — process data in batches if possible

Error Handling and Retry Logic

APIs fail. Servers go down, rate limits get hit, networks have issues. Your automations need to handle these gracefully.

Built-in Retry Options

The HTTP Request node has a built-in retry mechanism:

1. Under Options, find Retry on Fail
2. Enable it and configure:
Max Tries: How many times to retry (I use 3)
Wait Between Tries (ms): Delay between retries (start with 1000ms)

Understanding HTTP Status Codes

Knowing what different error codes mean helps you handle them properly:

400 Bad Request: Your request is malformed — fix the parameters
401 Unauthorized: Authentication failed — check your credentials
403 Forbidden: You do not have permission for this resource
404 Not Found: The endpoint or resource does not exist
429 Too Many Requests: You hit the rate limit — slow down
500 Internal Server Error: The API server has a problem — retry later
502/503/504: Server overload or gateway issues — retry later

Advanced Error Handling with Error Workflow

For production workflows, set up an Error Trigger workflow:

1. Create a new workflow with an Error Trigger node
2. Add notification nodes (Slack, email) to alert you when errors occur
3. In your main workflow, go to Settings > Error Workflow and select the error handler

This way, you get notified about any workflow failures without cluttering your main workflow with error handling logic.

Continue on Fail

Sometimes you want the workflow to continue even if one API call fails (e.g., when processing a batch of items and one fails):

1. Click on the HTTP Request node
2. Go to Settings
3. Enable Continue on Fail

The node outputs error information instead of stopping the workflow, and you can use an IF node to handle failed items separately.

Custom Error Handling Pattern

Here is my recommended pattern for robust API error handling:

1. HTTP Request — Make the API call with retry enabled
2. IF node — Check if the response status code indicates success
3. Success path — Continue processing
4. Error path — Log the error, send a notification, and optionally add the failed item to a retry queue

“`
Expression for checking status:
{{ $json.statusCode >= 200 && $json.statusCode < 300 }} ```

Rate Limiting

Most APIs limit how many requests you can make in a given time window. Exceeding the limit results in 429 errors and possibly getting your API key banned.

Method 1: Built-in Batch Processing

n8n’s Split In Batches node lets you process items in groups with a delay between batches:

1. Add a Split In Batches node before your HTTP Request
2. Set Batch Size to the number of items per batch (e.g., 10)
3. In the HTTP Request node, add a Wait node after it with a delay (e.g., 1 second)

Method 2: Wait Node

For simple rate limiting, add a Wait node after your HTTP Request:

1. Add a Wait node
2. Set the delay to match the API’s rate limit

For example, if the API allows 60 requests per minute, add a 1-second delay between requests.

Method 3: Code-Based Rate Limiting

For precise control, use a Code node to implement a token bucket or sliding window rate limiter:

“`javascript
// Simple rate limiter – waits to respect the limit
const RATE_LIMIT = 10; // requests per second
const DELAY = 1000 / RATE_LIMIT; // milliseconds between requests

// Get the current item index
const itemIndex = $itemIndex;

// Calculate delay based on position in batch
const waitMs = itemIndex * DELAY;

// Wait
await new Promise(resolve => setTimeout(resolve, waitMs));

return $input.all();
“`

Reading Rate Limit Headers

Many APIs return rate limit information in response headers:

– `X-RateLimit-Limit` — Maximum requests allowed
– `X-RateLimit-Remaining` — Requests remaining in the current window
– `X-RateLimit-Reset` — When the limit resets (usually a Unix timestamp)

You can read these in a Code node after the HTTP Request:

“`javascript
const remaining = $json.headers[‘x-ratelimit-remaining’];
const resetTime = $json.headers[‘x-ratelimit-reset’];

if (remaining < 5) { // Getting close to the limit, calculate wait time const waitMs = (resetTime * 1000) - Date.now(); if (waitMs > 0) {
await new Promise(resolve => setTimeout(resolve, waitMs));
}
}

return $input.all();
“`

Real-World Examples: Connecting APIs Without Native Nodes

Let me walk you through practical examples of connecting to APIs that do not have built-in n8n integrations.

Example 1: Pulling Data from a Custom REST API

Scenario: You have an internal API that returns customer data, and you want to sync it to Google Sheets daily.

Workflow:

1. Schedule Trigger — Runs every day at 9 AM
2. HTTP Request — GET to your API endpoint with authentication
3. Code node — Transform the data into the format Google Sheets expects
4. Google Sheets node — Append or update rows

HTTP Request configuration:

“`
Method: GET
URL: https://api.yourcompany.com/v1/customers
Authentication: Header Auth
Name: X-API-Key
Value: {{ $credentials.customApiKey }}
Query Parameters:
updated_since: {{ $now.minus(1, ‘day’).toISO() }}
limit: 500
“`

Example 2: Sending Data to a Webhook-Based Service

Scenario: You want to send lead data from a form submission to a CRM that only has a webhook API.

Workflow:

1. Webhook trigger — Receives form submissions
2. Code node — Map form fields to the CRM’s expected format
3. HTTP Request — POST the data to the CRM’s webhook endpoint

HTTP Request configuration:

“`
Method: POST
URL: https://hooks.crm-service.com/api/v1/leads
Headers:
Content-Type: application/json
Body (JSON):
{
“name”: “{{ $json.firstName }} {{ $json.lastName }}”,
“email”: “{{ $json.email }}”,
“source”: “website_form”,
“custom_fields”: {
“company”: “{{ $json.company }}”,
“interest”: “{{ $json.interest }}”
}
}
“`

Example 3: Working with GraphQL APIs

Some modern APIs use GraphQL instead of REST. The HTTP Request node handles this too.

HTTP Request configuration for a GraphQL query:

“`
Method: POST
URL: https://api.example.com/graphql
Headers:
Content-Type: application/json
Authorization: Bearer your_token
Body (JSON):
{
“query”: “query { users(first: 50) { edges { node { id name email createdAt } } pageInfo { hasNextPage endCursor } } }”
}
“`

For mutations (creating/updating data):

“`json
{
“query”: “mutation CreateUser($input: CreateUserInput!) { createUser(input: $input) { id name } }”,
“variables”: {
“input”: {
“name”: “John Doe”,
“email”: “[email protected]
}
}
}
“`

Example 4: File Upload via API

Some APIs require multipart form data for file uploads.

HTTP Request configuration:

“`
Method: POST
URL: https://api.example.com/upload
Body Content Type: Multipart Form Data
Body Parameters:
– Name: file (type: File)
– Name: description (type: String, value: “Uploaded by n8n”)
“`

In n8n, you can pass binary data from a previous node (like Read Binary File or another HTTP Request that downloaded a file) directly to the file parameter.

Example 5: Chaining Multiple API Calls

Often you need data from one API to call another. For example, getting a list of orders from one system and checking inventory in another.

Workflow:

1. HTTP Request 1 — GET orders from the e-commerce API
2. Split In Batches — Process orders one at a time
3. HTTP Request 2 — Check inventory for each order’s product
4. IF node — Is the product in stock?
5. HTTP Request 3 (yes path) — Confirm the order
6. HTTP Request 3 (no path) — Notify about stock issue

Each HTTP Request uses data from the previous step using expressions like `{{ $json.productId }}` and `{{ $json.orderId }}`.

Advanced Tips

Using Expressions in URLs

You can build dynamic URLs with expressions:

“`
https://api.example.com/users/{{ $json.userId }}/orders?status={{ $json.orderStatus }}
“`

Handling Different Response Formats

Most APIs return JSON, but some return XML, CSV, or binary data.

For XML responses, n8n can parse them automatically. In the HTTP Request node options, set Response Format to String and use a Code node to parse XML:

“`javascript
const xml2js = require(‘xml2js’);
const parser = new xml2js.Parser();
const result = await parser.parseStringPromise($json.data);
return [{ json: result }];
“`

Caching API Responses

If you call the same API endpoint frequently with the same parameters, consider caching:

1. Store API responses in a database or file
2. Before making an API call, check if a cached response exists and is still fresh
3. Only make the API call if the cache is stale

This reduces API calls, speeds up workflows, and helps stay within rate limits.

Timeout Configuration

For slow APIs, increase the timeout:

In the HTTP Request node options, set Timeout to a higher value (default is 300 seconds / 5 minutes). For particularly slow endpoints, you might need 600 seconds or more.

Wrapping Up

The HTTP Request node is what makes n8n truly universal. With it, any API becomes an automation building block — no matter how niche, how custom, or how new the service is. You do not have to wait for a native integration; you can build one yourself in minutes.

The key concepts to remember:

– Choose the right authentication method for each API
– Handle pagination to get complete datasets
– Implement error handling and retries for production reliability
– Respect rate limits to avoid getting blocked
– Use expressions to build dynamic, data-driven API calls

If you want to start building API automations with n8n, get started with n8n and try connecting to an API you use daily. Start simple — a single GET request — and build from there. The best way to learn is by doing.

Frequently Asked Questions

Can n8n connect to any API?

Yes, as long as the API is accessible over HTTP/HTTPS (which covers virtually all modern APIs), n8n can connect to it using the HTTP Request node. This includes REST APIs, GraphQL APIs, SOAP services (with XML body), and webhook endpoints. The only APIs you cannot connect to directly are those that require desktop SDK integration or specific binary protocols, which are extremely rare. If you can call it from Postman or curl, you can call it from n8n.

How do I debug API calls that are failing in n8n?

Start by looking at the HTTP Request node’s output after a test run — n8n shows the full response including status code, headers, and body. Common issues include wrong authentication (check for typos in tokens, missing Bearer prefix), incorrect URL (check for trailing slashes), wrong Content-Type header (most APIs expect application/json), and missing required fields in the body. Enable the “Full Response” option in the node to see all response details. You can also use the n8n execution log to review past runs and their input/output data at every step.

How do I handle APIs that require multiple authentication steps?

Some APIs use multi-step authentication, like getting a session token first and then using it for subsequent requests. Build this as a multi-node flow: first HTTP Request gets the token (POST to the auth endpoint with your credentials), a Set node or Code node extracts the token from the response, and then subsequent HTTP Request nodes use that token in their Authorization headers via expressions. For OAuth2 flows, n8n handles the complexity automatically through its built-in OAuth2 credential type — you just provide the client ID, secret, and authorization URLs, and n8n manages token refresh for you.

🚀 Ready to automate?

Start your free n8n trial today.

Try n8n Free →