Lesson 108 min

HTTP Node in n8n Tutorial

Learn how to use the HTTP Request node in n8n to connect to any API, fetch data, and integrate external services into your workflows.

HTTP Node in n8n Tutorial

In this tutorial, you'll learn how to use the HTTP Request node in n8n to connect your workflows to virtually any API or web service. The HTTP node is one of the most powerful and versatile nodes in n8n, allowing you to integrate with thousands of services, fetch data from external sources, and send data to other platforms.

What is the HTTP Node?

The HTTP Request node allows you to make HTTP/HTTPS requests to any URL endpoint. Whether you're working with REST APIs, webhooks, or custom web services, the HTTP node gives you complete control over:

  • Request Method: GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS
  • Headers: Custom headers, authentication tokens, content types
  • Body Data: JSON, form data, XML, or raw text
  • Query Parameters: URL parameters for filtering and pagination
  • Authentication: Basic auth, OAuth, API keys, bearer tokens

When to Use the HTTP Node

Use the HTTP node when you need to:

  • Connect to APIs that don't have a dedicated n8n node
  • Make custom API calls with specific configurations
  • Integrate with internal company APIs
  • Fetch data from public APIs (weather, news, stocks, etc.)
  • Send data to webhooks or external services
  • Test API endpoints during development

Basic Configuration

Making a Simple GET Request

The most common use case is fetching data from an API.

Configuration:

  • Method: GET
  • URL: https://api.example.com/users
  • Authentication: None (or as required)
  • Response Format: JSON

Example:

URL: https://jsonplaceholder.typicode.com/users
Method: GET

Response:

[
  {
    "id": 1,
    "name": "Leanne Graham",
    "email": "leanne@example.com",
    "username": "Bret"
  }
]

Making a POST Request

Send data to an API to create new resources.

Configuration:

  • Method: POST
  • URL: https://api.example.com/users
  • Body Content Type: JSON
  • Body: Your data in JSON format

Example:

{
  "name": "John Doe",
  "email": "john@example.com",
  "role": "admin"
}

Authentication Methods

1. API Key Authentication

Many APIs use API keys passed in headers or query parameters.

Header Authentication:

Header Name: X-API-Key
Header Value: your_api_key_here

Query Parameter Authentication:

URL: https://api.example.com/data?api_key=your_api_key_here

2. Bearer Token Authentication

Common for OAuth and JWT-based authentication.

Authentication Type: Bearer Token

Token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...

3. Basic Authentication

Uses username and password encoded in Base64.

Authentication Type: Basic Auth

Username: your_username
Password: your_password

4. OAuth2 Authentication

For services requiring OAuth2 flow.

Authentication Type: OAuth2

  • Configure authorization URL
  • Set token URL
  • Provide client ID and secret
  • Define scopes

Advanced Configuration

Working with Headers

Headers provide additional information about your request.

Common Headers:

Content-Type: application/json
Accept: application/json
User-Agent: n8n-workflow
Authorization: Bearer token_here

Setting Custom Headers:

Header Name: X-Custom-Header
Value: {{ $json.customValue }}

Query Parameters

Add parameters to your URL for filtering, pagination, or search.

Parameter Examples:

page: 1
limit: 50
search: {{ $json.searchTerm }}
filter: status=active

Resulting URL:

https://api.example.com/data?page=1&limit=50&search=products&filter=status=active

Request Body Options

The HTTP node supports multiple body formats:

1. JSON:

{
  "field1": "value1",
  "field2": "{{ $json.dynamicValue }}"
}

2. Form-Data:

key1: value1
key2: value2

3. Form-URL-Encoded:

username=john&password=secret&remember=true

4. Raw/Custom: Use for XML, plain text, or custom formats.

Practical Use Cases

Use Case 1: Weather API Integration

Fetch current weather data for a city.

Configuration:

Method: GET
URL: https://api.openweathermap.org/data/2.5/weather
Query Parameters:
  - q: {{ $json.city }}
  - appid: YOUR_API_KEY
  - units: metric

Use Case 2: Send Slack Notification

Post a message to Slack using their webhook.

Configuration:

Method: POST
URL: https://hooks.slack.com/services/YOUR/WEBHOOK/URL
Body (JSON):
{
  "text": "{{ $json.message }}",
  "channel": "#general",
  "username": "n8n Bot"
}

Use Case 3: CRM Data Sync

Update customer information in your CRM.

Configuration:

Method: PUT
URL: https://api.crm.com/v1/contacts/{{ $json.contactId }}
Headers:
  - Authorization: Bearer YOUR_TOKEN
