Vận chuyển

Kết nối hãng vận chuyển

Tạo mới một carrier: kết nối tài khoản hãng vận chuyển của shop

Endpoint

POST /v1/shippingcarriers

Quyền: setting.sale

Shop tự kết nối tài khoản hãng vận chuyển của mình bằng cách tạo carrier với api_type và thông tin kết nối (api_setting) tương ứng. Với GHN có thể tạo carrier rồi kết nối bằng OTP thay vì dán token.

Request Body

TrườngKiểuBắt buộcMô tả
company_idintCóID công ty
creator_idintCóID người tạo
namestringCóTên hiển thị
api_typeintKhôngLoại hãng (xem Shipping Carrier Object). Không truyền hoặc 1 = không tích hợp API
api_settingobjectKhôngThông tin kết nối theo hãng (xem các trường api_setting)
descriptionstringKhôngMô tả
statusintKhông1 (Bật), 3 (Tắt)
display_orderintKhôngThứ tự hiển thị

Response Schema

HTTP 201 - JSON Object

Shipping Carrier Object vừa tạo. Các trường bí mật trong api_setting được che bằng "********".

Error Codes

Mã lỗiMô tả
error_name_requiredThiếu tên (HTTP 422)
error_api_type_not_invalidapi_type không hợp lệ (HTTP 422)
error_api_type_not_availableLoại hãng đang ẩn, không cho tạo mới (HTTP 422)
error_quota_limit_exceedVượt hạn mức số carrier của công ty (HTTP 422)
error_role_not_availableKhông có quyền setting.sale (HTTP 403)
error_addLỗi hệ thống khi lưu (HTTP 500)

Ví dụ: kết nối GHN bằng token

curl -X POST "https://api.hubport.vn/v1/shippingcarriers" \
  -H "Authorization: <JWT>" \
  -H "Content-Type: application/json" \
  -d '{
    "company_id": 1001,
    "creator_id": 5,
    "name": "GHN - Kho Hà Nội",
    "api_type": 19,
    "status": 1,
    "api_setting": {
      "is_sandbox": 0,
      "connect_mode": "token",
      "token": "<GHN_API_TOKEN>",
      "shop_id": 885123,
      "service_type_id": 0,
      "payment_type_id": 1,
      "sender_name": "Shop Demo",
      "sender_phone": "0900000000",
      "sender_address": "12 Phố Huế",
      "sender_province": 1,
      "sender_district": 7
    }
  }'

Ví dụ: kết nối ViettelPost

{
  "company_id": 1001,
  "creator_id": 5,
  "name": "ViettelPost",
  "api_type": 15,
  "status": 1,
  "api_setting": {
    "is_sandbox": 0,
    "api_key": "<TÊN_ĐĂNG_NHẬP_VIETTELPOST>",
    "api_secret": "<MẬT_KHẨU_VIETTELPOST>",
    "service_code": "<MÃ_DỊCH_VỤ_VTP>",
    "sender_name": "Shop Demo",
    "sender_phone": "0900000000",
    "sender_address": "12 Phố Huế",
    "sender_province": 1,
    "sender_district": 7,
    "sender_ward": 0
  }
}

On this page