Skip to content

Latest commit

 

History

History
419 lines (295 loc) · 29.1 KB

File metadata and controls

419 lines (295 loc) · 29.1 KB

UserParcelTemplates

(userParcelTemplates)

Overview

A user parcel template represents a package used for shipping that has preset dimensions and attributes defined by you. They are useful for capturing attributes of parcel-types you frequently use for shipping, allowing them to be defined once and then used for many shipments. These parcel templates can also be used for live rates.

User parcel templates can also be created using a carrier parcel template, where the dimensions will be copied from the carrier presets, but the weight can be configured by you.

Available Operations

  • list - List all user parcel templates
  • create - Create a new user parcel template
  • delete - Delete a user parcel template
  • get - Retrieves a user parcel template
  • update - Update an existing user parcel template

list

Returns a list all of all user parcel template objects.

Example Usage

import { Shippo } from "shippo";

const shippo = new Shippo({
  apiKeyHeader: "<YOUR_API_KEY_HERE>",
  shippoApiVersion: "2018-02-08",
});

async function run() {
  const result = await shippo.userParcelTemplates.list();
  
  // Handle the result
  console.log(result)
}

run();

Standalone function

The standalone function version of this method:

import { ShippoCore } from "shippo/core.js";
import { userParcelTemplatesList } from "shippo/funcs/userParcelTemplatesList.js";

// Use `ShippoCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const shippo = new ShippoCore({
  apiKeyHeader: "<YOUR_API_KEY_HERE>",
  shippoApiVersion: "2018-02-08",
});

async function run() {
  const res = await userParcelTemplatesList(shippo);

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result)
}

run();

Parameters

Parameter Type Required Description
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<components.UserParcelTemplateList>

Errors

Error Object Status Code Content Type
errors.SDKError 4xx-5xx /

create

Creates a new user parcel template.
You can choose to create a parcel template using a preset carrier template as a starting point, or you can create an entirely custom one. To use a preset carrier template, pass in a unique template token from this list plus the weight fields (weight and weight_unit). Otherwise, omit the template field and pass the other fields, for the weight, length, height, and depth, as well as their units."

Example Usage

import { Shippo } from "shippo";

const shippo = new Shippo({
  apiKeyHeader: "<YOUR_API_KEY_HERE>",
  shippoApiVersion: "2018-02-08",
});

async function run() {
  const result = await shippo.userParcelTemplates.create({
    weight: "12",
    weightUnit: "lb",
  });
  
  // Handle the result
  console.log(result)
}

run();

Standalone function

The standalone function version of this method:

import { ShippoCore } from "shippo/core.js";
import { userParcelTemplatesCreate } from "shippo/funcs/userParcelTemplatesCreate.js";

// Use `ShippoCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const shippo = new ShippoCore({
  apiKeyHeader: "<YOUR_API_KEY_HERE>",
  shippoApiVersion: "2018-02-08",
});

async function run() {
  const res = await userParcelTemplatesCreate(shippo, {
    weight: "12",
    weightUnit: "lb",
  });

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result)
}

run();

Parameters

Parameter Type Required Description
request components.UserParcelTemplateCreateRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<components.UserParcelTemplate>

Errors

Error Object Status Code Content Type
errors.SDKError 4xx-5xx /

delete

Deletes a user parcel template using an object ID.

Example Usage

import { Shippo } from "shippo";

const shippo = new Shippo({
  apiKeyHeader: "<YOUR_API_KEY_HERE>",
  shippoApiVersion: "2018-02-08",
});

async function run() {
  await shippo.userParcelTemplates.delete("<value>");
}

run();

Standalone function

The standalone function version of this method:

import { ShippoCore } from "shippo/core.js";
import { userParcelTemplatesDelete } from "shippo/funcs/userParcelTemplatesDelete.js";

// Use `ShippoCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const shippo = new ShippoCore({
  apiKeyHeader: "<YOUR_API_KEY_HERE>",
  shippoApiVersion: "2018-02-08",
});

async function run() {
  const res = await userParcelTemplatesDelete(shippo, "<value>");

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  
}

run();

Parameters

Parameter Type Required Description
userParcelTemplateObjectId string ✔️ Object ID of the user parcel template
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<void>

Errors

Error Object Status Code Content Type
errors.SDKError 4xx-5xx /

get

Returns the parcel template information for a specific user parcel template, identified by the object ID.

Example Usage

import { Shippo } from "shippo";

const shippo = new Shippo({
  apiKeyHeader: "<YOUR_API_KEY_HERE>",
  shippoApiVersion: "2018-02-08",
});

async function run() {
  const result = await shippo.userParcelTemplates.get("<value>");
  
  // Handle the result
  console.log(result)
}

run();

Standalone function

The standalone function version of this method:

import { ShippoCore } from "shippo/core.js";
import { userParcelTemplatesGet } from "shippo/funcs/userParcelTemplatesGet.js";

// Use `ShippoCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const shippo = new ShippoCore({
  apiKeyHeader: "<YOUR_API_KEY_HERE>",
  shippoApiVersion: "2018-02-08",
});

async function run() {
  const res = await userParcelTemplatesGet(shippo, "<value>");

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result)
}

run();

Parameters

Parameter Type Required Description
userParcelTemplateObjectId string ✔️ Object ID of the user parcel template
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<components.UserParcelTemplate>

Errors

Error Object Status Code Content Type
errors.SDKError 4xx-5xx /

update

Updates an existing user parcel template.

Example Usage

import { Shippo } from "shippo";

const shippo = new Shippo({
  apiKeyHeader: "<YOUR_API_KEY_HERE>",
  shippoApiVersion: "2018-02-08",
});

async function run() {
  const result = await shippo.userParcelTemplates.update("<value>", {
    distanceUnit: "in",
    height: "6",
    length: "10",
    name: "My Custom Template",
    weight: "12",
    weightUnit: "lb",
    width: "8",
  });
  
  // Handle the result
  console.log(result)
}

run();

Standalone function

The standalone function version of this method:

import { ShippoCore } from "shippo/core.js";
import { userParcelTemplatesUpdate } from "shippo/funcs/userParcelTemplatesUpdate.js";

// Use `ShippoCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const shippo = new ShippoCore({
  apiKeyHeader: "<YOUR_API_KEY_HERE>",
  shippoApiVersion: "2018-02-08",
});

async function run() {
  const res = await userParcelTemplatesUpdate(shippo, "<value>", {
    distanceUnit: "in",
    height: "6",
    length: "10",
    name: "My Custom Template",
    weight: "12",
    weightUnit: "lb",
    width: "8",
  });

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result)
}

run();

Parameters

Parameter Type Required Description
userParcelTemplateObjectId string ✔️ Object ID of the user parcel template
userParcelTemplateUpdateRequest components.UserParcelTemplateUpdateRequest N/A
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<components.UserParcelTemplate>

Errors

Error Object Status Code Content Type
errors.SDKError 4xx-5xx /