WebHook

View as Markdown
# BizMail API 1.0 — Webhook Tracking --- ## 🇬🇧 English ### Overview BizMail automatically pushes real-time email delivery events to your webhook URL configured in the **BizMail Portal**. When an email changes status (delivered, bounced, dropped), BizMail sends an HTTP `POST` request to your endpoint with a JSON payload describing the event. --- ### Configuration Configure your webhook URL and which events to receive in the **BizMail Portal** under your account settings. You can register separate webhook URLs per event type. --- ### Events | Event | Description | |-------|-------------| | `delivered` | Email was successfully delivered to the recipient's inbox | | `bounced` | Email bounced — can be hard bounce (invalid address) or soft bounce (temporary server rejection) | | `dropped` | Email was dropped by the server | --- ### Payload Structure BizMail sends different payload shapes depending on the event type. --- #### Event: `delivered` Triggered when an email is successfully delivered. ```json { "event": "delivered", "id": "550e8400-e29b-41d4-a716-446655440000@bizfly.vn", "recipient": "user@example.com", "time": 1713100000, "mxHostname": "mx.example.com", "response": "250 OK" } ``` | Field | Type | Description | |-------|------|-------------| | event | string | Always `delivered` | | id | string | `message_id` of the original email | | recipient | string | Recipient email address | | time | integer | Delivery timestamp (Unix ms) | | mxHostname | string | MX server that accepted the email | | response | string | SMTP response from the receiving server | --- #### Event: `bounced` Triggered when an email bounces. Includes a `category` field to distinguish hard and soft bounce. ```json { "event": "bounce", "id": "550e8400-e29b-41d4-a716-446655440000@bizfly.vn", "to": "user@example.com", "time": 1713100000, "response": "550 5.1.1 The email account does not exist", "category": "hard_bounce", "user": "", "seq": "", "returnPath": "" } ``` | Field | Type | Description | |-------|------|-------------| | event | string | Always `bounce` | | id | string | `message_id` of the original email | | to | string | Recipient email address | | time | integer | Event timestamp (Unix ms) | | response | string | SMTP error response | | category | string | `hard_bounce` (permanent, e.g. invalid address) or `soft_bounce` (temporary, e.g. mailbox full) | | user | string | Reserved | | seq | string | Reserved | | returnPath | string | Return path header | **Category values:** | Value | Trigger condition | Description | |-------|-------------------|-------------| | `hard_bounce` | `REJECTED` | Permanent failure — invalid address or domain | | `soft_bounce` | `DEFERRED` | Temporary failure — server busy or mailbox full | --- #### Event: `dropped` Triggered when an email is dropped (suppressed before sending). ```json { "action": "drop", "id": "550e8400-e29b-41d4-a716-446655440000@bizfly.vn", "recipient": "user@example.com", "reason": "Suppressed address", "user": "", "seq": "" } ``` | Field | Type | Description | |-------|------|-------------| | action | string | Always `drop` | | id | string | `message_id` of the original email | | recipient | string | Recipient email address | | reason | string | Reason the email was dropped | | user | string | Reserved | | seq | string | Reserved | --- ### Webhook Request Details BizMail sends events as HTTP `POST` requests to your configured URL. **Headers:** ``` Content-Type: application/json ``` **Your endpoint must respond with HTTP `2xx`** to acknowledge receipt. If your endpoint does not respond or returns a non-2xx status, BizMail may retry the delivery. --- ### Example Receiver (PHP) ```php $payload = file_get_contents('php://input'); $data = json_decode($payload, true); switch ($data['event'] ?? $data['action'] ?? '') { case 'delivered': // handle delivered break; case 'bounce': $category = $data['category']; // hard_bounce or soft_bounce // handle bounce break; case 'drop': // handle dropped break; } http_response_code(200); ``` --- ### Example Receiver (Node.js / Express) ```js app.post('/webhook/bizmail', (req, res) => { const data = req.body; const event = data.event || data.action; switch (event) { case 'delivered': // handle delivered break; case 'bounce': const category = data.category; // hard_bounce or soft_bounce // handle bounce break; case 'drop': // handle dropped break; } res.sendStatus(200); }); ``` --- --- ## 🇻🇳 Tiếng Việt ### Tổng quan BizMail tự động đẩy các sự kiện tracking email theo thời gian thực đến webhook URL được cấu hình trong **BizMail Portal**. Khi email thay đổi trạng thái (delivered, bounced, dropped), BizMail gửi HTTP `POST` request đến endpoint của bạn kèm JSON payload mô tả sự kiện. --- ### Cấu hình Cấu hình webhook URL và các sự kiện cần nhận trong **BizMail Portal** tại phần cài đặt tài khoản. Bạn có thể đăng ký webhook URL riêng cho từng loại sự kiện. --- ### Các sự kiện | Sự kiện | Mô tả | |---------|-------| | `delivered` | Email đã được gửi thành công vào hộp thư của người nhận | | `bounced` | Email bị bounce — có thể là hard bounce (địa chỉ không tồn tại) hoặc soft bounce (server từ chối tạm thời) | | `dropped` | Email bị hủy trước khi gửi | --- ### Cấu trúc Payload BizMail gửi payload có cấu trúc khác nhau tùy theo loại sự kiện. --- #### Sự kiện: `delivered` Kích hoạt khi email được gửi thành công. ```json { "event": "delivered", "id": "550e8400-e29b-41d4-a716-446655440000@bizfly.vn", "recipient": "user@example.com", "time": 1713100000, "mxHostname": "mx.example.com", "response": "250 OK" } ``` | Trường | Kiểu | Mô tả | |--------|------|-------| | event | string | Luôn là `delivered` | | id | string | `message_id` của email gốc | | recipient | string | Địa chỉ email người nhận | | time | integer | Timestamp gửi thành công (Unix ms) | | mxHostname | string | MX server đã nhận email | | response | string | Phản hồi SMTP từ server nhận | --- #### Sự kiện: `bounced` Kích hoạt khi email bị bounce. Có trường `category` phân biệt hard/soft bounce. ```json { "event": "bounce", "id": "550e8400-e29b-41d4-a716-446655440000@bizfly.vn", "to": "user@example.com", "time": 1713100000, "response": "550 5.1.1 The email account does not exist", "category": "hard_bounce", "user": "", "seq": "", "returnPath": "" } ``` | Trường | Kiểu | Mô tả | |--------|------|-------| | event | string | Luôn là `bounce` | | id | string | `message_id` của email gốc | | to | string | Địa chỉ email người nhận | | time | integer | Timestamp sự kiện (Unix ms) | | response | string | Thông báo lỗi SMTP | | category | string | `hard_bounce` (lỗi vĩnh viễn) hoặc `soft_bounce` (lỗi tạm thời) | | user | string | Dự phòng | | seq | string | Dự phòng | | returnPath | string | Header return path | **Giá trị category:** | Giá trị | Điều kiện | Mô tả | |---------|-----------|-------| | `hard_bounce` | `REJECTED` | Lỗi vĩnh viễn — địa chỉ hoặc domain không tồn tại | | `soft_bounce` | `DEFERRED` | Lỗi tạm thời — server bận hoặc hộp thư đầy | --- #### Sự kiện: `dropped` Kích hoạt khi email bị hủy (bị chặn trước khi gửi). ```json { "action": "drop", "id": "550e8400-e29b-41d4-a716-446655440000@bizfly.vn", "recipient": "user@example.com", "reason": "Suppressed address", "user": "", "seq": "" } ``` | Trường | Kiểu | Mô tả | |--------|------|-------| | action | string | Luôn là `drop` | | id | string | `message_id` của email gốc | | recipient | string | Địa chỉ email người nhận | | reason | string | Lý do email bị hủy | | user | string | Dự phòng | | seq | string | Dự phòng | --- ### Chi tiết Webhook Request BizMail gửi sự kiện qua HTTP `POST` đến URL đã cấu hình. **Headers:** ``` Content-Type: application/json ``` **Endpoint của bạn phải trả về HTTP `2xx`** để xác nhận nhận được. Nếu không phản hồi hoặc trả về non-2xx, BizMail có thể thử gửi lại. --- ### Ví dụ nhận webhook (PHP) ```php $payload = file_get_contents('php://input'); $data = json_decode($payload, true); switch ($data['event'] ?? $data['action'] ?? '') { case 'delivered': // xử lý delivered break; case 'bounce': $category = $data['category']; // hard_bounce hoặc soft_bounce // xử lý bounce break; case 'drop': // xử lý dropped break; } http_response_code(200); ``` --- ### Ví dụ nhận webhook (Node.js / Express) ```js app.post('/webhook/bizmail', (req, res) => { const data = req.body; const event = data.event || data.action; switch (event) { case 'delivered': // xử lý delivered break; case 'bounce': const category = data.category; // hard_bounce hoặc soft_bounce // xử lý bounce break; case 'drop': // xử lý dropped break; } res.sendStatus(200); }); ```

Request

This endpoint expects a multipart form.

Response headers

x-powered-bystring
etagstring
front-end-httpsstring
strict-transport-securitystring

Response

OK
codeinteger
statusstring
message_idstringformat: "email"

Errors

400
Bad Request Error