Site Logo

🎉 ShipEngine is becoming ShipStation API 🎉

Over the next few months you'll notice the ShipEngine website, documentation portal, and dashboard being rebranded as ShipStation API. For our ShipEngine customers, you don't need to take any action or change any of your integrations in any way. All endpoints will remain the same and continue to function as they always have.

To learn more about what's coming, review our New ShipStation API page.

Purchase Label Element

The Purchase Label Element is a versatile UI component designed to streamline the process of creating and purchasing shipping labels. It provides a comprehensive solution that includes:

  • Address validation: Validate domestic and international addresses so your users have confidence their package will arrive at the correct destination.
  • Address parsing: Allow users to paste complete addresses and autocomplete the ship-to-address form.
  • Rate shopping: Get shipping rates from multiple carriers and let your users choose the fastest, cheapest, or most-trusted option when shipping their products.

Before you get started

Before implementing the Purchase Label Element, there are important prerequisites and requirements to consider.

Shipping Carriers

Before your users can start shipping with the Purchase Label Element, they must create ShipEngine carrier accounts or have pre-existing carrier accounts registered with ShipEngine. Using the Onboarding Element will allow your users to register new ShipEngine carrier accounts easily. Check out the Onboarding Element to learn more about registering ShipEngine carriers.

If your users already have pre-configured carrier accounts, check out the External Carriers Element to learn more about linking external carriers to use in the Purchase Label Element.

Shipments

The Shipment object is used throughout the label purchase process. Shipments are the source of truth the Purchase Label Element uses to read and write the information necessary to purchase shipping labels. Shipping information like ship-to and ship-from addresses, package dimensions, and insurance are just some of the entities stored in a shipment object. A complete understanding of shipments is not required to use the Purchase Label Element, but it can be beneficial when debugging. Check out the full shipment documentation for more details.

Ship From locations

To create shipments, you must define the address your shipment is originating from (home, office, warehouse, or anywhere with a valid address). This can be done by either setting the desired ship-from address or passing a warehouse ID in the request body when creating a shipment. It's important to note that a ship-from address or a valid warehouse ID is required to create a new shipment.

When providing a ship-from address, keep the following in mind:

  • The name property must contain a first and last name, each being at least two characters long.
  • If you include a company name, it must also be at least two characters long.
KeyTypeRequiredDescription
isDefaultbooleanrequiredA boolean value used to flag an address as default. The default address is used during one-off shipment creation and auto-selected in the element's ship-from address drop-down.
namestringoptionalA friendly name used to identify the address within the element's ship-from address drop-down. If a name isn't provided, the addressLine1 will be used in the drop-down.
originAddressobjectrequiredThe address from which the parcel is being shipped. See here
returnAddressobjectoptionalThe address for returning the parcel in case of transit issues. If no address is provided, the origin address will serve as the return address. See here

Example Ship From Address

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const shipFromAddresses = [
{
name: "The Mayor's Office",
isDefault: true,
originAddress: {
addressLine1: '301 W 2nd St',
cityLocality: 'Austin',
countryCode: 'US',
name: 'Kirk Watson',
phone: '(512) 974-2000',
postalCode: '78701',
stateProvince: 'TX',
},
returnAddress: {
addressLine1: '4301 Bull Creek Rd',
cityLocality: 'Austin',
countryCode: 'US',
name: 'Al Ko',
phone: '(512) 886-4006',
postalCode: '78731',
stateProvince: 'TX',
},
},
];

Warehouses

A warehouse is a colloquial term ShipEngine uses to refer to saved ship-from locations. Each new warehouse created comes with a unique ID used to reference a saved ship-from address during the creation of a shipment and throughout shipment configuration within the element. Setting the warehouse_id field to a valid warehouse ID in the shipment creation request body will create a new shipment with that warehouse's origin and return address. To learn more about warehouses, check out the full warehouse documentation. If you plan on using the Onboarding Element, a warehouse will automatically be created for your users.

Create a Purchase Label Element

While implementing the Purchase Label Element it is important to consider how the Element will fit into your platform and how you plan on hydrating the Element with Shipment data. It is also important to decide how your platform will manage the ship from locations used inside of the the Purchase Label Element.

To hydrate the Purchase Label Element with shipment data, you can provide a shipmentId, externalShipmentId, or salesOrderId. The Element will create an unassociated one-off shipment if you do not provide an entity ID.

If you plan on using Sales Orders to power the Purchase Label Element, it's important to note that while ShipEngine Sales Orders have a one-to-many relationship with shipments, the Purchase Label Element can handle only one shipment at a time. We recommend limiting one shipment to each Sales Order.

