Fetching Shipping Rates
To fetch shipping rates, POST an array of items and their destination address to the rates endpoint. An array of rate objects will be returned in the response.
Jump to POST /rates documentation
Test Mode & Rate Failure
The response will be an array of rates for the given shipment except in the following conditions:
- If the App is in test mode and the word "Bambri" is not found in the destination name field
- If no rates are found and rate failure is enabled
If either of the above conditions are met, the response will include an error message instead of an array of rate objects. See Test Mode and Rate Failure for more info.
Response Time
Note that the response time for rates is inherently linked to the response times of the various carrier and integration APIs we utilize (i.e. UPS, FedEx, USPS). While a rate call that processes only Flat Rate Methods will respond in milliseconds, a call that processes one or more carrier rates could take upwards of one second to respond.
Content Type
JSON is used for all requests and responses. The Content-Type header for each call must be set to "application/json"
Examples
Sample Request
curl -i https://api.advancedshippingrules.com/rates \ -X POST \ -u APP_ID:API_KEY \ -H "Content-Type: application/json" \ -d '{ "destination": { "country": "US", "postal_code": "11211", "province": "NY", "city": "Brooklyn", "name": "Bambri Testmode", "address1": "123 Main St", "address2": null, "phone": "1234567890", "company_name": null }, "items": [ { "variant_id": 1234567890, "fulfillment_service": "manual", "quantity": 1, "grams": 1000, "price": 2000, "name": "Product 1", "sku": "P1-012", "vendor": "TestVendor",
"properties":
{
"this_is_property_name":"this_is_property_value"
} }, { "variant_id": 2345678901, "fulfillment_service": "heavy-furniture", "quantity": 1, "grams": 77110, "price": 274900, "name": "Product 2", "sku": "P2-034", "vendor": "VendorName" } ] }'
Sample Response
[ { "service_name":"UPS Ground", "service_code":"ups-ground", "total_price":1243, "currency":"USD" }, { "service_name":"FedEx 2Day", "service_code":"FEDEX_2_DAY", "total_price":3789, "currency":"USD" } ]
POST /rates
Definition
POST https://api.advancedshippingrules.com/rates
Request Parameters
Field |
Description |
Type |
destination |
An object containing the destination address details |
Object |
items |
An array of items to ship |
Array |
Request: Destination Parameters
Destination must be sent as an object containing the following fields.
Field |
Description |
Type |
country |
The ISO 3166-1 alpha-2 two-letter country code for the destination country |
Char(2) |
postal_code |
The postal code (zip code) for the destination address |
String |
province optional |
The province, or state, of the destination address |
String |
city optional |
The city of the destination address |
String |
name optional |
The "ship to" name for the destination address. When a Shop's App is in test mode, the name field must include the word "Bambri" to display rates. |
String |
address1 optional |
The first address line of the destination address |
String |
address2 optional |
The second address line of the destination address |
String |
phone optional |
A phone number for the destination address |
String |
company_name optional |
The company name for the destination address |
String |
Request: Item Parameters
Items must be sent as an array of objects, each containing the following fields.
Field |
Description |
Type |
variant_id |
The Shopify variant id of an item being shipped |
Integer |
fulfillment_service |
The Fulfillment Service handle of the item |
String |
quantity |
The quantity of the item |
Integer |
grams |
The weight of one item, in grams The total shipping weight for this item will be calculated by multiplying this value by the item's quantity value. |
Integer |
price |
The price of one item, in cents |
Integer |
requires_shipping |
A boolean value indicating whether or not the item requires shipping. When false, the item's shipping price will not be calculated. By default, requires_shipping is assumed to be true and an item is only ignored if requires_shipping is explicitly set to false or 0. |
Boolean |
name optional |
The name, or title, of the item |
String |
sku optional |
The item's SKU |
String |
vendor optional |
The item's vendor name |
String |
Response: Rate Object Attributes
Rates are returned in a JSON array of objects with the following fields:
Field |
Description |
Type |
service_name |
The name of the rate, which customers see at checkout For example: "Fedex Ground" |
String |
description |
A description of the rate, which customers see at checkout For example: "Includes tracking and insurance" |
String |
service_code |
A unique code associated with the rate For example: "FEDEX_GROUND" |
String |
total_price |
Total price, in cents, based on the shipping rate currency For example: “1234” for $12.34 |
Integer |
currency |
Currency of the shipping rate For example: “USD” |
String |