Body (JSON):
{
  "email": "{{ $json.email }}",
  "phone": "{{ $json.phone }}",
  "status": "active"
}

Use Case 4: Database Webhook

Send processed data to an external database via webhook.

Configuration:

Method: POST
URL: https://your-database.com/api/records
Headers:
  - Content-Type: application/json
  - X-API-Key: YOUR_KEY
Body (JSON):
{
  "table": "customers",
  "data": {
    "name": "{{ $json.name }}",
    "created_at": "{{ $now }}"
  }
}

Response Handling

Accessing Response Data

The HTTP node returns the response in $json:

{{ $json.data }}          // Access data field
{{ $json.results[0] }}    // Access first array item
{{ $json.user.name }}     // Access nested properties

Response Options

Full Response: Get complete response including headers and status code

{
  "body": { "data": "..." },
  "headers": { "content-type": "application/json" },
  "statusCode": 200
}

Include Response Headers: Access response headers in your workflow

Follow Redirects: Automatically follow 301/302 redirects

Ignore SSL Issues: For development/testing with self-signed certificates

Error Handling

HTTP Status Codes

  • 200-299: Success
  • 400-499: Client errors (bad request, unauthorized, not found)
  • 500-599: Server errors

Error Handling Options

1. Continue on Fail: Don't stop workflow if request fails

2. Retry on Fail:

  • Set max retries
  • Define wait time between retries
  • Useful for rate-limited APIs

3. Use Error Trigger: Catch errors and handle them in a separate workflow branch

Handling Rate Limits

Many APIs have rate limits. Best practices:

- Add delay between requests (Wait node)
- Check rate limit headers
- Implement exponential backoff
- Use batching when possible

Best Practices

  1. Store Credentials Securely: Use n8n's credential system, never hardcode API keys
  2. Handle Errors Gracefully: Always configure error handling for production workflows
  3. Use Expressions: Leverage n8n expressions for dynamic URLs and data
  4. Log Responses: Keep response data for debugging and monitoring
  5. Test Thoroughly: Use "Execute Node" to test requests before deploying
  6. Respect Rate Limits: Implement delays and retry logic appropriately
  7. Validate Data: Check response data before using it in downstream nodes
  8. Use Appropriate Methods: GET for reading, POST for creating, PUT/PATCH for updating, DELETE for removing

Common Patterns

Pattern 1: Pagination

Loop through paginated API results:

1. Set Counter node (page = 1)
2. HTTP Request (with page parameter)
3. Process data
4. Increment counter
5. Loop if more pages exist

Pattern 2: Batch Processing

Process multiple items with API calls:

1. Split In Batches node
2. HTTP Request (for each batch)
3. Wait node (respect rate limits)
4. Merge results

Pattern 3: API Chain

Call multiple APIs in sequence:

1. HTTP Request (Get user ID)
2. HTTP Request (Get user details using ID)
3. HTTP Request (Get user orders using ID)
4. Combine data

Troubleshooting

Request Fails with 401 Unauthorized?

  • Check authentication credentials
  • Verify API key is active
  • Ensure token hasn't expired

Getting 404 Not Found?

  • Verify URL is correct
  • Check if endpoint exists
  • Ensure proper URL encoding

Timeout Errors?

  • Increase timeout setting
  • Check API server status
  • Verify network connectivity

CORS Errors?

  • CORS typically affects browsers, not n8n
  • Use proper credentials configuration
  • Contact API provider if issues persist

Advanced Tips

Dynamic URLs

Build URLs dynamically using expressions:

{{ "https://api.example.com/" + $json.endpoint + "/" + $json.id }}

Conditional Headers

Add headers based on conditions:

{
  "headers": {
    "Authorization": "{{ $json.useAuth ? 'Bearer ' + $json.token : '' }}"
  }
}

Response Parsing

Parse and transform response data:

{{ JSON.parse($json.responseString) }}
{{ $json.data.map(item => item.id) }}

Key Benefits

  • Universal Integration: Connect to any API or web service
  • Full Control: Complete control over requests and responses
  • Flexible Authentication: Support for all common auth methods
  • Dynamic Configuration: Use expressions for dynamic requests
  • Error Handling: Built-in retry and error handling capabilities
  • Production Ready: Reliable and scalable for production workflows

Conclusion

The HTTP Request node is your gateway to unlimited integrations in n8n. Master this node, and you'll be able to connect to virtually any service, fetch data from any source, and build powerful automation workflows that span across multiple platforms and services.

Start with simple GET requests, then progressively explore POST requests, authentication methods, and advanced configurations. With practice, you'll be building complex API integrations with ease.