금. 8월 15th, 2025

D: The n8n HTTP Node is a powerful tool for interacting with APIs, enabling seamless automation and data integration. Whether you’re fetching data from a REST API, sending payloads to a webhook, or handling complex authentication methods, mastering this node unlocks endless possibilities. 🚀

In this guide, we’ll explore:
Common API Authentication Methods (API Keys, OAuth, Basic Auth, Bearer Tokens)
Handling Request & Response Data (Query Params, Headers, JSON Parsing)
Practical Workflow Examples (Slack, Twitter, Custom APIs)

Let’s dive in!


🔑 1. API Authentication Methods in n8n HTTP Node

A. API Key Authentication

Many APIs (e.g., Weather APIs, OpenAI) use simple API keys.

  • Where to Place the Key?
    • Headers: Authorization: Bearer YOUR_API_KEY or X-API-Key: YOUR_KEY
    • Query Params: ?api_key=YOUR_KEY

Example (OpenAI API):

{
  "url": "https://api.openai.com/v1/chat/completions",
  "method": "POST",
  "headers": {
    "Authorization": "Bearer sk-xxxxxxxx",
    "Content-Type": "application/json"
  },
  "body": {
    "model": "gpt-3.5-turbo",
    "messages": [{"role": "user", "content": "Hello!"}]
  }
}

B. OAuth 2.0

For services like Google, Twitter, or Slack:

  • Use n8n OAuth2 API credentials (pre-configured or custom).
  • Automatically refreshes tokens! 🔄

Example (Google Sheets API):

  1. Set up OAuth2 credentials in n8n.
  2. In the HTTP node:
    {
     "url": "https://sheets.googleapis.com/v4/spreadsheets/SPREADSHEET_ID/values/Sheet1!A1:D10",
     "method": "GET",
     "authentication": "oAuth2"
    }

C. Basic Auth

For APIs requiring username/password (e.g., Jira):

{
  "url": "https://your-domain.atlassian.net/rest/api/2/issue",
  "method": "GET",
  "authentication": "basicAuth",
  "credentials": {
    "user": "email@example.com",
    "password": "YOUR_API_TOKEN"
  }
}

📡 2. Sending & Processing API Data

A. GET Requests with Query Parameters

Need to filter data? Use Query Parameters!

Example (Fetching Twitter Tweets):

{
  "url": "https://api.twitter.com/2/tweets/search/recent",
  "method": "GET",
  "query": {
    "query": "#n8n OR #automation",
    "max_results": "10"
  }
}

B. POST/PUT Requests with JSON Body

Sending data? Structure your payload properly!

Example (Slack Message):

{
  "url": "https://slack.com/api/chat.postMessage",
  "method": "POST",
  "headers": {
    "Authorization": "Bearer xoxb-your-token",
    "Content-Type": "application/json"
  },
  "body": {
    "channel": "#general",
    "text": "Hello from n8n! 🎉"
  }
}

C. Handling Pagination

Some APIs (e.g., Airtable) return paginated data. Use Loops + HTTP Node to fetch all pages.

Workflow Logic:

  1. First request → Get offset from response.
  2. Next request → Add ?offset=NEXT_OFFSET.

🛠 3. Real-World Use Cases

Case 1: Automating CRM (HubSpot API)

  • Goal: Sync new leads to a Google Sheet.
  • Steps:
    1. HTTP Node → Fetch leads from HubSpot (GET /contacts).
    2. Google Sheets Node → Append data.

Case 2: Discord Bot with Custom API

  • Goal: Post weather updates to Discord.
  • Steps:
    1. HTTP Node → Fetch weather (OpenWeatherMap API).
    2. Function Node → Format message.
    3. HTTP Node → Send to Discord webhook.

Case 3: Error Handling & Retries

  • Use n8n’s Error Trigger to retry failed API calls.
  • Example: Retry 3 times if statusCode = 429 (rate-limited).

💡 Pro Tips

Use Environment Variables for API keys (e.g., {{ $env.OPENAI_KEY }}).
Test APIs in Postman first, then replicate in n8n.
Log Responses with a Function Node for debugging.


🔥 Final Thoughts

The HTTP Node is n8n’s Swiss Army knife for API interactions. By mastering authentication, data handling, and real-world workflows, you can automate almost anything!

What will you build next? 🤖

> Try it yourself: Clone example workflows from n8n’s official docs!


Got questions? Drop them below! 👇 #n8n #Automation #APIs

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다