(rates)
A rate is the cost to ship a parcel from a carrier. The rate object details the service level including the cost and transit time.
- get - Retrieve a rate
- listShipmentRates - Retrieve shipment rates
- listShipmentRatesByCurrencyCode - Retrieve shipment rates in currency
Returns an existing rate using a rate object ID.
import { Shippo } from "shippo";
const shippo = new Shippo({
apiKeyHeader: "<YOUR_API_KEY_HERE>",
shippoApiVersion: "2018-02-08",
});
async function run() {
const result = await shippo.rates.get("<id>");
// Handle the result
console.log(result);
}
run();
The standalone function version of this method:
import { ShippoCore } from "shippo/core.js";
import { ratesGet } from "shippo/funcs/ratesGet.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 ratesGet(shippo, "<id>");
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result);
}
run();
Parameter | Type | Required | Description |
---|---|---|---|
rateId |
string | ✔️ | Object ID of the rate |
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.Rate>
Error Type | Status Code | Content Type |
---|---|---|
errors.SDKError | 4XX, 5XX | */* |
Returns a paginated list of rates associated with a shipment
import { Shippo } from "shippo";
const shippo = new Shippo({
apiKeyHeader: "<YOUR_API_KEY_HERE>",
shippoApiVersion: "2018-02-08",
});
async function run() {
const result = await shippo.rates.listShipmentRates("<id>", 1, 25);
// Handle the result
console.log(result);
}
run();
The standalone function version of this method:
import { ShippoCore } from "shippo/core.js";
import { ratesListShipmentRates } from "shippo/funcs/ratesListShipmentRates.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 ratesListShipmentRates(shippo, "<id>", 1, 25);
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result);
}
run();
Parameter | Type | Required | Description |
---|---|---|---|
shipmentId |
string | ✔️ | Object ID of the shipment to update |
page |
number | ➖ | The page number you want to select |
results |
number | ➖ | The number of results to return per page (max 100) |
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.RatePaginatedList>
Error Type | Status Code | Content Type |
---|---|---|
errors.SDKError | 4XX, 5XX | */* |
Returns all available shipping rates for a shipment object.
When you create a new valid shipment object, Shippo automatically calculates all available rates. Depending on your shipment data, there may be none, one or multiple rates.
By default, the calculated rates will return the price in two currencies under the amount
and amount_local
keys, respectively. The amount
key will contain the price of a rate expressed in the currency that is used in the country from where the parcel originates, and the amount_local
key will contain the price expressed in the currency that is used in the country the parcel is shipped to. You can request rates with prices expressed in a different currency by adding the currency code to the end of the resource URL. The full list of supported currencies along with their codes can be viewed on open exchange rates.
Note: re-requesting the rates with a different currency code will re-queue the shipment (i.e. set the Shipment's status
to QUEUED
) and the converted currency rates will only be available when the Shipment's status
is set to SUCCESS
.
import { Shippo } from "shippo";
const shippo = new Shippo({
apiKeyHeader: "<YOUR_API_KEY_HERE>",
shippoApiVersion: "2018-02-08",
});
async function run() {
const result = await shippo.rates.listShipmentRatesByCurrencyCode({
shipmentId: "<id>",
currencyCode: "USD",
page: 1,
results: 25,
});
// Handle the result
console.log(result);
}
run();
The standalone function version of this method:
import { ShippoCore } from "shippo/core.js";
import { ratesListShipmentRatesByCurrencyCode } from "shippo/funcs/ratesListShipmentRatesByCurrencyCode.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 ratesListShipmentRatesByCurrencyCode(shippo, {
shipmentId: "<id>",
currencyCode: "USD",
page: 1,
results: 25,
});
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result);
}
run();
Parameter | Type | Required | Description |
---|---|---|---|
request |
operations.ListShipmentRatesByCurrencyCodeRequest | ✔️ | 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.RatePaginatedList>
Error Type | Status Code | Content Type |
---|---|---|
errors.SDKError | 4XX, 5XX | */* |