Skip to content

Get Order File

API Overview

Retrieves one of the shipment documents generated when an order was closed, as a Base64-encoded PDF. Decode the string to obtain the PDF file.

Order documents are produced asynchronously after Create & Close Order returns, so this endpoint waits a short while for the requested file to appear before giving up.

Request Information

  • Method: POST
  • Path: /api/order/get-order-file
  • 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
job_nostringYesThe job number of the order, as returned in Data.JobNo by Create & Close Order.
typestringYesWhich document to retrieve. One of CN35, CN38, CP84, CP87, ExportControlForm, CN31, StatementOfLodgment, CN33, ReceptacleManifest. Which of them exist depends on the order's route and carrier.

Request Body Example

json
{
    "job_no": "CN38SG24010001",
    "type": "CN35"
}

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": {
        "Base64": "JVBERi0xLjcKJeLjz9MKMyAwIG9iago8PAovRmlsdGVyIC9GbGF0ZURlY29kZQ..."
    }
}

The Base64 value is truncated in this example. The real response contains the complete encoded PDF.

FieldTypeDescription
Data.Base64stringThe requested document 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": "Order 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/order/get-order-file" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d '{"job_no":"CN38SG24010001","type":"CN35"}'

Windows PowerShell

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

$body = @{
    job_no = "CN38SG24010001"
    type   = "CN35"
} | ConvertTo-Json

# The server may hold the request open while the document is still being generated
$response = Invoke-RestMethod -Uri "$BASE_URL/api/order/get-order-file" -Method Post `
    -ContentType "application/json" -Body $body -Headers @{Authorization = "Bearer $TOKEN"} `
    -TimeoutSec 90

[IO.File]::WriteAllBytes("CN35.pdf", [Convert]::FromBase64String($response.Data.Base64))

Python

python
import base64
import requests

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

# The server may hold the request open while the document is still being generated
resp = requests.post(f"{BASE_URL}/api/order/get-order-file", json={
    "job_no": "CN38SG24010001",
    "type": "CN35",
}, headers={"Authorization": f"Bearer {TOKEN}"}, timeout=90)
payload = resp.json()

with open("CN35.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";

// The server may hold the request open while the document is still being generated
const res = await fetch(`${BASE_URL}/api/order/get-order-file`, {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Authorization": `Bearer ${TOKEN}`,
  },
  body: JSON.stringify({job_no: "CN38SG24010001", type: "CN35"}),
  signal: AbortSignal.timeout(90_000),
});
const payload = await res.json();

writeFileSync("CN35.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/order/get-order-file');
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([
    'job_no' => 'CN38SG24010001',
    'type'   => 'CN35',
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// The server may hold the request open while the document is still being generated
curl_setopt($ch, CURLOPT_TIMEOUT, 90);
$response = curl_exec($ch);
curl_close($ch);

$payload = json_decode($response, true);
file_put_contents('CN35.pdf', base64_decode($payload['Data']['Base64']));
?>

Notes

  • This call can block for roughly half a minute. If the document is not ready yet, the server polls internally for up to about 25–30 seconds before returning The file is being generated. Please try again later. Set your client timeout above that, and retry after a short pause rather than immediately.
  • CN23 is a parcel label, not an order document, and is rejected here. Use Get Shipping Label PDF instead.
  • Not every document type exists for every order — the available set depends on the order's route and carrier. Requesting a type that is valid but not applicable to that order returns Type of file not found. (note the trailing period), whereas an unrecognised type name returns Type of file not found without one.
  • type is matched exactly, including capitalisation: send ExportControlForm, not exportcontrolform.
  • Only orders belonging to the authenticated account can be retrieved; another account's job_no is reported as Order not found!.
  • All parameters are case-sensitive.

Error Codes

codemessageDescription
1Type of file not foundtype is not one of the recognised document names.
1Order not found!No order with that job_no exists in your account.
1Type of file not found.The document type is recognised but is not produced for this order.
1The file is being generated. Please try again laterThe document had not finished generating within the server's wait window. Retry after a short pause.
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.