The Purchase Label Element will check for any corresponding pending shipments, indicating that these shipments are eligible for purchase. The Element will create a new shipment if no shipments are associated with the provided salesOrderId.

Check out the Shipment Summary Element for more information about viewing shipments with active or voided labels.

During the one-off Shipment creation process, the Element will first look for any addresses passed to the Element via the shipFromAddresses prop or argument. If none are present, the Element will use the ShipEngine warehouse associated with the ID passed to the warehouseID prop or argument. If all else fails, the Element will use a ShipEngine warehouse saved on the user's ShipEngine account.

If you decided on passing in you own ship-from addresses to the Purchase Label Element make sure that the addresses are of the correct type.

React Component

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { PurchaseLabel, ElementsProvider } from '@shipengine/elements';
import { themeConfig } from '../themeConfig';
import { shipFromAddresses } from '../shipFromAddresses'
const tokenPath = '/path/to/token/endpoint';
const Foo = ({ shipments }) => {
const [selectedShipment, setSelectedShipment] = useState();
const getToken = useCallback(() => {
return fetch(tokenPath).then((res) => res.text());
}, []);
return (
<ElementsProvider
getToken={getToken}
themeConfig={themeConfig}
onError={handleError}
features={{
globalFeatures: {
enabledShipEngineCarriers: ['ups', 'stamps_com'],
enabledExternalCarriers: [
'apc',
'asendia',
'better_trucks',
'courierpost',
'dpd',
'seko',
'ups',
'yodel',
],
poweredByShipEngine: true
},
purchaselabelFeatures: {
rateForm: { enableFunding: true },
shipmentForm: { shippingPresets: true },
}
}}
>
<ul>
{shipments.map((shipment) => (
<li>
<button onClick={() => setSelectedShipment(shipment)}>
Order #{shipment.`shipmentId`}
</button>
</li>
))}
</ul>
{selectedShipment && (
<PurchaseLabel.Element
onLabelCreateSuccess={() => {
console.log('Success!');
}}
printLabelLayout={
'letter' // '4x6'
}
shipmentId={shipmentId}
shipFromAddresses={shipFromAddresses}
/>
)}
</ElementsProvider>
);
};

SDK

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Creates a new instance of the Elements SDK.
const elements = new ElementsSDK(
getToken,
{
onError: (err: Error) => console.error(err),
themeConfig: themeConfig,
locale: 'en-US',
features: {
globalFeatures: {
enabledShipEngineCarriers: ['ups', 'stamps_com'],
enabledExternalCarriers: [
'apc',
'asendia',
'better_trucks',
'courierpost',
'dpd',
'seko',
'ups',
'yodel',
],
},
purchaselabelFeatures: {
rateForm: { enableFunding: true },
shipmentForm: { shippingPresets: true },
}
}
}
);
const purchaseLabel = elements.create('purchaseLabel', {
onLabelCreateSuccess: () => console.log('Success!'),
printLabelLayout: {
'letter' // '4x6'
},
shipmentId: "se-103889776",
shipFromAddresses
});
Args/PropsTypeRequired?Description
externalOrderIdstringoptionalThe order ID used by an external order source (PayPal, Shopify, eBay, etc.)
externalOrderNumberstringoptionalThe order number used by an external order source (PayPal, Shopify, eBay, etc.)
featuresobjectoptionalA set of features to be enabled or disabled. See Purchase Label Features for a comprehensive list of configurable features.
orderSourceCodestringoptionalThe API code used to identify the type of Order Source.
salesOrderIdstringoptionalThe ShipEngine Sales Order ID is used to identify the order. The purchase label element will create a shipment from the information in the sales order provided.
shipmentIdstringoptionalThe ShipEngine Shipment ID used to identify the shipment.
externalShipmentIdstringoptionalA unique external ID applied on creation of a shipment that is used to identify that shipment. A new one-off shipment will be created if a shipment can't be found by the provided external Id.
printLabelLayoutstringoptionalA string that represents the label layout you would like to use when purchasing a label. Example: 4x6
warehouseIdstringoptionalA string that represents a previously configured warehouse you would like to use as the Ship From Address when purchasing a label.
shipFromAddressesarrayoptionalAn an array of address objects that contain the ship from and return to addresses to be used when purchasing a label. This can be used in lieu of a warehouseId if initializing the Purchase Label Element without a pre-existing shipment or sales order.
harmonizedTariffCodesarrayoptionalAn array of objects that contain the Harmonized Tariff Codes and descriptions used to populate the HS Codes dropdown within the Customs Form, [{ code: string, description: string }]
onAddressValidationfunctionoptionalAn optional async/sync callback function that will be invoked on each Address validation request. For example, whenever you update the Ship To Address or Ship From Address for a given shipment.
onBeforeLabelCreatefunctionoptionalAn optional async/sync callback function that will be invoked before every label purchase.
onBeforeRateSavedfunctionoptionalAn optional async/sync callback function that will be invoked before each time a user saves a rate.
onChangeAddressfunctionoptionalAn optional async/sync callback function that will be invoked each time a Ship To Address or Ship From Address has been updated.
onLoadfunctionoptionalAn optional async/sync callback provided by the host application that is invoked after the element is loaded.
onLabelCreateSuccessfunctionoptionalAn optional async/sync callback provided by the client that is invoked if the label is successfully created/purchased.
onLabelCreateFailurefunctionoptionalAn optional async/sync callback function that will be invoked each time a label purchase fails.
onRateSavedfunctionoptionalAn optional async/sync callback function that will be invoked each time a rate is saved by the user when rate shopping.
onRatesCalculatedfunctionoptionalAn optional async/sync callback function that will be invoked each time rates are calculated for a given shipment.
onShipmentUpdatedfunctionoptionalAn optional async/sync callback function that will be invoked each time a shipment is updated with a new ShipTo/ShipFrom Address, rate, preset, etc.

