Skip to content

创建并关闭订单

接口概述

用已登记的包裹创建一张运输订单(CN38),把包裹分装进袋 / AKE / 托盘,并在同一次调用中关闭该订单。关闭会触发运输单据的生成,之后用 获取订单文件 取回。

本接口引用的每个包裹都必须已存在、属于你的账号,且尚未被其他订单占用。

请求信息

  • Method: POST
  • Path: /api/order/create-order
  • Authentication: Bearer Token

请求头

字段说明
Content-Typeapplication/json
AuthorizationBearer <token>

请求参数

请求体为 JSON 格式,包含以下字段:

参数类型必填说明
ship_typeinteger装载类型:1 = 袋(Bag),2 = AKE,3 = 托盘(Pallet)。
ship_routeinteger运输路线:1 = Direct CN,2 = Master2CN,3 = Master2CN(T2T),4 = Master2CN(OA),5 = Transshipment CN,6 = Transshipment CN(AF),7 = Transshipment CN(VP)。
is_ddpstring清关模式:Y = DDP,N = DDU。默认 N。必须与订单内每个包裹的清关模式一致。
destinationstring目的国家,2 位国家代码,如 SG 表示新加坡、TH 表示泰国。必须正好 2 个字符。
departure_portstring起运港代码。必须正好 3 个字符。
destination_portstring目的港代码。必须正好 3 个字符。
outbound_flight_nostring出港航班号。最长 60 个字符。
estimated_departure_datetimestring起运地预计出发当地时间,10 位 UNIX 秒级时间戳。
estimated_arrival_datetimestring目的地预计到达当地时间,10 位 UNIX 秒级时间戳。必须晚于 estimated_departure_datetime
shipment_servicestring条件必填当目的地有可选服务时必填:TP = Tracked Packet,EM = EMS。目的地没有可选服务时该字段被忽略。
ship_type_detailsarray装载单元数组。每个元素是该袋 / AKE / 托盘内所装 WMG 运单号的数组,且不能为空。
order_mawbobject条件必填MAWB 信息。当 ship_route234 时必填。
order_mawb.mawb_nostring条件必填MAWB 号。最长 60 个字符。
order_mawb.departure_airportstring条件必填出发机场代码。必须正好 3 个字符。
order_mawb.arrival_airportstring条件必填到达机场代码。必须正好 3 个字符。
order_mawb.outbound_flight_nostring条件必填MAWB 上的航班号。最长 60 个字符。
order_mawb.estimated_departure_datetimestring条件必填预计出发时间,10 位 UNIX 秒级时间戳。
order_mawb.estimated_arrival_datetimestring条件必填预计到达时间,10 位 UNIX 秒级时间戳。必须晚于 order_mawb.estimated_departure_datetime

请求体示例

Direct CN 路线——无需 MAWB,两个装载单元:

json
{
  "ship_type": 1,
  "ship_route": 1,
  "is_ddp": "N",
  "departure_port": "SIN",
  "destination_port": "PHS",
  "outbound_flight_no": "SQ918",
  "estimated_departure_datetime": "1784115300",
  "estimated_arrival_datetime": "1784128800",
  "destination": "PH",
  "shipment_service": "TP",
  "ship_type_details": [
    [
      "TES00123456TP",
      "TES00123457TP"
    ],
    [
      "TES00123458TP"
    ]
  ]
}

Master2CN 路线——order_mawb 必填:

json
{
  "ship_type": 3,
  "ship_route": 2,
  "is_ddp": "Y",
  "departure_port": "SIN",
  "destination_port": "TPE",
  "outbound_flight_no": "SQ876",
  "estimated_departure_datetime": "1784115300",
  "estimated_arrival_datetime": "1784128800",
  "destination": "TW",
  "order_mawb": {
    "mawb_no": "12123224",
    "departure_airport": "SIN",
    "arrival_airport": "TPE",
    "outbound_flight_no": "SQ876",
    "estimated_departure_datetime": "1784115300",
    "estimated_arrival_datetime": "1784128800"
  },
  "ship_type_details": [
    [
      "BX000000014CG",
      "BX000000028CG"
    ]
  ]
}

认证方式

本接口使用 Bearer Token 认证。

请先通过 获取 Token 取得 Token,并以 Authorization: Bearer <Token> 形式发送。

响应信息

响应为 JSON 格式。

响应格式

字段类型说明
Codeinteger0 表示成功;非 0 表示失败
Messagestring可读的结果说明
Dataobject业务数据;失败时为空数组 []

成功响应

  • Status Code: 200
json
{
    "Code": 0,
    "Message": "Success",
    "Data": {
        "JobNo": "CN38SG24010001"
    }
}
字段类型说明
Data.JobNostring新建订单的 Job No。在 获取订单文件 中作为 job_no 使用。

