n8nen.nl logo n8nen.nl

N8N HTTP Request Node: Complete Tutorial voor API Integraties

2025-01-25 Sam Hamelijnck
N8N HTTP Request Node: Complete Tutorial voor API Integraties
N8N Workflow Data Input Request HTTP Request GET • POST • PUT • DELETE Headers • Auth • Body Pagination • Retry API Call External API REST Service JSON/XML Response Data Process Next Node Transform Store/Send HTTP Request Node: API Integratie Meester Verbind met elke API • Authenticatie • Pagination • Error Handling

Wat is de N8N HTTP Request Node?

De HTTP Request Node is zonder twijfel een van de meest gebruikte en krachtigste nodes in N8N. Het is je gateway naar de wereld van API's en web services. Met deze node kun je:

  • API calls maken naar elke REST service
  • Data ophalen van externe bronnen
  • Informatie versturen naar web services
  • Webhooks triggeren in andere systemen
  • Authenticatie beheren voor beveiligde endpoints
  • Files uploaden/downloaden via HTTP
  • Complex pagination automatisch afhandelen

Waarom is de HTTP Request Node zo belangrijk?

Bijna elke moderne applicatie heeft een API. Als N8N geen specifieke integratie node heeft voor een service, is de HTTP Request Node je redding. Het is de universele connector die met ALLES kan praten wat een API heeft.

Inhoudsopgave

1. Basis Configuratie en HTTP Methods

Laten we beginnen met de fundamenten. De HTTP Request Node ondersteunt alle standaard HTTP methods:

Method Gebruik Voor Voorbeeld Use Case
GET Data ophalen User info, product lijst, status check
POST Nieuwe resources aanmaken Nieuwe order, user registratie, comment plaatsen
PUT Complete update van resource Profiel volledig updaten, product vervangen
PATCH Gedeeltelijke update Status wijzigen, enkele velden updaten
DELETE Resource verwijderen Account verwijderen, item deleten
HEAD Headers ophalen zonder body Check of resource bestaat, file size check
OPTIONS Toegestane methods checken CORS preflight, API capabilities

Basis Setup Stappen

  1. 1. Node toevoegen: Sleep de HTTP Request node naar je workflow
  2. 2. Method selecteren: Kies de juiste HTTP method voor je use case
  3. 3. URL invoeren: Voer de complete API endpoint URL in
  4. 4. Response format: Kies tussen JSON (meest gebruikt) of Text
# Voorbeeld: Simpele GET request
Method: GET URL: https://api.example.com/users/123 Response Format: JSON
# Response:
{ "id": 123, "name": "Jan Jansen", "email": "jan@example.nl", "status": "active" }

2. Request Parameters: Query, Headers en Body

De HTTP Request Node biedt volledige controle over alle aspecten van je request:

Query Parameters

Query parameters worden toegevoegd aan de URL na een ? teken. Perfect voor filtering, sorting en pagination:

# Query Parameters configuratie
Base URL: https://api.shop.nl/products Query Parameters: - category: "electronics" - sort: "price_asc" - limit: 50 - page: 1 Resulterende URL: https://api.shop.nl/products?category=electronics&sort=price_asc&limit=50&page=1

Headers

Headers bevatten metadata over je request. Essentieel voor authenticatie, content types en custom parameters:

Veelgebruikte Headers:

Header Waarde Voorbeeld Doel
Content-Type application/json Type van request body
Accept application/json Gewenst response format
Authorization Bearer abc123xyz Authentication token
User-Agent N8N/1.0 Client identificatie
X-API-Key your-api-key API key authenticatie

Request Body

Voor POST, PUT en PATCH requests moet je vaak data meesturen in de body:

JSON Body
{
  "customer": {
    "name": "Marie de Vries",
    "email": "marie@bedrijf.nl",
    "phone": "+31612345678"
  },
  "order": {
    "products": [
      {"id": 1, "qty": 2},
      {"id": 5, "qty": 1}
    ],
    "total": 299.99,
    "currency": "EUR"
  }
}
Form Data
Content-Type:
application/x-www-form-urlencoded

firstName=Jan
lastName=Pietersen
email=jan@example.nl
subscribe=true
preference=weekly

// Of multipart/form-data voor files:
------WebKitFormBoundary
Content-Disposition: form-data;
name="file"; filename="doc.pdf"
Content-Type: application/pdf

[Binary data]

3. Authenticatie Methodes

De HTTP Request Node ondersteunt verschillende authenticatie methodes. Hier zijn de belangrijkste:

Basic Authentication

