M
MJK.Supplies
Home / n8n / n8n API Workflows: Connect Any API Without Writi…
n8n

n8n API Workflows: Connect Any API Without Writing Code

n8n is fundamentally an API orchestration tool. Almost every workflow involves calling APIs — sending data, receiving data, and transforming it as it moves between services. This guide covers advanced API workflow patterns in n8n, including authentication, pagination, rate limiting, error handling, and building complex multi-API pipelines.

M
MJK Supplies · May 27, 2026 · 11 min read
ShareXinf↗
n8n API Workflows: Connect Any API Without Writing Code

HTTP Request Node Deep Dive

The HTTP Request node is n8n's universal API connector. Everything you can do via REST API, you can do with this node.

Core configuration:

  • Method: GET, POST, PUT, PATCH, DELETE, HEAD
  • URL: Target endpoint (can use expressions: https://api.example.com/{{$json.id}})
  • Authentication: None, Basic Auth, Header Auth, OAuth2, etc.
  • Body: Form data, JSON, raw text, form-urlencoded, or binary
  • Response: JSON, string, file

Dynamic URLs:

https://api.hubspot.com/crm/v3/contacts/{{ $json.contactId }}

Use expressions to build URLs from previous node data.

Authentication Patterns

Bearer token (most common): Header Auth credential:

  • Name: Authorization
  • Value: Bearer {{ $env.MY_API_TOKEN }}

API key in header:

  • Name: X-API-Key
  • Value: {{ $env.SERVICE_API_KEY }}

API key in query param: Add as query string parameter in the node:

  • Name: api_key
  • Value: {{ $env.API_KEY }}

OAuth2: n8n handles OAuth2 flows for supported services (Google, Slack, HubSpot, etc.) via the credential system. For custom OAuth2, use the generic OAuth2 credential type.

Rotating credentials: For APIs with short-lived tokens, use a Code node to fetch a new token before each API call:

// Fetch fresh token const tokenResponse = await $http.post('https://auth.example.com/token', { client_id: $env.CLIENT_ID, client_secret: $env.CLIENT_SECRET, grant_type: 'client_credentials' }); return [{ json: { token: tokenResponse.access_token } }];

Pagination Handling

Most APIs return results in pages. Handle pagination automatically:

Offset-based pagination:

// Code node that loops until all pages retrieved let allResults = []; let page = 0; const limit = 100; while (true) { const response = await $http.get(`https://api.example.com/items?limit=${limit}&offset=${page * limit}`); allResults = allResults.concat(response.items); if (response.items.length < limit) break; // Last page page++; } return allResults.map(item => ({ json: item }));

Cursor-based pagination:

let allResults = []; let cursor = null; do { const url = cursor ? `https://api.example.com/items?cursor=${cursor}` : 'https://api.example.com/items'; const response = await $http.get(url); allResults = allResults.concat(response.data); cursor = response.next_cursor; } while (cursor);

Rate Limiting

APIs enforce rate limits. Handle them without breaking workflows:

Proactive rate limiting (add delays): Use Wait nodes between HTTP Request nodes when calling the same API repeatedly:

  • Add Wait node → 1000ms between calls
  • This prevents 429 errors on APIs with per-second limits

Reactive rate limiting (retry on 429):

// Code node — check for 429 and set retry flag const statusCode = $input.first().json.statusCode; if (statusCode === 429) { return [{ json: { shouldRetry: true, waitMs: 60000 } }]; } return [{ json: { shouldRetry: false } }];

Then add IF node → if shouldRetry → Wait node (60s) → re-run HTTP request.

Webhook Workflows

n8n as a webhook receiver (not just sender):

Webhook trigger node: Generates a URL like https://your-n8n.com/webhook/abc123. Any service that can POST to a URL can trigger your workflow.

Common webhook sources:

  • GitHub (PR created, issue opened)
  • Stripe (payment received, subscription cancelled)
  • HubSpot (deal stage changed)
  • Calendly (booking made)
  • Shopify (order created)
  • Custom applications

Securing webhooks: For production webhooks, validate the signature:

const crypto = require('crypto'); const signature = $input.first().headers['x-hub-signature-256']; const payload = JSON.stringify($input.first().json); const expected = 'sha256=' + crypto.createHmac('sha256', $env.WEBHOOK_SECRET).update(payload).digest('hex'); if (signature !== expected) { throw new Error('Invalid webhook signature'); }

Multi-API Orchestration

Complex workflows combine multiple APIs:

CRM + Email + AI pipeline:

  1. HubSpot API: get new leads from today
  2. Clearbit API: enrich each lead
  3. Claude API: generate personalised email
  4. Gmail API: create draft email
  5. Slack API: notify sales rep

Each step calls a different API; n8n passes data between them.

Data sync workflow:

  1. Source API (e.g., Shopify): fetch new orders
  2. Transform (Code node): map Shopify fields to HubSpot fields
  3. HubSpot API: create/update contacts and deals
  4. Database: log sync results
  5. Slack: daily sync summary

Error Handling and Retry

Production API workflows need error handling:

Error branch: Right-click any node → Add Error Output. Connect to error handling nodes.

Exponential backoff:

const attempt = $input.first().json.attempt || 1; const maxAttempts = 5; if (attempt > maxAttempts) throw new Error('Max retry attempts exceeded'); const waitMs = Math.pow(2, attempt) * 1000; // 2s, 4s, 8s, 16s, 32s return [{ json: { attempt: attempt + 1, waitMs } }];

Recommended Tools

  • n8n — API orchestration backbone
  • Claude API — AI step in multi-API workflows
  • HubSpot — CRM API for sales workflows
  • Apollo.io — Lead data API
  • Airtable — Database for workflow state and results
#n8n#api#http#integration

Related articles

MJK Supplies · Automation Services

Want this built for you?

We design and ship custom AI agents and automation systems for teams that want results, not a backlog. Book a free 30-minute consult — no commitment, no pitch deck.