Webhooks
Tư vấn V2 cũng dùng giao thức này. App được bật quản lý ask.* không cần kho. Xem hướng dẫn Webhook V2 về chữ ký, cách ly và khôi phục.
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
| 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
Đă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.ready_for_payment | Đóng gói và tính phí hoàn tất; có thể thanh toán |
| 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
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
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.ready_for_payment
{
"shipment_id": "115",
"order_sn": "JIYUNRI1349",
"external_shipment_id": "MY-INTL-ORDER-001",
"previous_status": "PENDING",
"status": "WAIT_PAYMENT",
"amount_due": {
"amount": 10200,
"currency": "CNY"
},
"source_packages": [
{
"package_id": "pkg_…",
"external_order_id": "STORE-ORDER-10086"
}
],
"occurred_at": "2026-09-09T16:20:00.000Z"
}shipment.dispatched
{
"shipment_id": "shp_…",
"tracking_number": "…",
"status": "dispatched"
}balance.low
{
"available_amount": 12.5,
"currency": "USD",
"threshold": 50
}Gửi HTTP
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ý
- Đọ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
| 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
- Kho thực tế cần gói trả phí phù hợp còn hiệu lực, đơn vận hành đã duyệt và tài khoản production đã kích hoạt. HIOBuy quản lý thông tin nền tảng và liên kết kho. Làm theo hướng dẫn trong trung tâm; tích hợp mới không cần mã kho hoặc OAuth cá nhân.
- 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ữ
| 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)
Get Support
Need integration help? Contact Developer Support at support@hiobuy.com · Response within 1–2 business days