GetRates()

This method get possible rates for labels between two addresses.

Syntax

module.exports = async function GetRates(request) {
// Your code here
}
import { GetRatesRequest, GetRatesResponse } from "@shipengine/connect-carrier-api";
export default async function GetRates(
request: GetRatesRequest
): Promise<GetRatesResponse> {
// Your code here
}

Parameters

GetRatesRequest

An object containing information about the shipment to get rates for. The more information provided the more accurate rates (usually).

NameTypeNullable?Description
authorization

authorization object

The authorization information necessary to fulfill this request.

metadata

metadata object

This object should contain all of the necessary properties needed to make authenticated requests with the carrier when an AuthProcess has not been configured. Every property included here will be persisted by ShipEngine Connect and included on each subsequent request from this user.

service_codestring

Code used to map to what the carrier uses to identify the service.

ship_datetimestring

When the package is expected to ship. Not guaranteed to be in the future. Formatted per the https://tools.ietf.org/html/rfc3339 spec. Will always be in UTC.

confirmation

confirmation type

The requested confirmation for this label. If the field is absent it should be interpreted as "None".

advanced_optionsobject

This is a schemaless object. It is for open ended customizations unique to particular carriers. If the field is absent it should be interpreted as the default value for any applicable options, e.g. false for booleans.

insurance_providerstring

The insurance provider for the insured value of the label, carrier indicates that the user is requesting insurance from the carrier directly, anything else is extra information that should not result in a transaction.

Valid values include the following:

  • None
  • Shipstation
  • Carrier
  • External
is_return_labelboolean

Indicates whether the label is a return.

is_residentialboolean

Indicates whether the label is to a residential address.

packages

package object[]

All the packages that make up this shipment. There will always be at least one package defined.

customs

customs object

The customs associated with this shipment.

ship_to

shipping address object

The shipment recipient's address. It may or may not have been validated.

ship_from

shipping address object

The shipment sender's address. It may or may not have been validated.

pickup_location

pickup location object

If this is a pickup shipment, a pickup location will be populated for where the recipient can pickup the shipment.

ship_from_display

shipping address object

The address that should be displayed as the return address, only if the carrier supports this functionality.

next_dayboolean

Indicates whether this shipment is expected to use a next day service class. If the field is absent it should be interpreted as false

internationalboolean

Indicates Whether the shipment is international.

fulfillment_plan_details

fulfillment plan details object

This model contains information about the fulfillment plan. This is not provided for all rate requests.

Return Value

GetRatesResponse

This object model represents the response from a successful get rates request.

NameTypeRequired?Description
metadata

metadata object

This object should contain all of the necessary properties needed to make authenticated requests with the carrier. Every property included here will be persisted by ShipEngine Connect and included on each subsequent request from this user.

ratesobject[]

A list of rates for shipping services. If you use service codes there may be exactly one rate returned for the requested service. If you use service codes there may be more than one rate to provide additional options. If you don't use service codes there may be one or more rates. If you don't provide real time rates you should return a single hard coded zero value rate.

rates[].service_codestring

The service code uniquely identifies a shipping service that you offer. Which service codes can be passed to you will be configured in ShipEngine. If this field is missing, the rate will be discarded.

rates[].ship_datetimestring

When the package should ship for this rate to be valid. Formatted per the https://tools.ietf.org/html/rfc3339 spec. Must be in UTC.

rates[]   .estimated_delivery_datetimestring

When the package(s) in this shipment are expected to arrive at their destination. Formatted per the https://tools.ietf.org/html/rfc3339 spec. Must be in UTC.

rates[]   .billing_line_items

billing line item object[]

Individual Billing Line items for the rate.

rates[].error_messagesstring[]

Any error messages that resulted while trying to get the rate.

rates[].warning_messagesstring[]

Any warning messages that resulted while trying to get the rate.

rates[].negotiated_rateboolean

Indicates whether this is a pre-negotiated rate.

Example

module.exports = async function GetRates(request) {
// STEP 1: Validation
// TODO: add any validation logic here
// STEP 2: Create the data that the carrier's API expects
let data = {
operation: "quote_rates",
service_codes: [request.service_code],
confirmation_codes: [request.confirmation],
ship_date: request.ship_datetime,
from_zone: parseInt(request.ship_from.postal_code, 10),
to_zone: parseInt(request.ship_to.postal_code, 10),
};
// STEP 3: Call the carrier's API
const response = await apiClient.request({ data });
// STEP 4: Create the output data that ShipEngine expects
return formatRates(response.data);
}
import {
GetRatesRequest,
GetRatesResponse
} from "@shipengine/connect-carrier-api";
export default async function GetRates(request: GetRatesRequest): Promise<GetRatesResponse> {
// STEP 1: Validation
// TODO: add any validation logic here
// STEP 2: Create the data that the carrier's API expects
let data: GenerateRatesRequest = {
operation: "quote_rates",
service_codes: [request.service_code],
confirmation_codes: [request.confirmation],
ship_date: request.ship_datetime,
from_zone: parseInt(request.ship_from.postal_code, 10),
to_zone: parseInt(request.ship_to.postal_code, 10),
};
// STEP 3: Call the carrier's API
const response = await apiClient.request<GenerateRatesRequest>({ data });
// STEP 4: Create the output data that ShipEngine expects
return formatRates(response.data);
}