错误响应

  • Status Code: 200(业务逻辑错误)或 4xx/5xx(系统错误)
json
{
    "Code": 1,
    "Message": "WMG Tracking Num(TES00123456TP) not exists!",
    "Data": []
}

结果码

Code说明
0成功
1失败

示例

Bash

bash
BASE_URL="https://api.postal.test.wmgdelivery.com"
TOKEN="your_access_token"

curl -X POST "$BASE_URL/api/order/create-order" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d '{
    "ship_type": 1,
    "ship_route": 1,
    "is_ddp": "N",
    "departure_port": "SIN",
    "destination_port": "PHS",
    "outbound_flight_no": "SQ918",
    "estimated_departure_datetime": "1784115300",
    "estimated_arrival_datetime": "1784128800",
    "destination": "PH",
    "shipment_service": "TP",
    "ship_type_details": [["TES00123456TP", "TES00123457TP"]]
  }'

Windows PowerShell

powershell
$BASE_URL = "https://api.postal.test.wmgdelivery.com"
$TOKEN    = "your_access_token"

# @(, @(...)) 保证内层数组不被展平——只有一个内层数组时会被拉平
$body = @{
    ship_type                    = 1
    ship_route                   = 1
    is_ddp                       = "N"
    departure_port               = "SIN"
    destination_port             = "PHS"
    outbound_flight_no           = "SQ918"
    estimated_departure_datetime = "1784115300"
    estimated_arrival_datetime   = "1784128800"
    destination                  = "PH"
    shipment_service             = "TP"
    ship_type_details            = @(, @("TES00123456TP", "TES00123457TP"))
} | ConvertTo-Json -Depth 5

