Môi trường sandbox và fixtures

Đối tượng: tích hợp triển khai với https://api.hiobuy.com (Workers gateway) — cùng base URL như production.

Auth: fixtures xác định chỉ áp dụng cho khóa API có tiền tố hio_test_* (key_type: test). Khóa production hio_live_* không bao giờ dùng quy tắc trang này — luôn gọi upstream marketplace / kho bình thường.

Tài liệu liên quan: Authentication · Response format · Errors · Rate limits · Products · Orders · Fulfillment · Webhooks

Quan trọng: kiểm thử Warehouse Fulfillment

Sandbox API (hio_test_*) dùng cho kiểm thử tích hợp dựa trên mock và fixture.

Nếu HIOBuy đã cấp cho ứng dụng của bạn WH-DEV Warehouse Developer Code, đừng dùng Sandbox API key để kiểm thử cấu hình kho được gán.

Hãy dùng:

Production API Key (hio_live_*) + WH-DEV

WH-DEV vẫn là cấu hình kho thử nghiệm. Dùng Production API key với WH-DEV không có nghĩa ứng dụng đang thực hiện fulfillment kho thật.

Cấu hìnhMục đích
hio_test_*Kiểm thử API mock / fixture
hio_live_* + WH-DEVKiểm thử tích hợp kho được gán với dữ liệu kho thử
hio_live_* + ủy quyền kho productionFulfillment kho thật

Các endpoint Sandbox Fulfillment trả về dữ liệu định sẵn hoặc mô phỏng. Ví dụ: địa điểm kho, số dư, gói hàng, tuyến vận chuyển và trạng thái sandbox có thể khác cấu hình WH-DEV được gán cho ứng dụng.

Khi xác thực tích hợp WH-DEV, luôn dùng Production API key.

Phạm vi Public API (tóm tắt)

