1. Templates
  2. Retrieve Template

Templates

Retrieve Template

GET
`/v1/templates/:template`

Get a template using its id.

js
        const response = await fetch("https://api.packagex.io/v1/templates/temp_czhgjrk5JaVvyATPDbyURp", {
  method: "GET",
  headers: {
    "PX-API-KEY": process.env.PX_API_KEY,
    "Content-Type": "application/json",
  },
}).then((res) => res.json());

const template = response.data;

      

List Templates

GET
`/v1/templates`

Example

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, parcel__parcel_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.
location_id string (optional) Filter templates by the location they are assigned to. For example: location_id=loc_czhgjrk5JaVvyATPDbyURp
dimensions string (optional) Filter templates by label dimensions (e.g., 1x2, 2x2, 4x6).

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

      

Pagination

If the has_more property on the pagination object is set to true, you know there are more templates in the database that have not been returned to you. The pagination object also has a page property indicating your current offset and a limit property. The total_count property in pagination returns the the total number of templates in the database.

By default the page is set to 1 and the limit is 25.

If we want to query for templates 26 - 50, we would request page 2 with a query parameter.

js
        const response = await fetch("https://api.packagex.io/v1/templates?page=2&limit=25", {
  method: "GET",
  headers: {
    "PX-API-KEY": process.env.PX_API_KEY,
    "Content-Type": "application/json",
  },
}).then((res) => res.json());

const templates = response.data; //the array of templates 25 - 50
const pagination = response.pagination; //the pagination object