Multi-piece shipment
Shipments with multiple packages sent to the same destination can be grouped together in a multi-piece shipment to save money.
Multi-piece packages/parcels in a single shipment may receive timeouts at certain thresholds based on the carrier. Currently requesting rates for 5 or more packages/parcels in a single shipment may result in timeouts for UPS. Additionally, sending more than 12 parcels within one shipment for FedEx may result in a timeout. USPS does not support multi-piece packages/parcels in a single shipment at this time.
How to create a multi-piece shipment
To create a multi-piece shipment, simply add a list of Parcel objects to the parcels
field in a Shipment. Generating rates and creating transactions works the exact same way as with normal shipments. The limit on the number of parcels depends on each carrier's restrictions.
The Shipment request content should look like:
curl https://api.goshippo.com/shipments/\
-H "Authorization: ShippoToken <API_Token>"\
-H "Content-Type: application/json"\
-d '{
"address_from": {
"name": "Mr. Hippo",
"street1": "215 Clayton St.",
"city": "San Francisco",
"state": "CA",
"zip": "94117",
"country": "US",
"phone": "+1 555 341 9393",
"email": "support@shippo.com"
},
"address_to": {
"name": "Mrs. Hippo",
"street1": "965 Mission St.",
"city": "San Francisco",
"state": "CA",
"zip": "94105",
"country": "US",
"phone": "+1 555 341 9393",
"email": "support@shippo.com"
},
"parcels": [
{
"length": "5",
"width": "5",
"height": "5",
"distance_unit": "in",
"weight": "2",
"mass_unit": "lb"
},
{
"length": "10",
"width": "10",
"height": "10",
"distance_unit": "in",
"weight": "2",
"mass_unit": "lb"
}
],
"async": false
}'
require 'shippo'
Shippo::API.token = '<API_Token>'
address_from = {
:name => 'Shawn Ippotle',
:street1 => '965 Mission St.',
:city => 'San Francisco',
:state => 'CA',
:zip => '94117',
:country => 'US',
:phone => '+1 555 341 9393',
:email => 'shippotle@shippo.com'
}
address_to = {
:name => 'Mr Hippo',
:street1 => 'Broadway 1',
:city => 'New York',
:state => 'NY',
:zip => '10007',
:country => 'US',
:phone => '+1 555 341 9393',
:email => 'mrhippo@shippo.com'
}
parcel_1 = {
:length => 5,
:width => 1,
:height => 5.555,
:distance_unit => :in,
:weight => 2,
:mass_unit => :lb
}
parcel_2 = {
:length => 10,
:width => 10,
:height => 10,
:distance_unit => :in,
:weight => 2,
:mass_unit => :lb
}
shipment = Shippo::Shipment.create(
:address_from => address_from,
:address_to => address_to,
:parcels => [parcel_1, parcel_2],
:async => false
)
import shippo
shippo.api_key = "<API_Token>"
address_from = {
"name": "Shawn Ippotle",
"street1": "215 Clayton St.",
"city": "San Francisco",
"state": "CA",
"zip": "94117",
"country": "US",
"phone": "+1 555 341 9393",
"email": "shippotle@shippo.com"
}
address_to = {
"name": "Mr Hippo",
"street1": "Broadway 1",
"city": "New York",
"state": "NY",
"zip": "10007",
"country": "US",
"phone": "+1 555 341 9393",
"email": "mrhippo@shippo.com"
}
parcel_1 = {
"length": "5",
"width": "5",
"height": "5",
"distance_unit": "in",
"weight": "2",
"mass_unit": "lb"
}
parcel_2 = {
"length": "10",
"width": "10",
"height": "10",
"distance_unit": "in",
"weight": "2",
"mass_unit": "lb"
}
shipment = shippo.Shipment.create(
address_from = address_from,
address_to = address_to,
parcels = [parcel_1, parcel_2],
async = False
)
require_once('lib/Shippo.php');
Shippo::setApiKey("<API_Token>");
$fromAddress = array(
'name' => 'Shawn Ippotle',
'street1' => '215 Clayton St.',
'city' => 'San Francisco',
'state' => 'CA',
'zip' => '94117',
'country' => 'US',
'phone' => '+1 555 341 9393',
'email' => 'shippotle@shippo.com'
);
$toAddress = array(
'name' => 'Mr Hippo"',
'street1' => 'Broadway 1',
'city' => 'New York',
'state' => 'NY',
'zip' => '10007',
'country' => 'US',
'phone' => '+1 555 341 9393',
'email' => 'mrhippo@shippo.com'
);
$parcel_1 = array(
'length'=> '5',
'width'=> '5',
'height'=> '5',
'distance_unit'=> 'in',
'weight'=> '2',
'mass_unit'=> 'lb',
);
$parcel_2 = array(
'length'=> '10',
'width'=> '10',
'height'=> '10',
'distance_unit'=> 'in',
'weight'=> '2',
'mass_unit'=> 'lb',
);
$shipment = Shippo_Shipment::create(
array(
"address_from" => $fromAddress,
"address_to" => $toAddress,
"parcels" => array($parcel_1, $parcel_2),
"async" => false
)
);
var shippo = require('shippo')('<API_Token>');
var addressFrom = {
"name": "Shawn Ippotle",
"street1": "215 Clayton St.",
"city": "San Francisco",
"state": "CA",
"zip": "94117",
"country": "US",
"phone": "+1 555 341 9393",
"email": "shippotle@shippo.com"
};
var addressTo = {
"name": "Mr Hippo",
"street1": "Broadway 1",
"city": "New York",
"state": "NY",
"zip": "10007",
"country": "US",
"phone": "+1 555 341 9393",
"email": "mrhippo@shippo.com"
};
var parcel_1 = {
"length": "5",
"width": "5",
"height": "5",
"distance_unit": "in",
"weight": "2",
"mass_unit": "lb"
};
var parcel_2 = {
"length": "10",
"width": "10",
"height": "10",
"distance_unit": "in",
"weight": "2",
"mass_unit": "lb"
};
shippo.shipment.create({
"address_from": addressFrom,
"address_to": addressTo,
"parcels": [parcel_1, parcel_2],
"async": true
}, function(err, shipment) {
// asynchronously called
});
Shippo.setApiKey('<API_Token>');
// To Address
HashMap<String, Object> addressToMap = new HashMap<String, Object>();
addressToMap.put("name", "Mr Hippo");
addressToMap.put("company", "Shippo");
addressToMap.put("street1", "215 Clayton St.");
addressToMap.put("city", "San Francisco");
addressToMap.put("state", "CA");
addressToMap.put("zip", "94117");
addressToMap.put("country", "US");
addressToMap.put("phone", "+1 555 341 9393");
addressToMap.put("email", "mrhippo@goshipppo.com");
// From Address
HashMap<String, Object> addressFromMap = new HashMap<String, Object>();
addressFromMap.put("name", "Ms Hippo");
addressFromMap.put("company", "San Diego Zoo");
addressFromMap.put("street1", "2920 Zoo Drive");
addressFromMap.put("city", "San Diego");
addressFromMap.put("state", "CA");
addressFromMap.put("zip", "92101");
addressFromMap.put("country", "US");
addressFromMap.put("email", "mshippo@goshipppo.com");
addressFromMap.put("phone", "+1 619 231 1515");
addressFromMap.put("metadata", "Customer ID 123456");
List<HashMap> parcelList = new List();
// Parcel One
HashMap<String, Object> parcelMapOne = new HashMap<String, Object>();
parcelMapOne.put("length", "5");
parcelMapOne.put("width", "5");
parcelMapOne.put("height", "5");
parcelMapOne.put("distance_unit", "in");
parcelMapOne.put("weight", "2");
parcelMapOne.put("mass_unit", "lb");
// Parcel Two
HashMap<String, Object> parcelMapTwo = new HashMap<String, Object>();
parcelMapTwo.put("length", "1");
parcelMapTwo.put("width", "1");
parcelMapTwo.put("height", "1");
parcelMapTwo.put("distance_unit", "in");
parcelMapTwo.put("weight", "2");
parcelMapTwo.put("mass_unit", "lb");
parcelList.add(parcelMapOne);
parcelList.add(parcelMapTwo);
// Shipment
HashMap<String, Object> shipmentMap = new HashMap<String, Object>();
shipmentMap.put("address_to", addressToMap);
shipmentMap.put("address_from", addressFromMap);
shipmentMap.put("parcels", parcelList);
shipmentMap.put("async", false);
APIResource resource = new APIResource("<API_Token>");
Hashtable toAddressTable = new Hashtable();
toAddressTable.Add("name", "Mr. Hippo");
toAddressTable.Add("company", "Shippo");
toAddressTable.Add("street1", "215 Clayton St.");
toAddressTable.Add("city", "San Francisco");
toAddressTable.Add("state", "CA");
toAddressTable.Add("zip", "94117");
toAddressTable.Add("country", "US");
toAddressTable.Add("phone", "+1 555 341 9393");
toAddressTable.Add("email", "support@goshipppo.com");
// from address
Hashtable fromAddressTable = new Hashtable();
fromAddressTable.Add("name", "Ms Hippo");
fromAddressTable.Add("company", "San Diego Zoo");
fromAddressTable.Add("street1", "2920 Zoo Drive");
fromAddressTable.Add("city", "San Diego");
fromAddressTable.Add("state", "CA");
fromAddressTable.Add("zip", "92101");
fromAddressTable.Add("country", "US");
fromAddressTable.Add("email", "hippo@goshipppo.com");
fromAddressTable.Add("phone", "+1 619 231 1515");
fromAddressTable.Add("metadata", "Customer ID 123456");
List parcelsList = new List();
// parcel
Hashtable parcelTable = new Hashtable();
parcelTable.Add("length", "5");
parcelTable.Add("width", "5");
parcelTable.Add("height", "5");
parcelTable.Add("distance_unit", "in");
parcelTable.Add("weight", "2");
parcelTable.Add("mass_unit", "lb");
Hashtable parcelTableTwo = new Hashtable();
parcelTableTwo.Add("length", "1");
parcelTableTwo.Add("width", "1");
parcelTableTwo.Add("height", "1");
parcelTableTwo.Add("distance_unit", "in");
parcelTableTwo.Add("weight", "2");
parcelTableTwo.Add("mass_unit", "lb");
parcelsList.Add(parcelTable);
parcelsList.Add(parcelTableTwo);
// shipment
Hashtable shipmentTable = new Hashtable();
shipmentTable.Add("address_to", toAddressTable);
shipmentTable.Add("address_from", fromAddressTable);
shipmentTable.Add("parcels", parcelsList);
shipmentTable.Add("async", false);
As usual, the Shipment request will return a list of Rates for you to select from. The Rate amount
refers to the cost of the entire Shipment with multiple packages, not per package.
{
"status": "SUCCESS",
"object_created": "2013-12-01T06:24:20.121Z",
"object_updated": "2013-12-01T06:24:20.121Z",
"object_id": "5e40ead7cffe4cc1ad45108696162e42",
"object_owner": "shippotle@shippo.com",
"address_from": {
"object_id": "0943ae4e373e4120a99c337e496dcce8",
"validation_results": {},
"is_complete": true,
"company": "",
"street_no": "",
"name": "Mr. Hippo",
"street1": "215 Clayton St.",
"street2": "",
"city": "San Francisco",
"state": "CA",
"zip": "94117",
"country": "US",
"phone": "+15553419393",
"email": "support@shippo.com",
"is_residential": null
},
"address_to": {
"object_id": "4c7185d353764d0985a6a7825aed8ffb",
"validation_results": {},
"is_complete": true,
"name":"Mrs. Hippo",
"street1":"965 Mission St.",
"city":"San Francisco",
"state":"CA",
"zip":"94105",
"country":"US",
"phone":"+1 555 341 9393",
"email":"support@shippo.com",
"is_residential": false
},
"address_return": {
"object_id": "0943ae4e373e4120a99c337e496dcce8",
"validation_results": {},
"is_complete": true,
"company": "",
"street_no": "",
"name": "Mr. Hippo",
"street1": "215 Clayton St.",
"street2": "",
"city": "San Francisco",
"state": "CA",
"zip": "94117",
"country": "US",
"phone": "+15553419393",
"email": "support@shippo.com",
"is_residential": null
},
"parcels": [
{
"object_id": "ec952343dd4843c39b42aca620471fd5",
"object_created": "2013-12-01T06:24:21.121Z",
"object_updated": "2013-12-01T06:24:21.121Z",
"object_owner": "shippotle@shippo.com",
"template": null,
"length":"5",
"width":"5",
"height":"5",
"distance_unit":"in",
"weight":"2",
"mass_unit":"lb",
"value_amount": null,
"value_currency": null,
"metadata": "",
"line_items": [],
"test": true
},
{
"object_id": "dbe0260bb2674c709fa45667cf353f27",
"object_created": "2013-12-01T06:24:21.121Z",
"object_updated": "2013-12-01T06:24:21.121Z",
"object_owner": "shippotle@shippo.com",
"template": null,
"length":"5",
"width":"5",
"height":"5",
"distance_unit":"in",
"weight":"2",
"mass_unit":"lb",
"value_amount": null,
"value_currency": null,
"metadata": "",
"line_items": [],
"test": true
}
],
"shipment_date": "2013-12-03T12:00:00.000Z",
"extra": {
"insurance": {
"amount": "",
"currency": ""
},
"reference_1": "",
"reference_2": ""
},
"customs_declaration": "",
"rates": [
{
"object_created": "2013-12-01T06:24:21.121Z",
"object_id": "545ab0a1a6ea4c9f9adb2512a57d6d8b",
"object_owner": "shippotle@shippo.com",
"shipment": "5e40ead7cffe4cc1ad45108696162e42",
"attributes": [],
"amount": "65.80",
"currency": "USD",
"amount_local": "65.80",
"currency_local": "USD",
"provider": "USPS",
"provider_image_75": "https://cdn2.goshippo.com/providers/75/USPS.png",
"provider_image_200": "https://cdn2.goshippo.com/providers/200/USPS.png",
"servicelevel": {
"name": "Ground",
"token": "fedex_ground",
"terms": ""
},
"days": 5,
"arrives_by": null,
"duration_terms": null,
"messages": [],
"carrier_account": "078870331023437cb917f5187429b093",
"test": false
},
...
],
"carrier_accounts": [],
"metadata": "Customer ID 123456",
"messages": []
}
How to retrieve labels for each package
You can purchase a multi-piece shipping rate by POSTing the Rate object_id
to the Transaction endpoint as usual. A separate transaction will be created for each parcel.
curl https://api.goshippo.com/transactions\
-H "Authorization: ShippoToken <API_Token>"\
-d rate="cf6fea899f1848b494d9568e8266e076"
-d label_file_type="PDF"
-d async=false
# Get the first rate in the rates results.
# Customize this based on your business logic.
rate = shipment.rates.first
# Purchase the desired rate.
transaction = Shippo::Transaction.create(
:rate => rate["object_id"],
:label_file_type => "PDF",
:async => false )
# label_url and tracking_number
if transaction["status"] == "SUCCESS"
puts "Label sucessfully generated:"
puts "label_url: #{transaction.label_url}"
puts "tracking_number: #{transaction.tracking_number}"
else
puts "Error generating label:"
puts transaction.messages
end
# Get the first rate in the rates results.
# Customize this based on your business logic.
rate = shipment.rates[0]
# Purchase the desired rate.
transaction = shippo.Transaction.create(
rate=rate.object_id,
label_file_type="PDF",
async=False )
# Retrieve label url and tracking number or error message
if transaction.status == "SUCCESS":
print transaction.label_url
print transaction.tracking_number
else:
print transaction.messages
// Get the first rate in the rates results.
// Customize this based on your business logic.
$rate = $shipment["rates"][0];
// Purchase the desired rate.
$transaction = Shippo_Transaction::create( array(
'rate' => $rate["object_id"],
'label_file_type' => "PDF",
'async' => false ) );
// Retrieve label url and tracking number or error message
if ($transaction["status"] == "SUCCESS"){
echo( $transaction["label_url"] );
echo("\n");
echo( $transaction["tracking_number"] );
}else {
echo( $transaction["messages"] );
}
// Get the first rate in the rates results.
// Customize this based on your business logic.
var rate = shipment.rates[0];
// Purchase the desired rate.
shippo.transaction.create({
"rate": rate.object_id,
"label_file_type": "PDF",
"async": false
}, function(err, transaction) {
// asynchronous callback
});
// Get the first rate in the rates results.
// Customize this based on your own business logic
Rate rate = shipment.ratesList[0];
HashMap<String, Object> transactionMap = new HashMap<String, Object>();
transactionMap.put("rate", rate.objectId);
transactionMap.put("async", false);
// Purchase the desired rate
Transaction transaction = Transaction.create(transactionParameters);
if (transaction.getStatus().equals("SUCCESS")) {
System.out.println(String.format("Label url : %s",
transaction.getLabelUrl()));
System.out.println(String.format("Tracking number : %s",
transaction.getTrackingNumber()));
} else {
System.out.println(String.format("An Error has occured while generating your label. Messages : %s",
transaction.getMessages()));
}
// Get the first rate in the rates results.
// Customize this based on your business logic.
Rate rate = shipment.RatesList[0];
Hashtable transactionParameters = new Hashtable();
transactionParameters.Add("rate", rate.ObjectId);
transactionParameters.Add("async", false);
// Purchase the desired rate.
Transaction transaction = resource.CreateTransaction(transactionParameters);
if (((String) transaction.Status).Equals("SUCCESS", StringComparison.OrdinalIgnoreCase){
Console.WriteLine("Label url: " + transaction.LabelURL);
Console.WriteLine("Tracking number: " +
transaction.TrackingNumber);
} else{
Console.WriteLine("Error generating label. Messages: " +
transaction.Messages);
}
You can also create multi-piece shipments in one API call. Check out our tutorial for single label call creation for more details.
The POST request returns the master Transaction object in the response. To get labels for all the parcels in the Shipment you need to filter for each parcel transaction.
-
The Transaction response after you've purchased the rate provides you with the master
tracking_number
of the entire Shipment and thelabel_url
for the first parcel of the Shipment. As an example, this label has the master tracking number on it incl. information about the status of the entire multi-piece shipment. -
To retrieve labels for the rest of the parcels in the Shipment, you need to make another GET request to the Transaction endpoint with the Rate
object_id
as the query parameter. These sample labels have both the master tracking number on it as well as their own parcel-specific tracking number.
Here's an example request:
curl https://api.goshippo.com/transactions/?rate=cf6fea899f1848b494d9568e8266e076\
-H "Authorization: ShippoToken <API_Token>"
require 'shippo'
Shippo::API.token = '<API_Token>'
transactions = Shippo::Transaction.all(rate: 'cf6fea899f1848b494d9568e8266e076')
import shippo
shippo.api_key = "<API_Token>"
transactions = shippo.Transaction.all(rate='cf6fea899f1848b494d9568e8266e076')
require_once('lib/Shippo.php');
Shippo::setApiKey("<API_Token>");
$transactions = Shippo_Transaction::all( array('rate' => 'cf6fea899f1848b494d9568e8266e076'));
var shippo = require('shippo')('<API_Token>');
shippo.transaction.list({
"rate": "cf6fea899f1848b494d9568e8266e076"
}, function(transactions) {
// asynchronously called
});
The API will respond with a JSON serialized list of the transactions that belong to this Rate. Each of these transactions belongs to exactly one parcel of the multi-piece shipment. Each transaction has a unique tracking_number
and label_url
field for it's associated parcel.
{
"count":5,
"next":null,
"previous":null,
"results":[
{
"object_state":"VALID",
"status":"SUCCESS",
"object_created":"2014-07-17T00:43:40.842Z",
"object_updated":"2014-07-17T00:43:50.531Z",
"object_id":"70ae8117ee1749e393f249d5b77c45e0",
"object_owner":"shippotle@shippo.com",
"was_test":true,
"rate":"ee81fab0372e419ab52245c8952ccaeb",
"tracking_number":"9499907123456123456781",
"tracking_status":{
"object_created":"2014-07-17T00:43:50.402Z",
"object_id":"907d5e6120ed491ea27d4f681a7ccd4d",
"status":"UNKNOWN",
"status_details":"",
"status_date":null
},
"tracking_url_provider":"https://tools.usps.com/go/TrackConfirmAction_input?origTrackNum=9499907123456123456781",
"eta":"2014-07-21T12:00:00.000Z",
"label_url":"https://shippo-delivery.s3.amazonaws.com/70ae8117ee1749e393f249d5b77c45e0.pdf?Signature=vDw1ltcyGveVR1OQoUDdzC43BY8%3D&Expires=1437093830&AWSAccessKeyId=AKIAJTHP3LLFMYAWALIA",
"commercial_invoice_url": "",
"messages":[
],
"metadata":""
},
{...},
{...}
]
}
If you have more than 5 transactions that belong to the Rate, the response will be paginated.
You can modify your request to increase the number of transactions per page.
Example:
https://api.goshippo.com/transactions/?results=10&rate=ee81fab0372e419ab52245c8952ccaeb
Or you can retrieve each page of the response listed in the 'next' parameter.
Example:
"next": https://api.goshippo.com/transactions/?rate=ee81fab0372e419ab52245c8952ccaeb&page=2
Parcel-level insurance
You can also purchase insurance for each package of the multi-piece shipment. This can be done through the extras attribute when creating your Parcel object within the Shipment request. Here is a sample request for a Shipment with different insurance amounts for each Parcel.
curl https://api.goshippo.com/shipment/\
-H "Authorization: ShippoToken <API_Token>"\
-H "Content-Type: application/json"\
-d '{
"address_from": "d799c2679e644279b59fe661ac8fa488",
"address_to": "42236bcf36214f62bcc6d7f12f02a849",
"parcels": [
{
"length": "5",
"width": "5",
"height": "5",
"distance_unit": "cm",
"weight": "2",
"mass_unit": "lb",
"template": "",
"metadata": "Box1",
"extra": {
"insurance": {
"amount": 25.00,
"currency": "USD",
"provider": "FEDEX"
}
}
},
{
"length": "5",
"width": "10",
"height": "15",
"distance_unit": "cm",
"weight": "6",
"mass_unit": "lb",
"template": "",
"metadata": "Box2",
"extra": {
"insurance": {
"amount": 50.00,
"currency": "USD",
"provider": "FEDEX"
}
}
},
{
"length": "2",
"width": "8",
"height": "9",
"distance_unit": "cm",
"weight": "5",
"mass_unit": "lb",
"template": "",
"metadata": "Box3",
"extra": {
"insurance": {
"amount": 45.00,
"currency": "USD",
"provider": "FEDEX"
}
}
}
],
"async": false
}
Handling shipment-level and parcel-level insurance
- If both shipment-level and parcel-level insurance are specified, the parcel-level insurance will take precedence. Parcels without parcel-level insurance will have the shipment-level insurance amount applied to that parcel.
- If only shipment-level insurance is specified, then the shipment insurance amount will be applied to each parcel -- not divide amongst parcels.
Parcel-level Collect on Delivery
UPS offer Collect on Delivery (COD) for individual parcels in a multi-piece shipment. You can specific your COD preference in the extras attribute of the Parcel object when creating your Shipment.