Khu vựcSandbox
Toàn cụcresponse_format: upstream bị từ chối (chỉ standard). Trường currency trong body bị từ chối như prod. sandbox_trigger được phép với khóa test (fixtures nền tảng). Channel OAuth coi như đã ủy quyền cho hio_test_*. Bỏ qua quota & rate limits với khóa test.
/v1/products/*Search, detail, parse, upload-image, search-by-image, freight estimate, batch-check, analytics 1688 được mock như mô tả bên dưới. Mở rộng chỉ OpenAPI ngoài bộ handoff của site không mock.
/v1/orders/*Preview, create, detail, pay, cancel, logistics trace, list, purchase query được mock với magic / dynamic id.
/v1/fulfillment/*Balance, quotes, shipments, inbounds, packages, unclaimed, returns, locations, VAS, service-requests, finance được mock với magic / dynamic id (xem bên dưới).
/v1/support/ticketsList/detail/reply được mock với fixtures tkt_*.
WebhooksTài nguyên sandbox không tự gửi webhooks. Dùng portal Send test (livemode: false) để kiểm tra receiver và chữ ký.

Mục tiêu thiết kế

Mục tiêuÝ nghĩa
Lặp lại đượcCùng request → cùng response (không ngẫu nhiên kết quả).
Có tài liệuMỗi kịch bản có id hoặc keyword ổn định để grep trên trang này.
Khớp hợp đồngJSON khớp trường schema standard từ production; giá trị khác.
Happy path mặc địnhId không biết fallback mock thành công chung.
Lỗi rõ ràngDùng id sb_* hoặc sandbox_trigger để ép lỗi / trạng thái biên.

Đặt tên: sb_{domain}_{scenario}

Phân đoạnQuy tắcVí dụ
Tiền tốLuôn sb_sb_prod_not_found
domainDanh từ chữ thường (prod, search, ord, shp, pkg, plat, …)
scenariosnake_casenot_found, pay_declined

Ký tự: [a-z0-9_], độ dài ≤ ~48. Không thêm tiền tố sb_ cho id upstream thật trừ khi muốn fixture. Một số tài nguyên fulfillment cũng dùng id ổn định không phải sb_ (ret_*, ucp_*, svc_*, tkt_*, inv_*).

Hai lớp lỗi

Phân biệt lỗi transport/APItrạng thái nghiệp vụ HTTP 200:

  • Lỗi API → HTTP 4xx/5xx + error.code (vd. NOT_FOUND, PAYMENT_DECLINED).
  • HTTP 200 có trạng thái → vd. variants[].stock = 0, status: wait_payment.

Fixtures sản phẩm (tổng quan)

POST /v1/products/detail

Xem Product detail. Định dạng upstream không hỗ trợ trong sandbox.

Kích hoạt khi id, product_id, url đã parse, mi_id hoặc tao_password resolve thành id sb_*.

Fixture idKết quảHTTP
(mọi id không phải sb_)Sản phẩm mock chuẩn200
sb_prod_not_foundNOT_FOUND404
sb_prod_offlinePRODUCT_UNAVAILABLE422
sb_prod_no_stockDetail ok, stock: 0200
curl https://api.hiobuy.com/v1/products/detail \
  -H "Authorization: Bearer hio_test_..." \
  -H "Content-Type: application/json" \
  -d '{"channel":"1688","product_id":"sb_prod_not_found","language":"en"}'

POST /v1/products/search

Áp dụng channel, keyword, page, page_size, language. Bộ lọc 1688 filter / sort / giá chấp nhận nhưng bỏ qua cho hàng mock.

keyword (khớp chính xác)Kết quả
văn bản thườngDanh sách mock có kết quả
sb_search_emptyitems: [], total: 0
sb_search_not_foundAlias của rỗng

Parse / upload-image / search-by-image / freight / analytics

EndpointGhi chú sandbox
Parse URLQuery/path URL chứa sb_* phản chiếu hành vi detail.
Upload imageLuôn { "image_id": "img_sandbox_mock" } sau khi validation pass.
Image searchkeyword: sb_search_empty tùy chọn cho danh sách rỗng; kết hợp upload-image cho test luồng.
Advanced — freight estimateMock cước nội địa mặc định 800 minor units khớp preview.
Advanced — batch-checkTrả envelope kiểu upstream với mock mpProducts; dùng sb_prod_not_found trong mi_id/item_id cho danh sách loại trừ.
Advanced — top keywords/list / daily-sales-trendDùng sb_search_empty trên category_id / rank_id nơi có tài liệu để danh sách rỗng hoặc 404 detail.

Fixtures đơn hàng & thanh toán (magic id)

POST /v1/orders/detail

order_idstatus điển hìnhGhi chú
sb_ord_unpaidwait_payment
sb_ord_paidwait_shipment
sb_ord_shippedwait_receive
sb_ord_completedcompleted
sb_ord_cancelledcancelled
sb_ord_refundingwait_shipment (refund_status in progress)
sb_ord_not_found404

POST /v1/orders/pay

order_idKết quảHTTP
sb_ord_unpaidThanh toán thành công → trạng thái paid logic200
sb_ord_pay_declinedPAYMENT_DECLINED402
sb_ord_pay_insufficientPAYMENT_INSUFFICIENT_FUNDS402
sb_ord_paidORDER_ALREADY_PAID409
sb_ord_cancelledORDER_CANCELLED409
sb_ord_upstream_timeoutCHANNEL_UPSTREAM_ERROR502

Preview / create

Preview trả tổng minh họa cố định (dòng mẫu ~4500 + cước ~800 minor units). Create phát order_id động tiền tố sbo_* lưu trong sandbox storage — dòng tham chiếu offer_id: sb_prod_offline / sb_prod_no_stock trả 422 như production.

Cancel / logistics / list / purchase query

Theo cancel, trace, detail list: sb_ord_* chưa thanh toán và sbo_* động chưa thanh toán hủy được; fixtures paid/shipped/v.v. trả ORDER_NOT_CANCELLABLE. Logistics trả packages cho mock sb_ord_shipped / completed; unpaid/paid-await-shipment trả packages: []. Danh sách người mua tôn trọng product_name: sb_ord_list_empty cho mock rỗng. Purchase query trả upstream envelopes; bỏ qua pseudo id not-found tương ứng.

Fixtures fulfillment

Lưu ý: các fixture bên dưới chỉ dành cho kiểm thử Sandbox API. Chúng không đại diện cho cấu hình WH-DEV của ứng dụng. Để kiểm thử WH-DEV, hãy dùng Production API key (hio_live_*).

Tất cả endpoint bên dưới yêu cầu khóa hio_test_*. Id động từ create (pkg_*, sbs_*, sbi_*, …) được lưu trong sandbox storage theo khóa.

Balance · quotes · locations · VAS catalog

EndpointGhi chú sandbox
GET /v1/fulfillment/balanceMock số dư khả dụng 500000 CNY minor units.
POST /v1/fulfillment/shipping/quotesCần destination.country_code + trọng lượng hoặc kích thước; legacy …/shipments/freight/estimate vẫn hoạt động.
GET /v1/fulfillment/locationsloc_wh_001 (Weihai), loc_sz_001 (Shenzhen, paused), loc_yw_001 (Yiwu).
GET /v1/fulfillment/value-added-servicesBảng giá CODE ổn định; LEGACY_PHOTO_PRINT là INACTIVE → không khả dụng khi yêu cầu.

Shipments

Live warehouse Public id is the numeric PK as a string (e.g. "115"); order_sn is the warehouse order number. Sandbox create returns sbs_*; fixtures below use sb_shp_*.

Fixture / idBehavior
sb_shp_unpaidList + detail PENDING; intercept → SHIPMENT_NOT_INTERCEPTABLE
sb_shp_shippedShipped detail: split boxes, first/last-mile legs, packing files; plus international tracking events. Intercept → REQUESTED
sb_shp_not_foundDetail 404
sb_shp_pay_insufficientPOST …/shipments/sb_shp_pay_insufficient/payINSUFFICIENT_BALANCE
sb_shp_not_cancellableCancel → SHIPMENT_NOT_CANCELLABLE; intercept is allowed (WAIT_SHIP)
sb_shp_signedSigned; intercept → SHIPMENT_NOT_INTERCEPTABLE
sb_shp_interceptedDetail SHIPPED + interception.status: INTERCEPTED; intercept again → SHIPMENT_INTERCEPTION_ALREADY_REQUESTED
Dynamic sbs_*Create / pay / list / detail / cancel / intercept against sandbox storage
sb_parcel_not_foundCreate → 422 PARCEL_NOT_FOUND

List path: GET /v1/fulfillment/shipments. Tracking path: GET /v1/fulfillment/shipments/{id}/tracking (language query).

Inbounds (create / cancel)

Create trả package_id động (pkg_*) — khônginbound_id riêng.

Trigger valueFieldHTTPerror.code
sb_inbound_shippedtracking_number409INBOUND_TRACKING_ALREADY_SHIPPED
sb_inbound_existstracking_number409INBOUND_TRACKING_ALREADY_EXISTS
sb_inbound_bad_trackingtracking_number422INVALID_TRACKING_NUMBER
sb_inbound_external_existsexternal_order_id409EXTERNAL_ORDER_ID_ALREADY_EXISTS
sb_vas_missingservices[].service_code422VALUE_ADDED_SERVICE_NOT_FOUND
sb_vas_unavailableservices[].service_code422VALUE_ADDED_SERVICE_UNAVAILABLE
sb_vas_outboundservices[].service_code422VALUE_ADDED_SERVICE_INVALID_STAGE
Cancel idHTTPerror.code
Dynamic sbi_* (after create)200Đã hủy; package liên quan bị loại
Same sbi_* again409INBOUND_NOT_EDITABLE
sb_inb_not_found404INBOUND_NOT_FOUND
sb_inb_received409INBOUND_ALREADY_RECEIVED
sb_inb_shipped / sb_inb_consolidated / sb_inb_cancelled409INBOUND_NOT_EDITABLE

Packages · tracking · list

package_idDetail / tracking
Dynamic pkg_*PENDING; tracking bắt đầu tại INBOUND_CREATED
sb_pkg_pendingPENDING
sb_pkg_receivedRECEIVED + timeline PHOTO
sb_pkg_exceptionRECEIVED + condition.EXCEPTION
sb_pkg_shippedSHIPPED timeline outbound đầy đủ
sb_pkg_not_found404 PACKAGE_NOT_FOUND

Unclaimed packages

Id / triggerHành vi
ucp_01K2ABCDEF1234567890Có thể claim; tracking thật SF123456789012 (list bị che)
ucp_01K2ABCDEF9876543210Có thể claim; YT738800001148
sb_ucp_not_found404 UNCLAIMED_PACKAGE_NOT_FOUND
sb_ucp_already_claimed409 PACKAGE_ALREADY_CLAIMED
sb_ucp_not_claimable409 PACKAGE_NOT_CLAIMABLE
Wrong tracking ×5 trên cùng ucp429 CLAIM_ATTEMPTS_EXCEEDED

Returns

IdHành vi
ret_pending_001PENDING; fee=18; confirm thành công
ret_pending_002PENDING; fee=20; confirm với 18 → RETURN_FEE_CHANGED
ret_returned_001RETURNED + tracking
ret_cancelled_001CANCELLED
sb_ret_not_found404 RETURN_NOT_FOUND
sb_ret_fee_not_readyConfirm → RETURN_FEE_NOT_READY
sb_ret_insufficientConfirm → INSUFFICIENT_BALANCE
Create trên sb_pkg_shipped409 PACKAGE_NOT_RETURNABLE

Service requests

IdHành vi
svc_photo_completedPHOTO COMPLETED + images
svc_inspection_failedBASIC_INSPECTION FAILED
svc_video_processingVIDEO PROCESSING
svc_reinforce_pendingPACKAGE_REINFORCEMENT PENDING
svc_wooden_awaitingWOODEN_FRAME chờ xác nhận
sb_svc_not_found404
sb_svc_fee_not_ready / sb_svc_insufficientConfirm edge cases

Finance (transactions / invoices)

FixtureGhi chú
txn_01K2ABC001006TOP_UP / VAS / RETURN / SHIPPING / REFUND / STORAGE
inv_01K2ABC001ISSUED (tải được)
inv_01K2ABC002PENDING
inv_01K2ABC003REJECTED

Xem Fulfillment finance.

Fixtures support ticket

Fixture idKịch bản
tkt_01K2ABCDEF1234567890PACKAGE · NORMAL · WAITING_FOR_HIOBUY
tkt_01K2ABCDEF9876543210RETURN · URGENT · WAITING_FOR_CUSTOMER
tkt_01K2ABCDEFAPIRESOLVEDAPI · NORMAL · RESOLVED
tkt_01K2ABCDEFSHIPCLOSEDSHIPMENT · NORMAL · CLOSED (không có replies)
tkt_not_found404 TICKET_NOT_FOUND

Xem Support tickets.

Trigger nền tảng: sandbox_trigger

Chỉ cho phép trên hio_test_*; khóa production im lặng bỏ qua trường.

sandbox_triggerHTTPerror.code
sb_plat_quota_exceeded429QUOTA_EXCEEDED
sb_plat_rate_limited429RATE_LIMIT_EXCEEDED
sb_plat_upstream_error502CHANNEL_UPSTREAM_ERROR

Kết hợp với id vô hại để body thực tế vẫn validate:

{
  "channel": "1688",
  "product_id": "123456",
  "language": "en",
  "sandbox_trigger": "sb_plat_quota_exceeded"
}

Fixture auth đặc biệt sb_auth_channel_required kết hợp trigger có thể tạo CHANNEL_AUTH_REQUIRED (403) cho hồi quy UI dù quy tắc «authorized by default».

Ảnh chụp trạng thái triển khai

Giai đoạnPhạm viGhi chú
ShippedProducts, procurement orders, fulfillment (balance/quotes/shipments/inbounds/packages/unclaimed/returns/locations/VAS/service-requests/finance), support ticketsPhản ánh tập con Public API trên site này.
Not yetWebhooks sandbox tự phát; mở rộng catalogue OpenAPI-only chưa công bốƯu tiên portal Send test cho webhook CI; đừng giả định mọi live event đã bật cho đến khi thông báo.

Bảng gian lận sao chép nhanh

sb_prod_not_found          → 404 product missing
sb_prod_offline            → 422 unavailable
sb_prod_no_stock           → 200 detail with zero stock

sb_search_empty            → empty search/items
sb_ord_list_empty          → empty buyer order list filter
img_sandbox_mock           → stable upload-image id

sb_ord_unpaid              → detail wait_payment • pay succeeds • cancel ok
sb_ord_pay_declined        → pay 402 PAYMENT_DECLINED
sb_ord_paid                → pay 409 ALREADY_PAID • trace maybe empty until shipped fixtures
sb_ord_shipped             → detail wait_receive • trace populated
sb_ord_cancelled           → cancelled state • pay conflicts

sb_shp_unpaid / sb_shp_shipped / sb_shp_signed / sb_shp_intercepted → shipment list / detail / intercept
sb_pkg_received / sb_pkg_shipped → package detail / fulfillment timeline
sb_inbound_exists          → inbound create 409 tracking exists
ret_pending_001            → return confirm happy path
ucp_01K2ABCDEF1234567890   → unclaimed claimable
svc_photo_completed        → VAS request completed
tkt_01K2ABCDEF1234567890   → support ticket open

sb_plat_quota_exceeded     → sandbox_trigger → 429 QUOTA_EXCEEDED

Khi thêm fixtures nội bộ, phản ánh sơ đồ đánh số này trong test hồi quy — không bao giờ thay đổi hình dạng JSON standard trong mock.

Get Support

Need integration help? Contact Developer Support at support@hiobuy.com · Response within 1–2 business days

Email support