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).
Name | Type | Nullable? | Description |
---|---|---|---|
authorization | ✔ | The authorization information necessary to fulfill this request. | |
metadata | ✔ | 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_code | string | ✔ | Code used to map to what the carrier uses to identify the service. |
ship_datetime | string | 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 | ✔ | The requested confirmation for this label. If the field is absent it should be interpreted as "None". | |
advanced_options | ✔ | This contains an optional set of properties describing the advanced options a user might select. | |
insurance_provider | string | ✔ | The insurance provider for the insured value of the label,
Valid values include the following:
|
is_return_label | boolean | Indicates whether the label is a return. | |
is_residential | boolean | Indicates whether the label is to a residential address. | |
packages | All the packages that make up this shipment. There will always be at least one package defined. | ||
customs | ✔ | The customs associated with this shipment. | |
ship_to | The shipment recipient's address. It may or may not have been validated. | ||
ship_from | The shipment sender's address. It may or may not have been validated. | ||
pickup_location | ✔ | If this is a pickup shipment, a pickup location will be populated for where the recipient can pickup the shipment. | |
ship_from_display | ✔ | The address that should be displayed as the return address, only if the carrier supports this functionality. | |
next_day | boolean | ✔ | Indicates whether this shipment is expected to use a next day service class. If the field is absent it should be interpreted as false |
international | boolean | ✔ | Indicates Whether the shipment is international. |
fulfillment_plan_details | ✔ | 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.
Name | Type | Required? | Description |
---|---|---|---|
metadata | 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. | ||
rates | object[] | ✔ | 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_code | string | 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_datetime | string | 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_datetime | string | 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 | Individual Billing Line items for the rate. | ||
rates[].error_messages | string[] | Any error messages that resulted while trying to get the rate. | |
rates[].warning_messages | string[] | Any warning messages that resulted while trying to get the rate. | |
rates[].negotiated_rate | boolean | 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);}