Skip to content

Get Shipping Label ZPL

API Overview

Generates the CN23 shipping label for a parcel and returns it as ZPL, ready to send straight to a Zebra-compatible thermal printer.

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-zpl
  • Authentication: Bearer Token

Request Headers

FieldDescription
Content-Typeapplication/json
AuthorizationBearer <token>

Request Parameters

The request body is in JSON format and includes the following fields:

ParameterTypeRequiredDescription
BarcodestringYesThe WMG tracking number of the parcel, maximum 50 characters.
LabelTypestringYesLabel type. Currently only CN23 is available. Maximum 10 characters.
OriginstringYesOriginating country as a 2-letter code, e.g. SG for Singapore, TW for Taiwan.
DestinationstringYesDestination country as a 2-letter code, e.g. TW for Taiwan, JP for Japan.

Request Body Example

json
{
    "Barcode": "CY180000662SG",
    "LabelType": "CN23",
    "Origin": "SG",
    "Destination": "JP"
}

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

FieldTypeDescription
Codeinteger0 = success; non-zero = failure
MessagestringHuman-readable result
DataobjectPayload; empty array [] on failure

Success Response

  • Status Code: 200
json
{
    "Code": 0,
    "Message": "Success",
    "Data": {
        "Zpl": "^XA^GFA,7200,7200,90,:Z64:eJzt3D1v2zAQBuC..."
    }
}

The Zpl value is truncated in this example. The real response contains the complete ZPL command stream.

FieldTypeDescription
Data.ZplstringThe CN23 label as a ZPL command stream. Send it to the printer as-is.

Error Response

  • Status Code: 200 (business logic error) or 4xx/5xx (system error)
json
{
    "Code": 1,
    "Message": "Parcel not found",
    "Data": []
}

Code Reference

CodeDescription
0Success
1Failure

Example

Bash

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

curl -X POST "$BASE_URL/api/create-label-zpl" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d '{"Barcode":"CY180000662SG","LabelType":"CN23","Origin":"SG","Destination":"JP"}'

Windows PowerShell

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

$body = @{
    Barcode     = "CY180000662SG"
    LabelType   = "CN23"
    Origin      = "SG"
    Destination = "JP"
} | ConvertTo-Json

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

# Write the raw ZPL out for the printer (no trailing newline, no BOM)
[IO.File]::WriteAllText("label.zpl", $response.Data.Zpl)

Python

python
import requests

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

resp = requests.post(f"{BASE_URL}/api/create-label-zpl", json={
    "Barcode": "CY180000662SG",
    "LabelType": "CN23",
    "Origin": "SG",
    "Destination": "JP",
}, headers={"Authorization": f"Bearer {TOKEN}"}, timeout=30)
payload = resp.json()

# Write the raw ZPL out for the printer
with open("label.zpl", "w", encoding="utf-8", newline="") as fh:
    fh.write(payload["Data"]["Zpl"])

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-zpl`, {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Authorization": `Bearer ${TOKEN}`,
  },
  body: JSON.stringify({
    Barcode: "CY180000662SG",
    LabelType: "CN23",
    Origin: "SG",
    Destination: "JP",
  }),
});
const payload = await res.json();

// Write the raw ZPL out for the printer
writeFileSync("label.zpl", payload.Data.Zpl, "utf8");

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-zpl');
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',
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$response = curl_exec($ch);
curl_close($ch);

$payload = json_decode($response, true);

// Write the raw ZPL out for the printer
file_put_contents('label.zpl', $payload['Data']['Zpl']);
?>

Notes

  • Barcode must be the WMG tracking number, not your own reference.
  • Barcode is normalised to upper case before matching. Origin and Destination are matched exactly as sent, so send them in upper case.
  • The ZPL is produced by rendering the PDF label and converting it to a raster image embedded in a ZPL command stream. Every condition that applies to Get Shipping Label PDF therefore applies here too.
  • Because of that conversion step, this is the slowest of the three label endpoints — allow a generous client timeout.
  • The label is always rendered in the default orientation; this endpoint has no Direction parameter.
  • 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.
  • LabelType is validated for length but does not change the generated label. Send CN23.
  • All other parameters are case-sensitive.

Error Codes

codemessageDescription
1Parcel not foundNo parcel in your account matches the supplied Barcode, Origin and Destination.
1The package cannot undergo this operationThe parcel ships under a self-label service, so WMG does not generate its label.
1Barcode requireBarcode is missing or empty.
1max size of Barcode must be 50Barcode is longer than 50 characters.
1LabelType requireLabelType is missing or empty.
1max size of LabelType must be 10LabelType is longer than 10 characters.
1Origin requireOrigin is missing or empty.
1max size of Origin must be 2Origin is longer than 2 characters.
1Destination requireDestination is missing or empty.
1max size of Destination must be 2Destination is longer than 2 characters.
1Error encountered, please contact tech@wmg-group.com with screenshot of error page for resolution.Unexpected server error.
1003Token errorThe token is missing, expired, or superseded by a newer login. Call Get Token again.