4 × 6 in
Shipping labels
Shipping label 4 × 6 in
A carrier-neutral 4 × 6 inch shipping label in high-contrast black and white for thermal printers. It has a large ship-to address, service level, weight, package count, a bold routing code, Code 128 barcodes for the tracking number and postal code, and a QR code with the shipment summary.
Opens Dynamic Document API with this template preloaded in a free workspace.
Template language features
- Loops
- Conditionals
- Macros
- Filters
- Barcode
- QR code
- Date formatting
- Number formatting
Filters such as format_currency and qrcode are described in the template language reference.
Variables
Derived from the sample data: 3 top-level fields, 37 paths in total. Send the same shape as data.
| Path | Type | Example |
|---|---|---|
| shipment | object | |
| shipment.tracking_number | string | "ND48273019665502" |
| shipment.service_level | string | "Ground" |
| shipment.service_code | string | "GND" |
| shipment.transit | string | "3–5 business days" |
| shipment.ship_date | date | "2026-09-17" |
| shipment.weight_lb | number | 12.4 |
| shipment.dimensions_in | object | |
| shipment.dimensions_in.length | number | 14 |
| shipment.dimensions_in.width | number | 10 |
| shipment.dimensions_in.height | number | 8 |
| shipment.package_number | number | 2 |
| shipment.package_count | number | 3 |
| shipment.routing_code | string | "AZ 860 9-07" |
| shipment.hub | string | "PHX-3" |
| shipment.reference | string | "SO-58213" |
| shipment.po_number | string | "7730-114" |
| shipment.billing | string | "Prepaid" |
| shipment.signature_required | boolean | true |
| shipment.locale | string | "en-US" |
| sender | object | |
| sender.name | string | "Driftwood Supply Co." |
| sender.attention | string | "Shipping Dept." |
| sender.address_lines | array<string> · 1 | "480 Harbor Industrial Way, Unit C" |
| sender.city | string | "Portland" |
| sender.state | string | "OR" |
| sender.postal_code | string | "97217" |
| sender.phone | string | "+1 202-555-0119" |
| recipient | object | |
| recipient.name | string | "Rosalind Achebe-Morrow" |
| recipient.company | string | "Tamarack Ceramics Studio" |
| recipient.address_lines | array<string> · 2 | "2215 W Juniper Ave" |
| recipient.city | string | "Flagstaff" |
| recipient.state | string | "AZ" |
| recipient.postal_code | string | "86001" |
| recipient.country | string | "United States" |
| recipient.phone | string | "+1 202-555-0182" |
Sample data
Fictional records used for previews. Replace them with your own data when you call the API.
{
"shipment": {
"tracking_number": "ND48273019665502",
"service_level": "Ground",
"service_code": "GND",
"transit": "3–5 business days",
"ship_date": "2026-09-17",
"weight_lb": 12.4,
"dimensions_in": { "length": 14, "width": 10, "height": 8 },
"package_number": 2,
"package_count": 3,
"routing_code": "AZ 860 9-07",
"hub": "PHX-3",
"reference": "SO-58213",
"po_number": "7730-114",
"billing": "Prepaid",
"signature_required": true,
"locale": "en-US"
},
"sender": {
"name": "Driftwood Supply Co.",
"attention": "Shipping Dept.",
"address_lines": ["480 Harbor Industrial Way, Unit C"],
"city": "Portland",
"state": "OR",
"postal_code": "97217",
"phone": "+1 202-555-0119"
},
"recipient": {
"name": "Rosalind Achebe-Morrow",
"company": "Tamarack Ceramics Studio",
"address_lines": ["2215 W Juniper Ave", "Suite 110"],
"city": "Flagstaff",
"state": "AZ",
"postal_code": "86001",
"country": "United States",
"phone": "+1 202-555-0182"
}
}Source
The body markup with Jinja, the stylesheet placed in <head>.
{#- Carrier-neutral 4 × 6 inch thermal shipping label, black on white. The tracking number is printed
in groups of four and as a Code 128 barcode, the ship-to postal code gets its own routing barcode,
and the QR code carries a compact summary of the shipment. -#}
{%- set locale = shipment.locale | default("en-US") -%}
{%- set tracking = shipment.tracking_number -%}
{%- set qr_payload = "ND1|" ~ tracking ~ "|" ~ recipient.postal_code ~ "|" ~ shipment.package_number ~ "/" ~ shipment.package_count ~ "|" ~ (shipment.weight_lb | format_number(locale, 1)) ~ "LB|" ~ shipment.service_code -%}
{%- macro grouped(value, size=4) -%}
{%- for start in range(0, value | length, size) -%}{{ value[start:start + size] }}{% if not loop.last %} {% endif %}{%- endfor -%}
{%- endmacro -%}
<div class="label">
<section class="top">
<div class="from">
<p class="tiny-label">From</p>
<p class="from-name">{{ sender.name }}</p>
{% if sender.attention %}<p>{{ sender.attention }}</p>{% endif %}
{% for line in sender.address_lines %}<p>{{ line }}</p>{% endfor %}
<p>{{ sender.city | upper }} {{ sender.state }} {{ sender.postal_code }}</p>
{% if sender.phone %}<p>{{ sender.phone }}</p>{% endif %}
</div>
<div class="service">
<div class="service-code">{{ shipment.service_code }}</div>
<p class="service-transit">{{ shipment.transit }}</p>
</div>
</section>
<section class="facts">
<div><span class="tiny-label">Ship date</span><strong>{{ shipment.ship_date | format_date("short", locale) }}</strong></div>
<div><span class="tiny-label">Weight</span><strong>{{ shipment.weight_lb | format_number(locale, 1) }} LB</strong></div>
<div><span class="tiny-label">Dims (in)</span><strong>{{ shipment.dimensions_in.length }}×{{ shipment.dimensions_in.width }}×{{ shipment.dimensions_in.height }}</strong></div>
<div class="pkg"><span class="tiny-label">Package</span><strong>{{ shipment.package_number }} of {{ shipment.package_count }}</strong></div>
</section>
<section class="ship-to">
<p class="ship-to-label">Ship<br>to</p>
<div class="ship-to-address">
<p class="to-name">{{ recipient.name | upper }}</p>
{% if recipient.company %}<p class="to-line">{{ recipient.company | upper }}</p>{% endif %}
{% for line in recipient.address_lines %}<p class="to-line">{{ line | upper }}</p>{% endfor %}
<p class="to-city">{{ recipient.city | upper }} {{ recipient.state }} {{ recipient.postal_code }}</p>
{% if recipient.phone %}<p class="to-phone">{{ recipient.phone }}</p>{% endif %}
</div>
</section>
<section class="routing">
<div class="routing-main">
<p class="routing-code">{{ shipment.routing_code }}</p>
<div class="postal-barcode">{{ ("420" ~ recipient.postal_code) | barcode("code128", alt="Routing barcode for postal code " ~ recipient.postal_code) }}</div>
<p class="postal-text">(420) {{ recipient.postal_code }}{% if shipment.hub %} · Hub {{ shipment.hub }}{% endif %}</p>
</div>
<div class="routing-qr">{{ qr_payload | qrcode(size=160, margin=0, ecc="M", alt="QR code with the shipment summary") }}</div>
</section>
<section class="service-bar">
<span class="service-name">{{ shipment.service_level | upper }}</span>
{% if shipment.signature_required %}<span class="flag">Signature required</span>{% endif %}
</section>
<section class="tracking">
<p class="tracking-label">Tracking <strong>{{ grouped(tracking) }}</strong></p>
<div class="tracking-barcode">{{ tracking | barcode("code128", alt="Tracking barcode " ~ tracking) }}</div>
</section>
<section class="refs">
<div><span class="tiny-label">Ref</span>{{ shipment.reference }}</div>
<div><span class="tiny-label">PO</span>{{ shipment.po_number }}</div>
<div><span class="tiny-label">Bill</span>{{ shipment.billing | upper }}</div>
</section>
</div><title>Shipping label {{ shipment.tracking_number }} – {{ recipient.name }}</title>
<style>
* { box-sizing: border-box; }
html { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
body {
margin: 0;
color: #000000;
font-family: "DejaVu Sans", "Liberation Sans", Arial, sans-serif;
font-size: 7pt;
line-height: 1.2;
}
p { margin: 0; }
.tiny-label { display: block; font-size: 5pt; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
/* 4 × 6 in page minus 0.15 in margins = 3.7 × 5.7 in; kept a hair shorter so it never spills onto a second label. */
.label {
display: flex; flex-direction: column; width: 3.7in; height: 5.66in; overflow: hidden;
border: 0.035in solid #000000;
}
.label > section { flex: none; overflow: hidden; }
.label > section + section { border-top: 0.035in solid #000000; }
.top { display: flex; height: 0.92in; }
.from { flex: 1; padding: 0.06in 0.08in; font-size: 6.5pt; line-height: 1.22; }
.from-name { font-weight: 700; font-size: 7pt; }
.service { display: flex; flex: none; flex-direction: column; align-items: center; justify-content: center; width: 1.1in; border-left: 0.035in solid #000000; }
.service-code {
width: 0.9in; padding: 0.05in 0; background: #000000; color: #ffffff; text-align: center;
font-size: 21pt; font-weight: 700; letter-spacing: 0.02em; line-height: 1.1;
}
.service-transit { margin-top: 0.04in; font-size: 5.5pt; font-weight: 700; text-transform: uppercase; }
.facts { display: grid; grid-template-columns: 0.95fr 0.9fr 0.95fr 0.8fr; height: 0.36in; }
.facts > div { padding: 0.04in 0.06in; }
.facts > div + div { border-left: 0.02in solid #000000; }
.facts strong { display: block; font-size: 8pt; white-space: nowrap; }
.facts .pkg { background: #000000; color: #ffffff; }
.label > .ship-to { display: flex; flex: 1 1 auto; padding: 0.08in 0.1in 0.06in 0; }
.ship-to-label {
flex: none; width: 0.42in; padding-top: 0.02in; text-align: center;
font-size: 8pt; font-weight: 700; line-height: 1.05; text-transform: uppercase;
}
.ship-to-address { flex: 1; }
.to-name { font-size: 12pt; font-weight: 700; line-height: 1.15; }
.to-line { font-size: 10pt; font-weight: 700; line-height: 1.2; }
.to-city { margin-top: 0.03in; font-size: 14pt; font-weight: 700; line-height: 1.15; }
.to-phone { margin-top: 0.03in; font-size: 7pt; }
.routing { display: flex; height: 1.05in; }
.routing-main { flex: 1; padding: 0.06in 0.1in; }
.routing-code { font-size: 21pt; font-weight: 700; line-height: 1.05; white-space: nowrap; }
.postal-barcode img { display: block; width: 2.2in; height: 0.36in; margin-top: 0.05in; }
.postal-text { margin-top: 0.02in; font-size: 6.5pt; font-weight: 700; }
.routing-qr { display: flex; flex: none; align-items: center; justify-content: center; width: 1.1in; border-left: 0.035in solid #000000; }
.routing-qr img { display: block; width: 0.92in; height: 0.92in; }
.service-bar {
display: flex; justify-content: space-between; align-items: center; height: 0.3in; padding: 0 0.1in;
background: #000000; color: #ffffff;
}
.service-name { font-size: 13pt; font-weight: 700; letter-spacing: 0.06em; }
.flag { padding: 0.01in 0.05in; border: 0.015in solid #ffffff; font-size: 6pt; font-weight: 700; text-transform: uppercase; }
.tracking { height: 1.02in; padding: 0.05in 0.1in 0.04in; }
.tracking-label { font-size: 6.5pt; font-weight: 700; text-transform: uppercase; }
.tracking-label strong { margin-left: 0.04in; font-family: "DejaVu Sans Mono", "Liberation Mono", monospace; font-size: 10pt; letter-spacing: 0.02em; }
.tracking-barcode img { display: block; width: 3.5in; height: 0.68in; margin-top: 0.04in; }
.refs { display: grid; grid-template-columns: 1fr 1fr 0.8fr; height: 0.34in; }
.refs > div { padding: 0.04in 0.08in; font-size: 7.5pt; font-weight: 700; white-space: nowrap; }
.refs > div + div { border-left: 0.02in solid #000000; }
</style>Render it with the API
After adding the template to your workspace, render it by ID and pass your data. Arrays are shortened here.
curl -X POST https://api-eu.dynamicdocumentapi.com/v1/renders \
-H "Authorization: Bearer $DYNAMIC_DOCUMENT_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{
"input": {
"type": "template",
"template_id": "tpl_01J9ZK3M7Q8V5W2X4Y6Z8A0B1C"
},
"data": {
"shipment": {
"tracking_number": "ND48273019665502",
"service_level": "Ground",
"service_code": "GND",
"transit": "3–5 business days",
"ship_date": "2026-09-17",
"weight_lb": 12.4,
"dimensions_in": {
"length": 14,
"width": 10,
"height": 8
},
"package_number": 2,
"package_count": 3,
"routing_code": "AZ 860 9-07",
"hub": "PHX-3",
"reference": "SO-58213",
"po_number": "7730-114",
"billing": "Prepaid",
"signature_required": true,
"locale": "en-US"
},
"sender": {
"name": "Driftwood Supply Co.",
"attention": "Shipping Dept.",
"address_lines": [
"480 Harbor Industrial Way, Unit C"
],
"city": "Portland",
"state": "OR",
"postal_code": "97217",
"phone": "+1 202-555-0119"
},
"recipient": {
"name": "Rosalind Achebe-Morrow",
"company": "Tamarack Ceramics Studio",
"address_lines": [
"2215 W Juniper Ave",
"Suite 110"
],
"city": "Flagstaff",
"state": "AZ",
"postal_code": "86001",
"country": "United States",
"phone": "+1 202-555-0182"
}
},
"output": {
"format": "pdf",
"filename": "shipping-label-4x6.pdf"
}
}'const response = await fetch("https://api-eu.dynamicdocumentapi.com/v1/renders", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.DYNAMIC_DOCUMENT_API_KEY}`,
"Content-Type": "application/json",
"Idempotency-Key": crypto.randomUUID(),
},
body: JSON.stringify({
"input": {
"type": "template",
"template_id": "tpl_01J9ZK3M7Q8V5W2X4Y6Z8A0B1C"
},
"data": {
"shipment": {
"tracking_number": "ND48273019665502",
"service_level": "Ground",
"service_code": "GND",
"transit": "3–5 business days",
"ship_date": "2026-09-17",
"weight_lb": 12.4,
"dimensions_in": {
"length": 14,
"width": 10,
"height": 8
},
"package_number": 2,
"package_count": 3,
"routing_code": "AZ 860 9-07",
"hub": "PHX-3",
"reference": "SO-58213",
"po_number": "7730-114",
"billing": "Prepaid",
"signature_required": true,
"locale": "en-US"
},
"sender": {
"name": "Driftwood Supply Co.",
"attention": "Shipping Dept.",
"address_lines": [
"480 Harbor Industrial Way, Unit C"
],
"city": "Portland",
"state": "OR",
"postal_code": "97217",
"phone": "+1 202-555-0119"
},
"recipient": {
"name": "Rosalind Achebe-Morrow",
"company": "Tamarack Ceramics Studio",
"address_lines": [
"2215 W Juniper Ave",
"Suite 110"
],
"city": "Flagstaff",
"state": "AZ",
"postal_code": "86001",
"country": "United States",
"phone": "+1 202-555-0182"
}
},
"output": {
"format": "pdf",
"filename": "shipping-label-4x6.pdf"
}
}),
});
if (!response.ok) throw new Error(`Request failed: ${response.status}`);
const result = await response.json();
console.log(result);import os
import uuid
import requests
response = requests.post(
"https://api-eu.dynamicdocumentapi.com/v1/renders",
headers={
"Authorization": f"Bearer {os.environ['DYNAMIC_DOCUMENT_API_KEY']}",
"Idempotency-Key": str(uuid.uuid4()),
},
json={
"input": {
"type": "template",
"template_id": "tpl_01J9ZK3M7Q8V5W2X4Y6Z8A0B1C",
},
"data": {
"shipment": {
"tracking_number": "ND48273019665502",
"service_level": "Ground",
"service_code": "GND",
"transit": "3–5 business days",
"ship_date": "2026-09-17",
"weight_lb": 12.4,
"dimensions_in": {
"length": 14,
"width": 10,
"height": 8,
},
"package_number": 2,
"package_count": 3,
"routing_code": "AZ 860 9-07",
"hub": "PHX-3",
"reference": "SO-58213",
"po_number": "7730-114",
"billing": "Prepaid",
"signature_required": True,
"locale": "en-US",
},
"sender": {
"name": "Driftwood Supply Co.",
"attention": "Shipping Dept.",
"address_lines": ["480 Harbor Industrial Way, Unit C"],
"city": "Portland",
"state": "OR",
"postal_code": "97217",
"phone": "+1 202-555-0119",
},
"recipient": {
"name": "Rosalind Achebe-Morrow",
"company": "Tamarack Ceramics Studio",
"address_lines": ["2215 W Juniper Ave", "Suite 110"],
"city": "Flagstaff",
"state": "AZ",
"postal_code": "86001",
"country": "United States",
"phone": "+1 202-555-0182",
},
},
"output": {
"format": "pdf",
"filename": "shipping-label-4x6.pdf",
},
},
timeout=90,
)
response.raise_for_status()
print(response.json())