Shipments
Create Shipments
Creating a shipment is a two-step process. First, you will get shipping rates. Then you'll select one of those shipping rates to purchase.
Get Rates
There are three pieces of information we require to get rates: sender, recipient, and parcel. There are also some additional options you can pass in to configure the shipment.
Sender & Recipient
The sender and recipient information have the same properties, so we'll cover both here.
We'll automatically parse the address for you. If you use an autocomplete like from Google Maps, Algolia, or PackageX, the format will come packed as a single string.
However, many autocomplete results don't come with a unit field, so typically that information is entered in a different input. If that is the case, you can provide a unit or apartment number in the address_line2
property.
If you have the address information from the customer from multiple input fields, you can pass it through as an object
instead of an inline string
.
Lastly, if you already have reference to an address that we parsed before, you can pass that address's ID property instead. This will speed up your request.
Parcel
For the parcel, you'll need to let us know the size and weight of the parcel. If you are using one of the predefined packages, you can reference that using the type field or you can enter the length
, width
, and height
in inches. The weight
is entered in lbs.
You don't need to provide dimensions if using a predefined package. In fact, you don't strictly need to provide the weight either, but there are situations like with on-demand providers where not defaulting to the predefined package's max weight will result in better rates, so include this value if you have it.
You can also optionally provide a special_handing
. The special_handling
field is currently experimental and will be standardized soon.
If you want to let us know about specific inventory you are shipping, you can also pass an Inventory array to describe the items that are inside of the parcel. This is done automatically for you if you are creating a shipment via a fulfillment_id
, but you can do so manually if you would like.
The reasons that you would want to include the inventory items in each parcel are:
- you are shipping something internationally and need to include customs information
- something you are shipping in this parcel needs additional care due to the item attributes like alcohol, hazardous materials, or pharmaceuticals.
- you want to include additional information for your records later
Type
Typically, the shipment is always outbound
but you have the option of creating an inbound
shipment by specifying whether it is inbound or outbound by adding the following optional property in the request body (defaults to outbound
):
- type
"outbound" | "inbound"
Options
Any omitted options will be defaulted to the values set in your settings.
Simple Options Example
Filter Results Example
In the example below, we're showing all of the filter properties that you can add. It's not advise to add all of those options because there can be conflicts with the filtering resulting in all of the rates being filtered out.
If all of the shipping rates get filtered out, then all of the rates will be returned besides those that are offline_delivery
to prevent accidentally leaking them to customers.
Multi-piece shipments
If shipping multiple boxes that are part of the same shipment, you can pass all of the parcels in an array. Each rate that is returned will have their price reflect both parcels.
Depending on the provider, someones both parcels will have the same tracking number while other times each parcel has a unique tracking number. This is dependent on how the provider does things. If the provider creates multiple tracking numbers, we'll add those tracking numbers to the tracking_number
property of the parcel and use a single tracking number for the shipment's tracking_number
property.
Refetch Rates
After you already fetched rates, you can also fetch new rates. You'll want to do this if:
- Your rate has expired because the
rates_generated_at
is more than 15 minutes from now. - You want to update your options that you added into the shipment.
All of the options that are passed in for getting rates can also be passed in to refetch rates.
Purchase Rate
Properties
Now that you have generated your shipping rates, you are able to purchase the shipment. You'll want to find the id
of the shipping rate to purchase from the response that you received from generating the shipping rates.
Example
In this instance, we'll select the cheapest shipping rate from the response we received in the previous step. To purchase the shipment, we'll need the shipment ID from the response and the rate ID that we want to purchase. Everything else is optional.
Select Payment Method Example
In this instance, we'll select the cheapest shipping rate from the response we received in the previous step. To purchase the shipment, we'll need the shipment ID from the response and the rate ID that we want to purchase. Everything else is optional.