Labels
What’s different
Section titled “What’s different”| Parcel Monkey | Parcel2Go | |
|---|---|---|
| Where | label_url returned by CreateShipment |
GET /api/labels/{reference} after the order is paid, or document links from the order |
| When | Up to 30 minutes. Poll label_url at most every 5 minutes. It returns 404 until ready (503 on v3.0). |
After payment. See Timing. |
| Format | One label document | PDF or PNG, A4 or 4×6, all in one or one per order line |
| Auth | Signed URL | Bearer token, plus the order or order line hash with client credentials |
Get labels
Section titled “Get labels”Call GET /api/labels/{reference} with:
| Parameter | Values | Notes |
|---|---|---|
reference |
An OrderId or OrderLineId |
In the path |
referenceType |
OrderId, OrderLineId |
Which kind of reference you passed |
detailLevel |
All, Labels, AdditionalDocuments, Instructions, CommercialInvoice |
CommercialInvoice replaces Parcel Monkey’s customs doc_type |
labelMedia |
A4, Label4X6 |
Page size |
labelFormat |
PDF, PNG |
File type |
hash |
Hash from the create-order response |
Required with client credentials. Use the order hash for an OrderId, and the order line hash for an OrderLineId. |
curl -G -X GET "https://sandbox.parcel2go.com/api/labels/115030194" \ -H "Authorization: Bearer $P2G_TOKEN" \ -H "Accept: application/json" \ --data-urlencode 'referenceType=OrderLineId' \ --data-urlencode 'detailLevel=Labels' \ --data-urlencode 'labelMedia=Label4X6' \ --data-urlencode 'labelFormat=PDF' \ --data-urlencode 'hash=<order line hash>'<?php// $p2g is the client from the Authentication page$labels = $p2g->request('GET', '/api/labels/115030194', null, [ 'referenceType' => 'OrderLineId', 'detailLevel' => 'Labels', 'labelMedia' => 'Label4X6', 'labelFormat' => 'PDF', 'hash' => '<order line hash>',]);{ "SuccessfulLabels": 1, "FailedLabels": 0, "Base64EncodedLabels": [ "JVBERi0xLjcKJ..." ]}Each entry is a base64-encoded PDF or PNG. Decode it and save or print it.
Save the decoded file:
<?phpfile_put_contents('label-115030194.pdf', base64_decode($labels['Base64EncodedLabels'][0]));One file per order line
Section titled “One file per order line”GET /api/labels/{reference}/separate takes the same parameters and returns one file per order line, with its courier tracking numbers. Use it when you print or store labels per shipment.
curl -G -X GET "https://sandbox.parcel2go.com/api/labels/76423942/separate" \ -H "Authorization: Bearer $P2G_TOKEN" \ -H "Accept: application/json" \ --data-urlencode 'referenceType=OrderId' \ --data-urlencode 'detailLevel=All' \ --data-urlencode 'labelMedia=A4' \ --data-urlencode 'labelFormat=PDF' \ --data-urlencode 'hash=<order hash>'<?php// $p2g is the client from the Authentication page$labels = $p2g->request('GET', '/api/labels/76423942/separate', null, [ 'referenceType' => 'OrderId', 'detailLevel' => 'All', 'labelMedia' => 'A4', 'labelFormat' => 'PDF', 'hash' => '<order hash>',]);{ "SuccessfulLabels": 1, "FailedLabels": 0, "Items": [ { "OrderLineId": 115030194, "Base64EncodedLabel": "JVBERi0xLjcKJ...", "CourierTrackingNumbers": [ "<courier tracking number>" ] } ]}Document links
Section titled “Document links”After payment, Links objects can include public document URLs that you fetch with a plain GET, with no token. They include labels-a4, labels-4x6, labels-a4-4x6 (PDF), invoice, picking-list, and for print-in-store services barcode-printinstore (PNG). Which links you get depends on the order. See Parcel2Go’s links object guide.
Timing
Section titled “Timing”Parcel Monkey labels could take up to 30 minutes. With Parcel2Go, request labels after a successful payment. The labels endpoints can return 408 RequestTimeout: if you get one, wait and retry with a backoff, not in a tight loop.
paywithprepay succeeds? If not, what retry interval should customers use?
Check FailedLabels in the response. If it’s above 0, some labels weren’t generated. Retry, and log the order line IDs if it keeps failing.