# Basic Auth configuratie
Authentication: Basic Auth Username: api_user Password: super_secret_password
# Dit wordt automatisch omgezet naar:
Authorization: Basic YXBpX3VzZXI6c3VwZXJfc2VjcmV0X3Bhc3N3b3Jk
# (Base64 encoded username:password)

Bearer Token / API Key

# Bearer Token configuratie
Authentication: Header Auth Name: Authorization Value: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
# Voor API Key authenticatie:
Name: X-API-Key Value: sk_live_4242424242424242

OAuth2

Voor complexere OAuth2 flows ondersteunt N8N verschillende grant types:

OAuth2 Grant Types:

  • Authorization Code: Voor user-based authenticatie (Google, Facebook, etc.)
    • • Redirect user naar auth provider
    • • User geeft toestemming
    • • Ontvang authorization code
    • • Exchange voor access token
  • Client Credentials: Voor server-to-server communicatie
    • • Direct token exchange met client ID/secret
    • • Geen user interactie nodig
    • • Perfect voor backend integraties
# OAuth2 Client Credentials configuratie
Grant Type: Client Credentials Access Token URL: https://api.service.com/oauth/token Client ID: your_client_id Client Secret: your_client_secret Scope: read write
# N8N handelt automatisch af:
1. Token request naar OAuth endpoint 2. Access token opslaan 3. Token automatisch verversen bij expiry 4. Token toevoegen aan API requests

Custom Authentication

Voor speciale authenticatie scenarios kun je Custom Auth gebruiken met JSON configuratie:

# Custom Auth JSON voorbeeld
{ "headers": { "X-Shop-Access-Token": "{{$credentials.apiKey}}", "X-Shop-Domain": "{{$credentials.shopDomain}}" }, "qs": { "api_version": "2025-01" } }

4. Werken met JSON Data

JSON is het meest gebruikte data format voor API's. Hier zijn belangrijke technieken:

Dynamic JSON Body met Expressions

Gebruik N8N expressions om dynamische JSON bodies te bouwen:

# Dynamische JSON body met data van vorige node
{ "customer_id": "{{ $json.customer.id }}", "order_date": "{{ $now.toISO() }}", "items": {{ JSON.stringify($json.cart_items) }}, "total": {{ $json.cart_items.reduce((sum, item) => sum + item.price * item.qty, 0) }}, "shipping": { "method": "{{ $json.shipping_preference }}", "address": "{{ $json.address }}" }, "metadata": { "source": "n8n_workflow", "workflow_id": "{{ $workflow.id }}", "execution_id": "{{ $execution.id }}" } }

Response Parsing

N8N parseert JSON responses automatisch, maar soms moet je specifieke data extracten:

JSON Path Expressions:

$.data → Root level data property
$.users[0] → Eerste user in array
$.users[*].email → Alle emails uit users array
$.products[?(@.price > 100)] → Products duurder dan 100
$..id → Alle id's recursief

5. Error Handling en Retry Logic

Robuuste error handling is cruciaal voor betrouwbare workflows:

Retry on Fail Configuratie

Request Fails Wait 1s Retry 1 Fails Wait 2s Retry 2 Fails Wait 4s Retry 3 Success! Exponential Backoff Retry Strategy Max Retries: 3 • Wait Between Tries: 1000ms • Backoff Factor: 2
# Retry configuratie in HTTP Request Node
Settings → Retry on Fail: Max Tries: 5 Wait Between Tries (ms): 2000 Max Wait Time (ms): 10000 On Error: Continue (error output)
# Continue on Fail opties:
- Stop Workflow: Stop bij error - Continue: Ga door met lege output - Continue (using error output): Error data naar volgende node

Error Response Handling

Verschillende manieren om met errors om te gaan:

HTTP Status Codes

  • 400: Bad Request - Verkeerde data
  • 401: Unauthorized - Auth probleem
  • 403: Forbidden - Geen toegang
  • 404: Not Found - Resource bestaat niet
  • 429: Too Many Requests - Rate limit
  • 500: Server Error - API probleem
  • 503: Service Unavailable - Tijdelijk down

Error Workflow Pattern

  1. 1. HTTP Request met Continue on Fail
  2. 2. IF node: Check {{ $json.error }}
  3. 3. Error path: Log + Alert
  4. 4. Success path: Process data
  5. 5. Merge: Combine paths

6. Pagination: Grote Datasets Ophalen

Bij grote datasets gebruikt een API vaak pagination. De HTTP Request Node heeft hier geavanceerde ondersteuning voor:

Pagination Types

