(serviceGroups)
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.
- list - List all service groups
- create - Create a new service group
- update - Update an existing service group
- delete - Delete a service group
Returns a list of service group objects.
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();
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();
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. |
Promise<components.ServiceGroup[]>
Error Object | Status Code | Content Type |
---|---|---|
errors.SDKError | 4xx-5xx | / |
Creates a new service group.
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();
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();
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. |
Promise<components.ServiceGroup>
Error Object | Status Code | Content Type |
---|---|---|
errors.SDKError | 4xx-5xx | / |
Updates an existing service group object.
The object_id cannot be updated as it is the unique identifier for the object.
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();
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();
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. |
Promise<components.ServiceGroup>
Error Object | Status Code | Content Type |
---|---|---|
errors.SDKError | 4xx-5xx | / |
Deletes an existing service group using an object ID.
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();
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();
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. |
Promise<void>
Error Object | Status Code | Content Type |
---|---|---|
errors.SDKError | 4xx-5xx | / |