Skip to content

Webhook & HTTP Request

Mục tiêu bài học

Sau bài học này, bạn sẽ:

  • Thành thạo node Webhook để nhận dữ liệu từ bên ngoài
  • Thành thạo node HTTP Request để gọi API (REST, GraphQL)
  • Hiểu về các loại Authentication (Basic, Header, OAuth2)

1. Webhook Node (Trigger)

Webhook là cách phổ biến nhất để kích hoạt workflow từ bên ngoài.

External App ──(POST)──▶ [ Webhook Node ] ──▶ Workflow

Cấu hình cơ bản

  • HTTP Method: POST (nhận data) hoặc GET.
  • Path: Đường dẫn URL (VD: /webhook/my-hook).
  • Authentication: None, Basic Auth, hoặc Header Auth.

Test vs Production URL

URLĐịnh dạngKhi nào dùng?
Test/webhook-test/...Khi đang mở Editor (Execute Workflow).
Production/webhook/...Khi workflow đã Active (Chạy ngầm).

2. HTTP Request Node (Action)

Giúp n8n giao tiếp với các dịch vụ bên ngoài.

Các thông số quan trọng

  • Method: GET, POST, PUT, DELETE.
  • URL: Địa chỉ API.
  • Authentication: Chọn Credential.
  • Send Body: Dữ liệu gửi đi (JSON).

Authentication (Xác thực)

  1. Predefined: Có sẵn (Google, Slack...).
  2. Generic:
    • Header Auth: Authorization: Bearer [token]
    • Basic Auth: username:password

3. Ví dụ: Gọi API GitHub

Lấy thông tin user từ GitHub API.

json
{
  "nodes": [
    {
      "parameters": {
        "url": "https://api.github.com/user",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "githubApi"
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1
    }
  ]
}

Tổng kết

Webhook và HTTP Request là cặp bài trùng mạnh mẽ nhất. Webhook giúp n8n "nghe", còn HTTP Request giúp n8n "nói".

Bài học tiếp theo

Chúng ta sẽ học cách lên lịch chạy tự động với Schedule và Cron.

Schedule & Cron

Internal documentation for iNET Portal