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...

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 and ask again later, at a cadence your application chooses.
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.

400, 401, 403, and 500 follow the standard public error envelope — see Error Handling.

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