Webhooks
Khi app ở chế độ HIOBuy warehouse fulfillment, HIOBuy đẩy sự kiện vòng đời fulfillment tới endpoint HTTPS của bạn. Cấu hình tại Developer Portal → Webhooks . Gửi bất đồng bộ; phản hồi Public API không chờ server webhook.
Điều kiện tiên quyết: Ủy quyền kênh → chế độ fulfillment = HIOBuy warehouse. Self chỉ xem intro; không tạo/bật Endpoint.
Tổng quan {#overview}
| Hạng mục | Giá trị |
|---|---|
| Vận chuyển | POST JSON tới endpoint của bạn |
| Timeout | 10 giây |
| Thành công | HTTP 2xx |
| Secret ký | whsec_… (chỉ hiện một lần khi tạo / xoay vòng) |
| Header chữ ký | HioBuy-Signature |
| Header ID sự kiện | HioBuy-Event-Id |
| User-Agent | HioBuy-Webhooks/1.0 |
| Retry | tối đa 5 lần: ngay, rồi 1m / 5m / 30m / 2h |
| Sự kiện test | Portal Send test → livemode: false, tiền tố id evt_test_ |
Đăng ký, xoay secret, lịch sử gửi và retry thủ công là chỉ portal (auth phiên). v1 không có Public /v1/webhooks/*.
Danh mục sự kiện {#events}
Đăng ký theo endpoint. Cần ≥ 1 sự kiện.
| Nhóm | Loại sự kiện | Khi nào |
|---|---|---|
| Mua hàng | procurement.failed | Mua hàng kho thất bại |
| Mua hàng | procurement.out_of_stock | SKU hết hàng khi mua |
| Kho | package.received | Kiện nội địa đã nhập kho |
| Kho | package.exception | Ngoại lệ nhập kho (data.exception_type) |
| Gom hàng | consolidation.completed | Gom hàng hoàn tất |
| Vận chuyển | shipment.created | Tạo vận đơn quốc tế |
| Vận chuyển | shipment.dispatched | Đã giao cho carrier |
| Vận chuyển | shipment.delivered | Đã giao người nhận |
| Vận chuyển | shipment.exception | Ngoại lệ xuất kho (data.exception_type) |
| Tài khoản | balance.low | Số dư ví kho dưới ngưỡng |
Push live warehouse→developer đang mở dần; hãy dùng Send test trên portal để kiểm tra receiver.
Envelope công khai {#envelope}
Mỗi body gửi là JSON:
{
"id": "evt_01HXYZ…",
"type": "package.received",
"created_at": "2026-08-16T04:00:00.000Z",
"livemode": true,
"app_id": "app_…",
"data": {
"package_id": "pkg_…",
"order_id": "ord_…",
"status": "received"
}
}| Trường | Kiểu | Mô tả |
|---|---|---|
id | string | ID sự kiện công khai (evt_… live, evt_test_… test) |
type | string | Loại trong catalog |
created_at | string | Timestamp ISO-8601 |
livemode | boolean | false với test portal |
app_id | string | App ID của bạn |
data | object | Payload sự kiện (không có trường nội bộ kho) |
Ví dụ data {#data-shapes}
Giống mẫu test portal; live dùng cùng khóa.
procurement.failed
{
"order_id": "ord_…",
"status": "failed",
"reason": "supplier_rejected"
}package.exception
{
"package_id": "pkg_…",
"order_id": "ord_…",
"status": "exception",
"exception_type": "DAMAGED"
}shipment.dispatched
{
"shipment_id": "shp_…",
"tracking_number": "…",
"status": "dispatched"
}balance.low
{
"available_amount": 12.5,
"currency": "USD",
"threshold": 50
}Gửi HTTP {#delivery}
POST /your/webhook-path HTTP/1.1
Host: your-server.example
Content-Type: application/json
User-Agent: HioBuy-Webhooks/1.0
HioBuy-Event-Id: evt_01HXYZ…
HioBuy-Signature: t=1723780800,v1=abcdef0123456789…- Production bắt buộc HTTPS. Ngoài production có thể dùng
http://localhost/ tunnel. - Trả
2xxtrong 10s. Mã khác hoặc lỗi mạng sẽ retry. - Gửi at-least-once. Dedup theo
id(và tùy chọnHioBuy-Event-Id).
Xác minh chữ ký {#signature}
- Đọc
HioBuy-Signature(t=<unix_seconds>,v1=<hex_hmac>). - Tạo chuỗi ký:
"{t}.{raw_body}",raw_bodylà body gốc nhận được (JSON UTF-8). - Tính
HMAC-SHA256(secret, signed_payload)rồi hex. - So sánh với
v1theo thời gian hằng. - Từ chối nếu
|now - t|quá lớn (dung sai khuyến nghị: 5 phút).
Node.js ví dụ
import crypto from "node:crypto";
function verifyHioBuySignature(rawBody, signatureHeader, secret, toleranceSec = 300) {
const match = /^t=(\d+),v1=([0-9a-f]+)$/i.exec(signatureHeader || "");
if (!match) return false;
const t = Number(match[1]);
const expected = match[2].toLowerCase();
if (!Number.isFinite(t)) return false;
if (Math.abs(Math.floor(Date.now() / 1000) - t) > toleranceSec) return false;
const signed = `${t}.${rawBody}`;
const digest = crypto
.createHmac("sha256", secret)
.update(signed, "utf8")
.digest("hex");
const a = Buffer.from(digest, "utf8");
const b = Buffer.from(expected, "utf8");
return a.length === b.length && crypto.timingSafeEqual(a, b);
}Chỉ lưu
whsec_…trên server. Portal hiện mask (6 ký tự cuối). Sau khi xoay, cập nhật server trước lần gửi tiếp theo.
Retry & trạng thái {#retries}
| Lần thử | Độ trễ sau lần thất bại trước |
|---|---|
| 1 | Ngay (vào queue) |
| 2 | 1 phút |
| 3 | 5 phút |
| 4 | 30 phút |
| 5 | 2 giờ |
Sau lần thất bại cuối: failed. Có thể Retry now trong chi tiết portal.
Trạng thái: pending · success · retrying · failed.
Quy trình portal {#portal}
- Đặt app sang warehouse fulfillment trong Channel Auth / setup.
- Mở Webhooks → Add endpoint.
- Nhập URL HTTPS, mô tả tùy chọn và sự kiện.
- Sao chép secret ngay khi hiện (một lần).
- Dùng Send test event và xem deliveries / attempts.
- Xoay secret, tắt hoặc xóa khi cần.
Giới hạn & lưu trữ {#limits}
| Giới hạn | Giá trị |
|---|---|
| Payload | ≤ 64 KB |
| body phản hồi lưu trong attempt | ≤ 4 KB |
| lưu events / deliveries | ~30 ngày |
| Attempt | ~14 ngày |
Liên quan
- Fulfillment setup — chế độ warehouse
- Fulfillment API — tuyến vận chuyển quốc tế
- Authentication — API keys (khác secret webhook)
- Sandbox — đơn sandbox không tự push; dùng Send test
Get Support
Need integration help? Contact Developer Support at support@hiobuy.com · Response within 1–2 business days