Type Hoe Het Werkt Voorbeeld
Page-based Page nummer ophogen ?page=1, ?page=2, ?page=3
Offset-based Skip X records ?offset=0&limit=100
Cursor-based Next cursor token ?cursor=eyJpZCI6MTAwfQ
Link Header URL in response header Link: <url>; rel="next"
Next URL in Body Complete URL in response {"next": "https://api.com/page2"}

Pagination Configuratie

# Page-based Pagination Setup
Pagination Mode: Update a Parameter in Each Request Pagination Parameters: - Type: Query Parameter - Name: page - Value: {{ $pageCount }} - Pagination Complete When: Response is Empty Request Options: - Max Pages: 100 # Voorkom infinite loops - Request Interval: 200 # ms tussen requests
# Cursor-based Pagination
Pagination Mode: Update a Parameter in Each Request - Type: Query Parameter - Name: cursor - Value: {{ $response.headers["x-next-cursor"] }} - Pagination Complete When: Other - Complete Expression: {{ !$response.headers["x-next-cursor"] }}

Pagination Loop Pattern

Voor complexe pagination scenarios kun je een manual loop bouwen:

Initialize page = 1 HTTP Request Get Page Process Store Data Has More? Check Next Yes: page++ No Complete All Data

7. Rate Limiting en Throttling

Veel API's hebben rate limits om overbelasting te voorkomen. Zo ga je er mee om:

Rate Limit Strategies:

Strategie 1: Batch Split

  1. 1. Split Items node (batch size: 10)
  2. 2. HTTP Request voor batch
  3. 3. Wait node (1 seconde)
  4. 4. Loop naar volgende batch

Strategie 2: Rate Limit Headers

  1. 1. Check X-RateLimit-Remaining header
  2. 2. Als 0: Wait tot X-RateLimit-Reset
  3. 3. Anders: Continue met request
  4. 4. Adaptive delay based on remaining
# Rate Limit handling met Wait node
Split in Batches Node: - Batch Size: 50 - Options: Reset Loop Over Items Node:HTTP Request Node: - Batch van 50 items ↓ Wait Node: - Wait: 1 second - Unit: Seconds ↓ Loop back to next batch
# Check rate limit headers:
{{ $response.headers["x-ratelimit-remaining"] }} {{ $response.headers["x-ratelimit-reset"] }} {{ $response.headers["retry-after"] }}

8. Files en Binary Data

De HTTP Request Node kan ook met files en binary data werken:

File Upload

# Multipart Form Data Upload
Method: POST URL: https://api.example.com/upload Body Content Type: Multipart Form Data Body Parameters: { "file": "={{ $binary.data }}", "filename": "={{ $binary.data.fileName }}", "description": "Uploaded via N8N" }
# Voor base64 encoded upload:
Headers: Content-Type: application/json Body: { "file_data": "={{ $binary.data.data }}", "mime_type": "={{ $binary.data.mimeType }}" }

File Download

Download Binary Data:

  1. 1. Response Format: Set to "File" in HTTP Request node
  2. 2. Binary Property: Geef naam voor binary data (bijv. "downloadedFile")
  3. 3. Options:
    • • Download: Als response een file is
    • • Full Response: Include headers en status
    • • Follow Redirects: Voor CDN URLs
  4. 4. Process: Use Move Binary Data node om op te slaan

9. SSL Certificates en Security

Voor enterprise API's met strenge security requirements:

Client Certificate Authentication

# SSL Certificate configuratie
Settings → SSL Certificates: Enable Certificate Credential: - CA Certificate: -----BEGIN CERTIFICATE----- [CA cert content] -----END CERTIFICATE----- - Client Certificate: -----BEGIN CERTIFICATE----- [Client cert content] -----END CERTIFICATE----- - Client Private Key: -----BEGIN PRIVATE KEY----- [Private key content] -----END PRIVATE KEY----- - Passphrase: (optional voor encrypted key)

Security Headers

Belangrijke Security Headers:

  • X-Request-ID: Unique identifier voor request tracking
  • X-Forwarded-For: Original client IP bij proxy gebruik
  • X-API-Version: API versie voor compatibility
  • X-Signature: HMAC signature voor request validation
  • X-Timestamp: Request timestamp voor replay protection

10. Praktijkvoorbeelden met Populaire API's

Laten we kijken naar real-world implementaties:

Voorbeeld 1: OpenAI GPT API

🤖 OpenAI Chat Completion

Method: POST URL: https://api.openai.com/v1/chat/completions Headers: Authorization: Bearer sk-... Content-Type: application/json Body: { "model": "gpt-4", "messages": [ {"role": "system", "content": "Je bent een behulpzame assistent."}, {"role": "user", "content": "{{ $json.user_question }}"} ], "temperature": 0.7, "max_tokens": 500 }

