Skip to content

Latest commit

 

History

History
389 lines (290 loc) · 23.7 KB

File metadata and controls

389 lines (290 loc) · 23.7 KB

ServiceGroups

(serviceGroups)

Overview

A service group is a set of service levels grouped together. Rates at checkout uses services groups to present available shipping options to customers in their shopping basket.

Available Operations

  • list - List all service groups
  • create - Create a new service group
  • update - Update an existing service group
  • delete - Delete a service group

list

Returns a list of service group 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.serviceGroups.list();
  
  // Handle the result
  console.log(result)
}

run();

Standalone function

The standalone function version of this method:

import { ShippoCore } from "shippo/core.js";
import { serviceGroupsList } from "shippo/funcs/serviceGroupsList.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 serviceGroupsList(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.ServiceGroup[]>

Errors

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

create

Creates a new service group.

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.serviceGroups.create({
    description: "USPS shipping options",
    flatRate: "5",
    flatRateCurrency: "USD",
    freeShippingThresholdCurrency: "USD",
    freeShippingThresholdMin: "5",
    name: "USPS Shipping",
    rateAdjustment: 15,
    type: "FLAT_RATE",
    serviceLevels: [
      {
        accountObjectId: "80feb1633d4a43c898f0058506cfd82d",
        serviceLevelToken: "ups_next_day_air_saver",
      },
    ],
  });
  
  // Handle the result
  console.log(result)
}

run();

Standalone function

The standalone function version of this method:

import { ShippoCore } from "shippo/core.js";
import { serviceGroupsCreate } from "shippo/funcs/serviceGroupsCreate.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 serviceGroupsCreate(shippo, {
    description: "USPS shipping options",
    flatRate: "5",
    flatRateCurrency: "USD",
    freeShippingThresholdCurrency: "USD",
    freeShippingThresholdMin: "5",
    name: "USPS Shipping",
    rateAdjustment: 15,
    type: "FLAT_RATE",
    serviceLevels: [
      {
        accountObjectId: "80feb1633d4a43c898f0058506cfd82d",
        serviceLevelToken: "ups_next_day_air_saver",
      },
    ],
  });

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

  const { value: result } = res;

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

run();

Parameters

Parameter Type Required Description
request components.ServiceGroupCreateRequest ✔️ 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.ServiceGroup>

Errors

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

update

Updates an existing service group object.
The object_id cannot be updated as it is the unique identifier for the object.

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.serviceGroups.update({
    description: "USPS shipping options",
    flatRate: "5",
    flatRateCurrency: "USD",
    freeShippingThresholdCurrency: "USD",
    freeShippingThresholdMin: "5",
    name: "USPS Shipping",
    rateAdjustment: 15,
    type: "FLAT_RATE",
    objectId: "80feb1633d4a43c898f005850",
    isActive: true,
    serviceLevels: [
      {
        accountObjectId: "80feb1633d4a43c898f0058506cfd82d",
        serviceLevelToken: "ups_next_day_air_saver",
      },
      {
        accountObjectId: "80feb1633d4a43c898f0058506cfd82d",
        serviceLevelToken: "ups_next_day_air_saver",
      },
      {
        accountObjectId: "80feb1633d4a43c898f0058506cfd82d",
        serviceLevelToken: "ups_next_day_air_saver",
      },
    ],
  });
  
  // Handle the result
  console.log(result)
}

run();

Standalone function

The standalone function version of this method:

import { ShippoCore } from "shippo/core.js";
import { serviceGroupsUpdate } from "shippo/funcs/serviceGroupsUpdate.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 serviceGroupsUpdate(shippo, {
    description: "USPS shipping options",
    flatRate: "5",
    flatRateCurrency: "USD",
    freeShippingThresholdCurrency: "USD",
    freeShippingThresholdMin: "5",
    name: "USPS Shipping",
    rateAdjustment: 15,
    type: "FLAT_RATE",
    objectId: "80feb1633d4a43c898f005850",
    isActive: true,
    serviceLevels: [
      {
        accountObjectId: "80feb1633d4a43c898f0058506cfd82d",
        serviceLevelToken: "ups_next_day_air_saver",
      },
      {
        accountObjectId: "80feb1633d4a43c898f0058506cfd82d",
        serviceLevelToken: "ups_next_day_air_saver",
      },
      {
        accountObjectId: "80feb1633d4a43c898f0058506cfd82d",
        serviceLevelToken: "ups_next_day_air_saver",
      },
    ],
  });

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

  const { value: result } = res;

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

run();

Parameters

Parameter Type Required Description
request components.ServiceGroupUpdateRequest ✔️ 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.ServiceGroup>

Errors

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

delete

Deletes an existing service group 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.serviceGroups.delete("<value>");
}

run();

Standalone function

The standalone function version of this method:

import { ShippoCore } from "shippo/core.js";
import { serviceGroupsDelete } from "shippo/funcs/serviceGroupsDelete.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 serviceGroupsDelete(shippo, "<value>");

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

  const { value: result } = res;

  
}

run();

Parameters

Parameter Type Required Description
serviceGroupId string ✔️ Object ID of the service group
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 /