Purchase Label Features

Features are optional configuration keys used to customize the Purchase Label experience.

FeatureTypeDescription
compatibleCountryCodesstring[]A list of all supported countries available in ShipEngine Elements.
enableErrorWhenShipmentCancelledbooleandisabled by default When enabled will modify the default behavior of creating a new shipment for a sales order to throwing an error.
disabledShippingServicesRecord<string, string[]>disabled by default Allows hiding specific shipping services by carrier. Rates will not be returned for the given services. Records should be in the form { "carrier_code": ["service_code1", "service_code2"] } See detailed example below.
betaEnableWindsorFrameworkbooleandisabled by default Enables or disables additional fields for shipping from Great Britain to Northern Ireland required by the Windsor Framework.

To disable GlobalPost rates from appearing in the PurchaseLabel element, format the disabledShippingServices property as follows. Since GlobalPost rates may appear on both usps and stamps_com carriers, both carriers are included in the property:

1
2
3
4
5
6
7
8
9
10
11
12
13
{
"disabledShippingServices": {
"usps" : [
"globalpost_economy",
"globalpost_priority",
"gp_plus" ],
"stamps_com" : [
"globalpost_economy",
"globalpost_priority",
"gp_plus"
]
}
}

Shipment Form Features

FeatureDescription
addOnsenabled by default Enables the add ons feature. This allows users to add additional services to a shipment such as insurance and delivery confirmation.
browseRatesenabled by default Enables the browse rates feature. This allows users to browse rates for a shipment with varying shipment configurations.
includeCarrierInsurancedisabled by default Enables the carrier insurance feature, allowing users to select insurance provided by the carrier when insuring their shipment.
includeThirdPartyInsurancedisabled by default Enables the third party insurance feature, allowing users to indicate the package is insured by a third-party insurance service. Using this value does not add insurance to a shipment. Use this option if you have your own parcel insurance account and wish to identify packages insured externally for reporting purposes.
selectServiceenabled by default Enables the select service feature, allowing users to select a service when rate shopping across multiple carrier providers.
shippingPresetsdisabled by default Enables the shipping presets feature, allowing users to pass in a set of shipping presets they wish to use within the shipment form of the Purchase Label Element.
useWarehousesenabled by default When disabled the Purchase Label element will not use the Seller's saved warehouses during Shipment creation or expose the warehouses in the ship from drop down.

Rate Form Features

FeatureDescription
enableFundingenabled by default Enables the funding section of the rate form.
enablePudoUIdisabled by default Overrides the default rate list and enables a Pick Up Drop Off (PUDO)-specific interaction. Allows your customers to browse and select service points in both a list and map view.
labelLayoutdisabled by default Enables the feature to allows users to pick their desired label layout.
nicknameRateenabled by default Enables showing the carrier nickname when rates are fetched.
requireDhlTermsAcknowledgementdisabled by default Enables the DHL terms acknowledgement when rates are fetched.
saveRateenabled by default Enables the save rate button in the rate form. This allows users to save a rateId for a shipment to be purchased later.

For an in depth overview of the global features object, please review the Configuring Elements Features step in either the ElementsProvider or the Elements SDK guides.

1