Templates
Create Template
POST
`/v1/templates`
To create a template, you need to provide a name, a flag to set it as default, and the template data, which varies depending on the type of template being created.
name string (required)The name of the template, must be between 3 and 31 characters. |
set_as_default boolean (required)Indicates whether this template should be set as the default template for the resource. |
location_id string (optional)The ID of the location to associate this template with. |
template_data Object (required)The data specific to the template type being created. The structure will depend on the type of template. |
# Template Data Structure
The template_data can be one of the following types:
# Asset Label PDF Template
type string (required)Set to "asset__asset_label_pdf". |
barcode stringBarcode for the asset, defaults to the serial number. |
secondary_barcode stringAn optional additional barcode for the asset. |
dimensions LABEL_DIMENSIONS (optional)The dimensions for the label. |
org_logo_url stringURL for the organization's logo. |
text_line_1 stringFirst line of text on the label. |
text_line_2 stringSecond line of text on the label. |
text_line_3 stringThird line of text on the label. |
# Item Label PDF Template
type string (required)Set to "item__item_label_pdf". |
barcode stringBarcode for the item. |
dimensions LABEL_DIMENSIONS (optional)The dimensions for the label. |
org_logo_url stringURL for the organization's logo. |
text_line_1 stringFirst line of text on the label. |
text_line_2 stringSecond line of text on the label. |
text_line_3 stringThird line of text on the label. |
# Shipment Shipping Label PDF Template
type string (required)Set to "shipment__shipping_label_pdf". |
qr_code ObjectInformation for the QR code on the shipping label. |
- tracking_number stringTracking number for the shipment. |
- order_number stringOrder number associated with the shipment. |
- recipient ObjectDetails about the recipient. |
- name stringName of the recipient. |
- phone_number stringPhone number of the recipient. |
- email stringEmail address of the recipient. |
- delivery_date stringEstimated delivery date of the shipment. |
box_header stringHeader for the shipping box label. |
box_label_1 stringFirst label line for the shipping box. |
box_label_2 stringSecond label line for the shipping box. |
barcode stringBarcode associated with the tracking number. |
org_logo_url stringURL for the organization's logo to be displayed on the label. |
# Parcel Label PDF Template
type string (required)Set to "parcel__parcel_label_pdf". |
barcode stringBarcode for the parcel, typically the tracking number. |
qr_code ObjectInformation for the QR code on the parcel label. |
- tracking_number stringTracking number for the parcel. |
- order_number stringOrder number associated with the parcel. |
- recipient ObjectDetails about the recipient. |
- name stringName of the recipient. |
- sender ObjectDetails about the sender. |
- name stringName of the sender. |
- parcel_id stringThe ID of the parcel. |
org_logo_url stringURL for the organization's logo to be displayed on the label. |
dimensions stringDimensions of the parcel label. Currently only supports 4x6. |
text_line_1 stringFirst line of text on the parcel label. |
grid ObjectGrid configuration for the parcel label. |
- dimensions stringDimensions to display. |
- weight stringWeight to display. |
- order_number stringOrder number to display. |
- package_number stringPackage number to display. |
# Example Request
const data = {
name: "My Asset Label Template",
set_as_default: true,
template_data: {
type: "asset__asset_label_pdf",
barcode: "PX-AST-1001",
secondary_barcode: "SKU-12345",
dimensions: "A4",
org_logo_url: "https://example.com/logo.png",
text_line_1: "Asset Name",
text_line_2: "Category",
text_line_3: "Sub-category",
},
};
const res = await fetch(`https://api.packagex.io/v1/templates`, {
method: "POST",
headers: {
"PX-API-KEY": process.env.PX_API_KEY,
"Content-Type": "application/json",
},
body: JSON.stringify(data),
}).then((res) => res.json());
const template = res.data; // Refer to the created template model
Update Template
POST
/v1/templates/:template_id
You can update most properties of a template, including the name, the default setting, and the template data. The structure of the request body is similar to that of the create template endpoint.
const data = {
name: "Updated Asset Label Template",
set_as_default: false,
template_data: {
type: "asset__asset_label_pdf",
barcode: "PX-AST-2002",
secondary_barcode: "SKU-54321",
dimensions: "A4",
org_logo_url: "https://example.com/logo-updated.png",
text_line_1: "Updated Asset Name",
text_line_2: "Updated Category",
text_line_3: "Updated Sub-category",
},
};
const res = await fetch(`https://api.packagex.io/v1/templates/template_id`, {
method: "POST",
headers: {
"PX-API-KEY": process. env.PX_API_KEY,
"Content-Type": "application/json",
},
body: JSON.stringify(data),
}).then((res) => res.json());
const updatedTemplate = res.data; // Refer to the updated template model
List Templates
GET
`/v1/templates`
To retrieve a list of templates, you can filter by type, status, and order them by different properties.
| Property | Type | Description |
|---|---|---|
| type | TemplateType (optional) | Filter templates by their type (e.g., asset__asset_label_pdf, item__item_label_pdf, shipment__shipping_label_pdf). |
| status | string (optional) | Filter templates by their status, either default or custom. |
| order_by | string (optional) | Order the results by properties such as created_at, updated_at, name, type, or status. |
# Example Request
const res = await fetch(`https://api.packagex.io/v1/templates`, {
method: "GET",
headers: {
"PX-API-KEY": process.env.PX_API_KEY,
},
}).then((res) => res.json());
const templates = res.data; // Refer to the list of templates