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.
Key | Type | Required | Description |
---|---|---|---|
isDefault | boolean | required | A 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. |
name | string | optional | A 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. |
originAddress | object | required | The address from which the parcel is being shipped. See here |
returnAddress | object | optional | The 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
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
SDK
Args/Props | Type | Required? | Description |
---|---|---|---|
externalOrderId | string | optional | The order ID used by an external order source (PayPal, Shopify, eBay, etc.) |
externalOrderNumber | string | optional | The order number used by an external order source (PayPal, Shopify, eBay, etc.) |
features | object | optional | A set of features to be enabled or disabled. See Purchase Label Features for a comprehensive list of configurable features. |
orderSourceCode | string | optional | The API code used to identify the type of Order Source. |
salesOrderId | string | optional | The 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. |
shipmentId | string | optional | The ShipEngine Shipment ID used to identify the shipment. |
externalShipmentId | string | optional | A 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. |
printLabelLayout | string | optional | A string that represents the label layout you would like to use when purchasing a label. Example: 4x6 |
warehouseId | string | optional | A string that represents a previously configured warehouse you would like to use as the Ship From Address when purchasing a label. |
shipFromAddresses | array | optional | An 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. |
harmonizedTariffCodes | array | optional | An 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 }] |
onAddressValidation | function | optional | An 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. |
onBeforeLabelCreate | function | optional | An optional async/sync callback function that will be invoked before every label purchase. |
onBeforeRateSaved | function | optional | An optional async/sync callback function that will be invoked before each time a user saves a rate. |
onChangeAddress | function | optional | An optional async/sync callback function that will be invoked each time a Ship To Address or Ship From Address has been updated. |
onLoad | function | optional | An optional async/sync callback provided by the host application that is invoked after the element is loaded. |
onLabelCreateSuccess | function | optional | An optional async/sync callback provided by the client that is invoked if the label is successfully created/purchased. |
onLabelCreateFailure | function | optional | An optional async/sync callback function that will be invoked each time a label purchase fails. |
onRateSaved | function | optional | An optional async/sync callback function that will be invoked each time a rate is saved by the user when rate shopping. |
onRatesCalculated | function | optional | An optional async/sync callback function that will be invoked each time rates are calculated for a given shipment. |
onShipmentUpdated | function | optional | An 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.
Feature | Type | Description |
---|---|---|
compatibleCountryCodes | string[] | A list of all supported countries available in ShipEngine Elements. |
enableErrorWhenShipmentCancelled | boolean | disabled by default When enabled will modify the default behavior of creating a new shipment for a sales order to throwing an error. |
disabledShippingServices | Record<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. |
betaEnableWindsorFramework | boolean | disabled 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:
Shipment Form Features
Feature | Description |
---|---|
addOns | enabled by default Enables the add ons feature. This allows users to add additional services to a shipment such as insurance and delivery confirmation. |
browseRates | enabled by default Enables the browse rates feature. This allows users to browse rates for a shipment with varying shipment configurations. |
includeCarrierInsurance | disabled by default Enables the carrier insurance feature, allowing users to select insurance provided by the carrier when insuring their shipment. |
includeThirdPartyInsurance | disabled 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. |
selectService | enabled by default Enables the select service feature, allowing users to select a service when rate shopping across multiple carrier providers. |
shippingPresets | disabled 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. |
useWarehouses | enabled 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
Feature | Description |
---|---|
enableFunding | enabled by default Enables the funding section of the rate form. |
enablePudoUI | disabled 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. |
labelLayout | disabled by default Enables the feature to allows users to pick their desired label layout. |
nicknameRate | enabled by default Enables showing the carrier nickname when rates are fetched. |
requireDhlTermsAcknowledgement | disabled by default Enables the DHL terms acknowledgement when rates are fetched. |
saveRate | enabled 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.