$response = Invoke-RestMethod -Uri "$BASE_URL/api/order/create-order" -Method Post `
    -ContentType "application/json" -Body $body -Headers @{Authorization = "Bearer $TOKEN"}
$response.Data.JobNo

Python

python
import requests

BASE_URL = "https://api.postal.test.wmgdelivery.com"
TOKEN    = "your_access_token"

resp = requests.post(f"{BASE_URL}/api/order/create-order", json={
    "ship_type": 1,
    "ship_route": 1,
    "is_ddp": "N",
    "departure_port": "SIN",
    "destination_port": "PHS",
    "outbound_flight_no": "SQ918",
    "estimated_departure_datetime": "1784115300",
    "estimated_arrival_datetime": "1784128800",
    "destination": "PH",
    "shipment_service": "TP",
    # 外层数组是装载单元,内层数组是该单元内的包裹
    "ship_type_details": [["TES00123456TP", "TES00123457TP"]],
}, headers={"Authorization": f"Bearer {TOKEN}"}, timeout=60)
print(resp.json())

Node.js / TypeScript

typescript
const BASE_URL = "https://api.postal.test.wmgdelivery.com";
const TOKEN = "your_access_token";

const res = await fetch(`${BASE_URL}/api/order/create-order`, {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Authorization": `Bearer ${TOKEN}`,
  },
  body: JSON.stringify({
    ship_type: 1,
    ship_route: 1,
    is_ddp: "N",
    departure_port: "SIN",
    destination_port: "PHS",
    outbound_flight_no: "SQ918",
    estimated_departure_datetime: "1784115300",
    estimated_arrival_datetime: "1784128800",
    destination: "PH",
    shipment_service: "TP",
    // 外层数组是装载单元,内层数组是该单元内的包裹
    ship_type_details: [["TES00123456TP", "TES00123457TP"]],
  }),
});
console.log(await res.json());

PHP

php
<?php
$BASE_URL = 'https://api.postal.test.wmgdelivery.com';
$TOKEN    = 'your_access_token';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $BASE_URL . '/api/order/create-order');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/json',
    'Authorization: Bearer ' . $TOKEN,
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
    'ship_type'                    => 1,
    'ship_route'                   => 1,
    'is_ddp'                       => 'N',
    'departure_port'               => 'SIN',
    'destination_port'             => 'PHS',
    'outbound_flight_no'           => 'SQ918',
    'estimated_departure_datetime' => '1784115300',
    'estimated_arrival_datetime'   => '1784128800',
    'destination'                  => 'PH',
    'shipment_service'             => 'TP',
    // 外层数组是装载单元,内层数组是该单元内的包裹
    'ship_type_details'            => [['TES00123456TP', 'TES00123457TP']],
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
$response = curl_exec($ch);
curl_close($ch);

echo json_encode(json_decode($response, true), JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n";
?>

注意事项

  • 本接口在一次调用中同时创建并关闭订单。 没有单独的关闭步骤,且订单关闭后无法通过 API 修改——发送前请核对好数据。
  • 运输单据不是立即生成的。请用 获取订单文件 取回,该接口会短暂等待生成完成。
  • ship_type_details数组的数组:外层是装载单元列表,每个内层数组是该单元内所装的 WMG 运单号。内层数组不能为空。
  • 单个订单最多包含 999 个包裹(所有装载单元合计)。
  • 同一个运单号不能在 ship_type_details 中出现两次,跨装载单元也不行。
  • 每个包裹必须同时满足以下条件,否则整个请求被拒绝:
    • 包裹存在且属于你的账号;
    • 尚未被其他订单占用——重复使用的包裹会返回 "scanned before in previous shipments" 那条消息,需要重新出 CN23 面单;
    • 清关模式与订单的 is_ddp 一致;
    • 目的地与订单的 destination 一致——但 Transshipment CN 和 Transshipment CN(AF) 两条路线会跳过这项检查;
    • 承运商与订单的承运商一致;
    • 尺寸类型与订单的装载尺寸一致;
    • 长宽高和重量在该服务与目的地的限制范围内。
  • order_mawb 只在 Master2CN 系列路线(ship_route234)下必填,其他路线可传但不强制。
  • 时间戳为 10 位 UNIX 秒级;示例中以字符串形式发送,与现有接入方的用法一致。
  • 本接口会完成订单构建、单据触发和关闭,比普通查询慢,客户端超时时间请设置得宽松一些。
  • 所有参数区分大小写。

错误码

codemessage说明
1ship_type requireship_type 缺失或为空。
1ship_type invalidship_type 不是 123
1ship_route requireship_route 缺失或为空。
1Ship Route Invalidship_route 不在 17 范围内。
1is_ddp must be in Y,Nis_ddp 既不是 Y 也不是 N
1destination requiredestination 缺失或为空。
1size of destination must be 2destination 不是正好 2 个字符。
1departure_port requiredeparture_port 缺失或为空。
1size of departure_port must be 3departure_port 不是正好 3 个字符。
1destination_port requiredestination_port 缺失或为空。
1size of destination_port must be 3destination_port 不是正好 3 个字符。
1outbound_flight_no requireoutbound_flight_no 缺失或为空。
1max size of outbound_flight_no must be 60outbound_flight_no 超过 60 个字符。
1estimated_departure_datetime requireestimated_departure_datetime 缺失或为空。
1estimated_departure_datetime must be a timestampestimated_departure_datetime 不是合法的 UNIX 时间戳。
1estimated_arrival_datetime requireestimated_arrival_datetime 缺失或为空。
1estimated_arrival_datetime must be a timestampestimated_arrival_datetime 不是合法的 UNIX 时间戳。
1estimated_arrival_datetime must be greater than 'estimated_departure_datetime'到达时间不晚于出发时间。
1shipment_service must be TP or EM目的地有可选服务,但 shipment_service 既不是 TP 也不是 EM
1ship_type_details requireship_type_details 缺失或为空。
1ship_type_details must be a arrayship_type_details 不是数组。
1ship_type_details must contain non-empty bagsship_type_details 中有装载单元为空或不是数组。
1bags requireship_type_details 解析后没有任何装载单元。
1bag item(1) must be array该位置的装载单元不是数组,括号内是从 1 开始的单元序号。
1bag item parcel(1) must be string装载单元内该位置的元素不是字符串,括号内是从 1 开始的元素序号。
1WMG Tracking Num(TES00123456TP) Duplicate!同一个运单号在所有装载单元中出现了多次。
1The number of items cannot exceed 999单个订单包裹数超过 999。
1WMG Tracking Num(TES00123456TP) not exists!你的账号下没有该包裹。
1Order clearance mode(DDP) is inconsistent with the parcel((TES00123456TP)) clearance mode(DDU)包裹的清关模式与订单的 is_ddp 不一致。
1Parcel(TES00123456TP) destination(TH) is inconsistent with order destination(PH)包裹目的地与订单 destination 不一致。
1Parcel(TES00123456TP) partner is inconsistent with order partner包裹承运商与订单承运商不一致。
1(TES00123456TP) The package size does not match the size set in the order包裹尺寸类型与订单装载尺寸不一致。
1(TES00123456TP)This parcel has been scanned before in previous shipments. Please generate a new CN23 label for this parcel and redo bagging scan.该包裹已属于其他订单。请重新生成 CN23 面单并重新装袋扫描。
1Parcel(TES00123456TP):包裹超出该服务与目的地的尺寸、长度或重量限制。冒号后的文本说明是哪一项限制。
1Error encountered, please contact tech@wmg-group.com with screenshot of error page for resolution.未预期的服务端错误。
1003Token errorToken 缺失、已过期或被新登录顶替。请重新调用 获取 Token

订单构建和承运商匹配失败会带着各自的消息文本返回 Code: 1。凡是无法识别的 Message,都应视为整个订单被拒绝——调用失败时不会创建任何数据。