API cho đối tác
OpenAPI JSONTích hợp GB Cargo vào hệ thống của bạn: báo giá, tạo đơn, theo dõi, công nợ. Tiền luôn là số nguyên pence (GBP). Mã lỗi, trạng thái, scope không đổi theo ngôn ngữ.
Bắt đầu
- Liên hệ chúng tôi để được cấp khóa API (dạng gbk_...), có scope và đối tác riêng.
- Gửi khóa trong header
Authorization: Bearer gbk_.... Không đưa khóa vào mã nguồn công khai hay trình duyệt. - Thêm
?lang=vihoặc headerAccept-Language: viđể nhận thông báo tiếng Việt.
Kiểm tra khóa
curl https://cargo.gbglobal.trade/api/v1/me \ -H "Authorization: Bearer gbk_xxxxxxxx"
Báo giá
curl -X POST https://cargo.gbglobal.trade/api/v1/quotes \
-H "Authorization: Bearer gbk_xxxxxxxx" \
-H "Content-Type: application/json" \
-d '{"route":"UK_VN_HN","parcels":[{"kg":12.5,"l_cm":50,"w_cm":40,"h_cm":30}]}'
Tạo đơn (an toàn khi gửi lại)
curl -X POST https://cargo.gbglobal.trade/api/v1/orders \
-H "Authorization: Bearer gbk_xxxxxxxx" \
-H "Idempotency-Key: order-2026-0001" \
-H "Content-Type: application/json" \
-d '{"route":"UK_VN_HN","parcels":[...],"sender":{...},"receiver":{...},
"ack_prohibited":true,"external_ref":"PO-0001","confirm":true,"payment_method":"on_account"}'
Cùng Idempotency-Key và cùng nội dung: nhận lại kết quả lần đầu (48 giờ). Cùng khóa khác nội dung: lỗi 422.
Quyền (scope)
Mỗi khóa chỉ có các quyền được cấp. Thiếu quyền trả 403 insufficient_scope.
| Scope | Cho phép |
|---|---|
rates:read | Xem bảng giá |
quotes:write | Báo giá (không tạo đơn) |
tracking:read | Tra cứu vận đơn |
tracking:write | Cập nhật trạng thái (hãng VC) |
orders:read | Xem đơn của đối tác |
orders:write | Tạo/sửa/hủy/xác nhận đơn |
payments:read | Xem thanh toán |
payments:write | Báo đã thanh toán |
addresses:rw | Sổ địa chỉ |
ledger:read | Xem công nợ và sao kê |
webhooks:rw | Quản lý webhook |
batches:rw | Lô hàng |
Endpoints
System 2
| Phương thức | Đường dẫn | Mô tả | Scope |
|---|---|---|---|
| GET | /openapi.json | OpenAPI 3 document. Public copy omits admin/staff endpoints; send a valid Bearer key with an admin:/staff: scope for the full document | không cần |
| GET | /me | Describe the calling API key (scopes, partner, expiry, limits) | không cần |
Rates 1
| Phương thức | Đường dẫn | Mô tả | Scope |
|---|---|---|---|
| GET | /rates | Current published rates for all routes | rates:read |
Quotes 1
| Phương thức | Đường dẫn | Mô tả | Scope |
|---|---|---|---|
| POST | /quotes | Price a shipment (no order is created) | quotes:write |
Tracking 4
| Phương thức | Đường dẫn | Mô tả | Scope |
|---|---|---|---|
| GET | /tracking/{code} | Public tracking (6 milestones) for a GBT-... code | tracking:read |
| POST | /tracking/search | Look up up to 50 tracking codes at once | tracking:read |
| POST | /tracking/updates | Carrier pushes a status update (same rules as POST /api/v1/partner/status) | tracking:write |
| POST | /partner/status | LEGACY carrier status update (kept for existing integrations; prefer POST /tracking/updates) | tracking:write |
Orders 7
| Phương thức | Đường dẫn | Mô tả | Scope |
|---|---|---|---|
| POST | /orders | Create an order (optionally confirm it; on-account accounts are charged to the ledger) | orders:write |
| GET | /orders | List own orders (cursor pagination, limit <= 200; filters status, route, from, to, q) | orders:read |
| GET | /orders/{id} | Order detail by numeric id or code GBG-... | orders:read |
| PATCH | /orders/{id} | Edit a DRAFT order (partial update) | orders:write |
| DELETE | /orders/{id} | Delete a DRAFT order | orders:write |
| POST | /orders/{id}/confirm | Confirm a draft (on_account: ledger debit, blocked above credit limit) | orders:write |
| POST | /orders/{id}/cancel | Cancel an order that has not been received yet (ledger charges are credited back) | orders:write |
Payments 3
| Phương thức | Đường dẫn | Mô tả | Scope |
|---|---|---|---|
| GET | /orders/{id}/payments | Payments, amount outstanding and bank transfer details of an order | payments:read |
| POST | /orders/{id}/payments/report | Report that the bank transfer has been made | payments:write |
| POST | /orders/{id}/payments/card | Start a hosted card checkout; returns the URL to pay | payments:write |
Addresses 5
| Phương thức | Đường dẫn | Mô tả | Scope |
|---|---|---|---|
| GET | /addresses | List saved addresses | addresses:rw |
| POST | /addresses | Save an address | addresses:rw |
| GET | /addresses/{id} | Get an address | addresses:rw |
| PUT | /addresses/{id} | Update an address | addresses:rw |
| DELETE | /addresses/{id} | Delete an address | addresses:rw |
Ledger 2
| Phương thức | Đường dẫn | Mô tả | Scope |
|---|---|---|---|
| GET | /ledger | Own balance, credit limit and ageing (0-30 / 31-60 / 60+ days) | ledger:read |
| GET | /ledger/statement | Own statement (date filter, cursor; format=csv needs from+to) | ledger:read |
Batches 7
| Phương thức | Đường dẫn | Mô tả | Scope |
|---|---|---|---|
| GET | /batches | List batches (latest 100) | batches:rw |
| POST | /batches | Create a batch | batches:rw |
| GET | /batches/{id} | Batch with its orders | batches:rw |
| PATCH | /batches/{id} | Rename / change note | batches:rw |
| DELETE | /batches/{id} | Delete an EMPTY batch | batches:rw |
| POST | /batches/{id}/orders | Add orders by code (GBG-..., GBT-... or partner tracking) | batches:rw |
| POST | /batches/{id}/status | Move every order in the batch to a status (per-order result) | batches:rw |
Webhooks 9
| Phương thức | Đường dẫn | Mô tả | Scope |
|---|---|---|---|
| GET | /webhooks | List own webhook endpoints | webhooks:rw |
| POST | /webhooks | Register an https endpoint; the signing secret is shown once | webhooks:rw |
| GET | /webhooks/{id} | Endpoint detail | webhooks:rw |
| PATCH | /webhooks/{id} | Update url / events / name / active | webhooks:rw |
| DELETE | /webhooks/{id} | Delete an endpoint and its history | webhooks:rw |
| POST | /webhooks/{id}/rotate-secret | Issue a new signing secret (shown once) | webhooks:rw |
| POST | /webhooks/{id}/test | Queue a webhook.ping delivery | webhooks:rw |
| GET | /webhooks/{id}/deliveries | Delivery history (cursor) | webhooks:rw |
| POST | /webhooks/{id}/deliveries/{did}/redeliver | Send a past delivery again | webhooks:rw |
Chi tiết trường dữ liệu: xem OpenAPI JSON.
Webhook
Chúng tôi gửi POST JSON tới URL https của bạn. Xác thực header X-GB-Signature: t=<unix>,v1=<hex> = HMAC-SHA256(secret, t + "." + rawBody). Trả 2xx trong 10 giây, nếu không sẽ được gửi lại.
order.createdOrder confirmed/submitted. data: { order }order.status_changeddata: { order, from, to }order.cancelleddata: { order }payment.receiveddata: { order, payment }ledger.entrydata: { entry, balance_pence, credit_limit_pence }
Mã lỗi
Lỗi có dạng {"ok":false,"error":"code","message":"...","request_id":"..."}. Hãy xử lý theo error, không theo message.
| HTTP | Mã | Ý nghĩa |
|---|---|---|
| 400 | bad_amount | Số tiền không hợp lệ: phải là số dương (biểu mẫu web và CSV: bảng Anh, ví dụ 12.50; API: số nguyên pence, ví dụ 1250). |
| 400 | bad_credit_limit | Hạn mức không hợp lệ. |
| 400 | bad_cursor | Cursor không hợp lệ. |
| 400 | bad_date | Ngày không hợp lệ. Nhập dạng DD/MM/YYYY hoặc YYYY-MM-DD (API chỉ nhận YYYY-MM-DD). |
| 400 | bad_events | Sự kiện webhook không hợp lệ. |
| 400 | bad_expires_at | expires_at phải ở tương lai. |
| 400 | bad_idempotency_key | Idempotency-Key phải gồm 8-120 ký tự. |
| 400 | bad_ip_allowlist | Danh sách IP không hợp lệ. |
| 400 | bad_json | Nội dung không phải JSON hợp lệ. |
| 400 | bad_kind | Loại phải là nộp tiền (deposit) hoặc rút tiền (withdrawal). |
| 400 | bad_limit | limit phải là số nguyên từ 1 đến 200. |
| 400 | bad_payment_method | payment_method phải là on_account hoặc bank. |
| 400 | bad_prohibited | Mục hàng cấm không hợp lệ (cần nhãn VI và EN). |
| 400 | bad_request | Yêu cầu không hợp lệ. |
| 400 | bad_scopes | Danh sách scope không hợp lệ. |
| 400 | bad_status | Mã trạng thái không hợp lệ. |
| 400 | bad_surcharge | Phụ phí không hợp lệ. |
| 400 | bad_terms_days | terms_days phải từ 0 đến 365. |
| 400 | bad_webhook_url | URL webhook phải là https công khai. |
| 400 | idempotency_key_required | Bắt buộc có Idempotency-Key cho yêu cầu này. |
| 400 | invalid_occurred_at | occurred_at không hợp lệ. |
| 400 | invalid_status | Trạng thái không hợp lệ. |
| 400 | ip_allowlist_required | Khóa API admin/staff bắt buộc có danh sách IP cho phép (ip_allowlist). |
| 400 | name_required | Cần nhập tên. |
| 400 | note_required | Bút toán điều chỉnh bắt buộc có ghi chú. |
| 400 | too_many_codes | Tối đa 50 mã mỗi yêu cầu. |
| 400 | tracking_code_required | Cần có tracking_code. |
| 400 | unknown_route | Tuyến không hợp lệ. |
| 401 | api_key_expired | Khóa API đã hết hạn. |
| 401 | invalid_api_key | Thiếu hoặc sai khóa API. |
| 402 | credit_limit_exceeded | Đơn vượt hạn mức công nợ của tài khoản. |
| 403 | email_not_verified | Email tài khoản chủ đơn chưa xác minh. |
| 403 | insufficient_scope | Khóa API không có quyền (scope) cần thiết. |
| 403 | ip_not_allowed | IP không nằm trong danh sách cho phép của khóa. |
| 403 | partner_inactive | Tài khoản đối tác đã bị tắt. |
| 403 | partner_required | Khóa này chưa gắn với đối tác. |
| 404 | not_found | Không tìm thấy. |
| 404 | partner_not_found | Không thấy đối tác (hoặc đã tắt). |
| 404 | unknown_tracking_code | Mã tracking không tồn tại. |
| 409 | batch_not_empty | Lô vẫn còn đơn. |
| 409 | cannot_cancel | Đơn không còn hủy online được. |
| 409 | card_disabled | Chưa mở thanh toán thẻ. |
| 409 | conflict | Dữ liệu vừa được cập nhật ở nơi khác. |
| 409 | exists | Đã tồn tại. |
| 409 | idempotency_in_progress | Yêu cầu cùng Idempotency-Key đang được xử lý. |
| 409 | invalid_transition | Bước chuyển trạng thái không hợp lệ. |
| 409 | ledger_inactive | Tài khoản chưa bật ghi nợ. |
| 409 | no_balance_due | Không có chênh lệch cần thu. |
| 409 | not_editable | Đơn không thể sửa nữa. |
| 409 | not_payable | Khoản thanh toán không còn chờ. |
| 409 | not_payable_order | Đơn hiện không nhận thanh toán. |
| 409 | not_receivable | Đơn chưa ở kho. |
| 409 | nothing_due | Không còn khoản cần thanh toán. |
| 409 | order_not_payable | Đơn hiện không nhận thanh toán. |
| 409 | partner_has_no_account | Đối tác chưa có tài khoản; công nợ cần tài khoản. |
| 409 | partner_user_mismatch | Đơn thuộc tài khoản khác với đối tác này. |
| 409 | payment_required | Cần nhận đủ tiền trước. |
| 409 | too_many_addresses | Sổ địa chỉ đã đầy (50). |
| 409 | user_already_partner | Tài khoản đó đã là đối tác. |
| 409 | user_not_customer | Email đó là tài khoản nhân viên/admin. |
| 409 | webhook_limit_reached | Đã đủ 5 endpoint webhook cho mỗi đối tác. Hãy xóa bớt một cái. |
| 409 | weigh_required | Cần cân/đo thực trước. |
| 413 | export_too_large | File xuất vượt giới hạn số dòng; hãy chọn khoảng ngày ngắn hơn. |
| 422 | idempotency_key_reuse | Idempotency-Key đã dùng cho yêu cầu khác. |
| 422 | incomplete | Đơn chưa đủ thông tin. |
| 429 | rate_limited | Quá nhiều yêu cầu. |
| 500 | server_error | Lỗi hệ thống. |
| 502 | card_unavailable | Thanh toán thẻ đang không dùng được. |