Skip to main content

Download a Label File

Turn a Label identifier into a file on disk. The successful response is binary, not the JSON envelope every other operation returns.

What you'll build​

  • One request that asks for the Label as a PDF.
  • A binary write path that never touches a JSON parser.
  • A check that separates a ready file from one that is still being generated.

Prerequisites​

Step 1 — Download the bytes​

GET/api/v1/labels/{labelId}/download

format=1 asks for PDF. Omit format entirely to use the Account's configured label printing technology, which falls back to PDF.

curl -s -o label.pdf -w '%{http_code} %{content_type}\n' \
"${MAILHUB_API_BASE_URL}/api/v1/labels/${LABEL_ID}/download?format=1" \
-H "Authorization: Bearer ${MAILHUB_ACCESS_TOKEN}"

Response​

A 200 has no JSON envelope. The body is the file itself, and Content-Type is application/pdf or application/zpl:

GET /api/v1/labels/f6c7d8e9-0a1b-4c2d-8e3f-4a5b6c7d8e9f/download?format=1

HTTP/1.1 200 OK
Content-Type: application/pdf

%PDF-1.4 ...binary...

The snippets above download once and stop, so they carry no retry policy of their own. If yours asks again after a 202, take the interval from that response's Retry-After header rather than choosing one — it is the only retry hint the public contract declares. See Handling 202. The 202 a Label purchase returns is a different response and carries no such header.

Use this next​

Nothing. The bytes are the end of the workflow: hand them to your printer, storage, or fulfilment step.

Expected result​

label.pdf on disk, with the Label identifier still available for Cancel a Label if you need it.

Common outcomes​

StatusWhat it meansWhat to do
200The Label file was returned.Write the bytes. Do not parse them as JSON.
202The requested Label file is pending or still being generated.Keep the Label identifier, read the Retry-After header, wait at least that many seconds, then request the same download again. Keep the loop bounded — see Handling 202.
404The Label was not found, or the requested format has not been generated.Confirm the Label identifier, and whether you asked for a format that exists.
409Label generation conflicts with the current state.Inspect the response — see Label Errors.

Download Label is a file endpoint, so its failures do not share one JSON shape. Read the HTTP status and Content-Type before parsing anything as JSON:

StatusBody
400, 401The standard {success, data, errors} envelope — raised around the operation, before it can write a body of its own.
202, 503A flat error object: code, description, category, metadata.
404, 409, 500Either of the two above — the download and the surrounding pipeline can both answer these, so branch on the body you received. Check for a top-level code (flat) or success (envelope).
403No body at all — there is nothing to parse.

The operation's entry in the API Reference is authoritative for each status. See Binary download failures for the same split with the carrier cases spelled out.

Other formats​

1 is PDF. 2, 3, and 4 are ZPL at 300, 203, and 600 DPI, and all three share the one application/zpl media type — the format you asked for is what identifies the resolution, not the response. See Download a Label for the full treatment.

Next steps​