Voorbeeld 2: Stripe Payment API

💳 Stripe Customer Creation

Method: POST URL: https://api.stripe.com/v1/customers Authentication: Basic Auth Username: sk_live_... Password: (leave empty) Body Content Type: Form URL Encoded Body: email={{ $json.customer_email }} name={{ $json.customer_name }} metadata[user_id]={{ $json.user_id }} metadata[source]=n8n_workflow

Voorbeeld 3: SendGrid Email API

📧 SendGrid Transactional Email

Method: POST URL: https://api.sendgrid.com/v3/mail/send Headers: Authorization: Bearer SG... Content-Type: application/json Body: { "personalizations": [{ "to": [{"email": "{{ $json.recipient }}"}], "dynamic_template_data": { "name": "{{ $json.name }}", "order_id": "{{ $json.order_id }}" } }], "from": {"email": "noreply@company.nl"}, "template_id": "d-abc123xyz" }

11. Debugging en Troubleshooting

Tips voor het debuggen van HTTP Request problemen:

Common Issues en Oplossingen

🔍 Debugging Checklist:

  1. 1. Check Request URL
    • • Is de URL correct? (https:// niet vergeten)
    • • Zijn er typos in de endpoint?
    • • Werkt de URL in Postman?
  2. 2. Verify Authentication
    • • Is de API key/token geldig?
    • • Juiste auth method gebruikt?
    • • Token expired?
  3. 3. Inspect Headers
    • • Content-Type correct?
    • • Accept header nodig?
    • • Custom headers vereist?
  4. 4. Validate Body
    • • Valid JSON syntax?
    • • Required fields aanwezig?
    • • Data types correct?
  5. 5. Check Response
    • • Error message in response?
    • • Status code betekenis?
    • • Rate limit hit?

Debug Output

# Enable full response output voor debugging
Options → Response: ✓ Include Response Headers and Status ✓ Full Response Object ✓ Never Error
# Dit geeft je toegang tot:
{{ $json.headers }} # Response headers {{ $json.statusCode }} # HTTP status code {{ $json.statusMessage }} # Status message {{ $json.body }} # Response body
# Log voor debugging:
console.log('Request URL:', $node["HTTP Request"].json.url) console.log('Status:', $node["HTTP Request"].json.statusCode) console.log('Headers:', JSON.stringify($node["HTTP Request"].json.headers))

12. Best Practices en Performance Tips

Volg deze best practices voor betrouwbare en performante API integraties:

✅ DO's

  • • Gebruik environment variables voor API keys
  • • Implementeer proper error handling
  • • Set timeouts voor lange requests
  • • Cache responses waar mogelijk
  • • Use batch endpoints voor bulk operations
  • • Log belangrijke API calls
  • • Test met kleine datasets eerst
  • • Monitor rate limits proactief

❌ DON'Ts

  • • Hardcode geen credentials
  • • Ignore geen error responses
  • • Overload API's niet met requests
  • • Skip geen SSL verificatie in productie
  • • Vergeet geen retry logic
  • • Negeer geen API documentatie
  • • Gebruik geen outdated API versions
  • • Test niet in productie

Performance Optimalisatie

⚡ Performance Tips

Parallel Requests

Gebruik Split in Batches met multiple HTTP nodes voor parallel processing

Connection Reuse

Keep-Alive headers voor persistent connections

Response Filtering

Vraag alleen fields op die je nodig hebt via query params

🚀 Master API Integraties met N8N!

Wil je complexe API integraties bouwen maar weet je niet waar te beginnen? Wij helpen je!

N8N API Integration Service - €100

  • ✅ Custom API integratie setup
  • ✅ Authentication configuratie
  • ✅ Error handling & retry logic
  • ✅ Pagination & rate limiting
  • ✅ Testing & documentatie
  • ✅ 30 dagen support
Start Nu Met API Automatisering →

Conclusie

De HTTP Request Node is de backbone van API integraties in N8N. Met de technieken uit deze guide kun je:

  • ✅ Elke REST API integreren
  • ✅ Complexe authenticatie flows implementeren
  • ✅ Grote datasets verwerken met pagination
  • ✅ Robuuste error handling bouwen
  • ✅ Rate limits respecteren
  • ✅ Files en binary data verwerken

Of je nu een simpele GET request doet of een complexe OAuth2 flow implementeert, de HTTP Request Node heeft alle tools die je nodig hebt. Het is de universele connector die N8N zo krachtig maakt voor automatisering.

#n8n #http request #api #integratie #authenticatie #pagination #tutorial #automatisering