1. Templates
  2. Create Template

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.
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 string
Barcode for the asset, defaults to the serial number.
secondary_barcode string
An optional additional barcode for the asset.
dimensions LABEL_DIMENSIONS (optional)
The dimensions for the label.
org_logo_url string
URL for the organization's logo.
text_line_1 string
First line of text on the label.
text_line_2 string
Second line of text on the label.
text_line_3 string
Third line of text on the label.

Item Label PDF Template

type string (required)
Set to "item__item_label_pdf".
barcode string
Barcode for the item.
dimensions LABEL_DIMENSIONS (optional)
The dimensions for the label.
org_logo_url string
URL for the organization's logo.
text_line_1 string
First line of text on the label.
text_line_2 string
Second line of text on the label.
text_line_3 string
Third line of text on the label.

Shipment Shipping Label PDF Template

type string (required)
Set to "shipment__shipping_label_pdf".
qr_code Object
Information for the QR code on the shipping label.
- tracking_number string
Tracking number for the shipment.
- order_number string
Order number associated with the shipment.
- recipient Object
Details about the recipient.
- name string
Name of the recipient.
- phone_number string
Phone number of the recipient.
- email string
Email address of the recipient.
- delivery_date string
Estimated delivery date of the shipment.
box_header string
Header for the shipping box label.
box_label_1 string
First label line for the shipping box.
box_label_2 string
Second label line for the shipping box.
barcode string
Barcode associated with the tracking number.
org_logo_url string
URL for the organization's logo to be displayed on the label.

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