Get Shipping Label PDF
API Overview
Generates the CN23 shipping label for a parcel and returns it as a Base64-encoded PDF. Decode the string to obtain the PDF file.
The parcel must already exist and must be identified by its WMG tracking number — obtain it from Get Tracking No if you only hold your own reference.
Request Information
- Method: POST
- Path:
/api/create-label - Authentication: Bearer Token
Request Headers
| Field | Description |
|---|---|
| Content-Type | application/json |
| Authorization | Bearer <token> |
Request Parameters
The request body is in JSON format and includes the following fields:
| Parameter | Type | Required | Description |
|---|---|---|---|
| Barcode | string | Yes | The WMG tracking number of the parcel, maximum 50 characters. |
| LabelType | string | Yes | Label type. Currently only CN23 is available. Maximum 10 characters. |
| Origin | string | Yes | Originating country as a 2-letter code, e.g. SG for Singapore, TW for Taiwan. |
| Destination | string | Yes | Destination country as a 2-letter code, e.g. TW for Taiwan, JP for Japan. |
| Direction | string | No | Page orientation: horizontal or vertical. Defaults to horizontal. |
Request Body Example
json
{
"Barcode": "CY180000662SG",
"LabelType": "CN23",
"Origin": "SG",
"Destination": "JP",
"Direction": "horizontal"
}Authentication
This endpoint uses Bearer token authentication.
Obtain a token from Get Token and send it as Authorization: Bearer <Token>.
Response Information
The response is in JSON format.
Response Format
| Field | Type | Description |
|---|---|---|
| Code | integer | 0 = success; non-zero = failure |
| Message | string | Human-readable result |
| Data | object | Payload; empty array [] on failure |
Success Response
- Status Code: 200
json
{
"Code": 0,
"Message": "Success",
"Data": {
"Base64": "JVBERi0xLjcKJeLjz9MKMyAwIG9iago8PAovRmlsdGVyIC9GbGF0ZURlY29kZQ..."
}
}The
Base64value is truncated in this example. The real response contains the complete encoded PDF.
| Field | Type | Description |
|---|---|---|
| Data.Base64 | string | The CN23 label as a Base64-encoded PDF. Decode it to obtain the PDF file. |
Error Response
- Status Code: 200 (business logic error) or 4xx/5xx (system error)
json
{
"Code": 1,
"Message": "Parcel not found",
"Data": []
}Code Reference
| Code | Description |
|---|---|
| 0 | Success |
| 1 | Failure |
Example
Bash
bash
BASE_URL="https://api.postal.test.wmgdelivery.com"
TOKEN="your_access_token"
curl -X POST "$BASE_URL/api/create-label" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{"Barcode":"CY180000662SG","LabelType":"CN23","Origin":"SG","Destination":"JP","Direction":"horizontal"}'Windows PowerShell
powershell
$BASE_URL = "https://api.postal.test.wmgdelivery.com"
$TOKEN = "your_access_token"
$body = @{
Barcode = "CY180000662SG"
LabelType = "CN23"
Origin = "SG"
Destination = "JP"
Direction = "horizontal"
} | ConvertTo-Json
$response = Invoke-RestMethod -Uri "$BASE_URL/api/create-label" -Method Post `
-ContentType "application/json" -Body $body -Headers @{Authorization = "Bearer $TOKEN"}
# Decode the Base64 payload into a PDF file
[IO.File]::WriteAllBytes("label.pdf", [Convert]::FromBase64String($response.Data.Base64))Python
python
import base64
import requests
BASE_URL = "https://api.postal.test.wmgdelivery.com"
TOKEN = "your_access_token"
resp = requests.post(f"{BASE_URL}/api/create-label", json={
"Barcode": "CY180000662SG",
"LabelType": "CN23",
"Origin": "SG",
"Destination": "JP",
"Direction": "horizontal",
}, headers={"Authorization": f"Bearer {TOKEN}"}, timeout=30)
payload = resp.json()
# Decode the Base64 payload into a PDF file
with open("label.pdf", "wb") as fh:
fh.write(base64.b64decode(payload["Data"]["Base64"]))Node.js / TypeScript
typescript
import {writeFileSync} from "node:fs";
const BASE_URL = "https://api.postal.test.wmgdelivery.com";
const TOKEN = "your_access_token";
const res = await fetch(`${BASE_URL}/api/create-label`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${TOKEN}`,
},
body: JSON.stringify({
Barcode: "CY180000662SG",
LabelType: "CN23",
Origin: "SG",
Destination: "JP",
Direction: "horizontal",
}),
});
const payload = await res.json();
// Decode the Base64 payload into a PDF file
writeFileSync("label.pdf", Buffer.from(payload.Data.Base64, "base64"));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/create-label');
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([
'Barcode' => 'CY180000662SG',
'LabelType' => 'CN23',
'Origin' => 'SG',
'Destination' => 'JP',
'Direction' => 'horizontal',
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$response = curl_exec($ch);
curl_close($ch);
$payload = json_decode($response, true);
// Decode the Base64 payload into a PDF file
file_put_contents('label.pdf', base64_decode($payload['Data']['Base64']));
?>Notes
Barcodemust be the WMG tracking number, not your own reference. This differs from Get Tracking No, whereBarcodeis your own number.Barcodeis normalised to upper case before matching.OriginandDestinationare matched exactly as sent, so send them in upper case.Directionaccepts onlyhorizontalorvertical. Any other value fails withCode: 1and the generic error message rather than a field-specific one.- Generating a label records a label event against the parcel, so it becomes visible in the parcel's tracking history.
- Parcels shipped under a self-label service cannot be labelled through this endpoint and return
The package cannot undergo this operation. - Label rendering is heavier than a plain lookup — allow a generous client timeout.
LabelTypeis validated for length but does not change the generated label. SendCN23.- All other parameters are case-sensitive.
Error Codes
| code | message | Description |
|---|---|---|
1 | Parcel not found | No parcel in your account matches the supplied Barcode, Origin and Destination. |
1 | The package cannot undergo this operation | The parcel ships under a self-label service, so WMG does not generate its label. |
1 | Barcode require | Barcode is missing or empty. |
1 | max size of Barcode must be 50 | Barcode is longer than 50 characters. |
1 | LabelType require | LabelType is missing or empty. |
1 | max size of LabelType must be 10 | LabelType is longer than 10 characters. |
1 | Origin require | Origin is missing or empty. |
1 | max size of Origin must be 2 | Origin is longer than 2 characters. |
1 | Destination require | Destination is missing or empty. |
1 | max size of Destination must be 2 | Destination is longer than 2 characters. |
1 | Error encountered, please contact tech@wmg-group.com with screenshot of error page for resolution. | Unexpected server error, including an invalid Direction value. |
1003 | Token error | The token is missing, expired, or superseded by a newer login. Call Get Token again. |