Nhận webhookPorter chủ động báo sự kiện tới máy chủ của bạn bằng `POST` JSON — chi tiết từng sự kiện ở mục [Webhooks](/docs/api/webhooks). | Header | Ý nghĩa | |---|---| | `X-Porter-Event` | Loại sự kiện, ví dụ `ticket.updated` | | `X-Porter-Event-Id` | Mã sự kiện, dùng để chống xử lý trùng | | `X-Porter-Timestamp` | Thời điểm ký, Unix giây | | `X-Porter-Signature` | `sha256=` + HMAC-SHA256(secret, `<timestamp>.<body>`) | **Kiểm chữ ký** trước khi tin dữ liệu, và từ chối request có timestamp quá cũ (ví dụ > 5 phút): ```python import hashlib, hmac def verify(secret: str, timestamp: str, body: bytes, signature: str) -> bool: expected = "sha256=" + hmac.new(secret.encode(), timestamp.encode() + b"." + body, hashlib.sha256).hexdigest() return hmac.compare_digest(expected, signature) ``` ```javascript import crypto from "node:crypto"; function verify(secret, timestamp, rawBody, signature) { const expected = "sha256=" + crypto.createHmac("sha256", secret).update(`${timestamp}.${rawBody}`).digest("hex"); return crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(signature)); } ``` Trả mã `2xx` trong 10 giây là xong. Lỗi hoặc quá thời gian thì Porter gửi lại, giãn dần, tối đa 8 lần; sau đó sự kiện được đánh dấu hỏng và ban quản lý được báo. Webhook lỗi vẫn kéo được dữ liệu bằng API polling.TrướcGiới hạnTiếpPhiên bản