Create a Shipping Label
ShipEngine is a REST API that allows you to manage almost every facet possible for shipping. This tutorial will show you how to create a label.
Before you begin:
- Sign up for a ShipEngine account, if you haven't already.
- You'll need an API key (a sandbox API key will work for this tutorial)
- You'll need a tool to make an API call, like curl or Postman.
Creating a shipping label requires the following steps:
In the example below, you'll request a label using the UPS account that's included with your ShipEngine account. The general steps are the same, regardless of which carrier you use.
Step 1: Prepare Your Request
API Endpoint
To create a label, you'll need to send an HTTP POST
request to https://api.shipengine.com/v1/labels
.
From now on we'll refer to this as the /v1/labels
API endpoint to keep things short.
Headers
There are two HTTP headers that you need to set in your request:
HTTP Header | Desription |
---|---|
Content-Type | The Content-Type header specifies the media type of your API request. |
ShipEngine requires all requests to be in JSON format, so this header should always be set to application/json
.
| API-Key
| For this header you'll need to pass your ShipEngine API key. This is how ShipEngine knows who you are.
If you don't have an API key yet, then read our Getting Started guide to learn how to create one.
Request Body
The body of your HTTP request is where you'll specify all the information about the shipping label that you want to create, such as the "from" and "to" addresses, the package weight and dimensions, etc.
For this tutorial, we'll create a label with the following criteria:
Field | Value |
---|---|
Delivery Service | UPS Ground |
Ship from address | John Doe 4301 Bull Creek Rd Austin, TX 78731 555-555-5555 |
Ship to address | Jane Doe 525 S Winchester Blvd San Jose, CA 95128 |
Package weight | 20 ounces |
Package dimensions | 12 x 24 x 6 inches |
As we mentioned above, ShipEngine requires all requests to be in JSON format.
Example Request
Here's what our label request body will look like. Notice that it contains all of the information listed above:
Step 2: Sending the Request
Now we'll take everything we talked about in Step 1 and put it all together using curl. Notice the example below uses everything we talked about in Step 1:
- Makes a POST call to
https://api.shipengine.com/v1/labels
- Sets the content type header to
application/json
- Sets the API Key to your ShipEngine API Key
- Uses the Request Body of the sample
json
code from above
Paste the following curl example into your Terminal (if you are not familiar with using curl, please review our page on how to use curl):
Example Request
Example Response
If your request was successful, you'll receive an HTTP 200 response that looks similar to this:
Notice that this response includes the following:
- Status: completed
- Label cost
- A link to download the label
- Service type
- Package type
- Label size, and
- Tracking number
Step 3: Download the Label
At the end of Step 2, you received an HTTP response that included the label details. Among those details are some URLs to download the label in various formats:
Example Label URLs
The label download formats include:
Format | Description | Uses |
---|---|---|
pdf | Adobe PDF file | A common format that's supported by most printers. Also a good format for email attachments when sending shipping labels to customers. |
png | PNG image file | PNG images are great for embedding in emails, web pages, or mobile apps. |
zpl | Zebra Printer file | If you print labels using a Zebra Printer, then ZPL is probably the best file format to use. |
These URLs are just like any other URLs, in that you can paste them into a browser to download the file. You can also download the label using curl.
Copy the curl request below and replace the __YOUR_LABEL_URL_HERE__
placeholder with the URL of the label format you wish to download:
Congratulations! You've now downloaded a label!
Advanced Options
Review the options below for ways to improve your label flow.
Ship Engine has three other ways to download labels
Request and Download In One Call
In the example above, two API requests were necessary: one to create the label, and another to download the .pdf
file.
You can accomplish both steps in a single request by setting label_download_type: "inline"
. See Download a Label for more details.
Create Return Label with Outgoing Label
You can create return labels by setting is_return_label
to true
. See our Return Shipping Labels page for more details.
Create Branded Labels
Learn how to customize your labels to print with your brand's logo or other images and see which carriers support this feature in our Create Custom Shipping Labels article.
Add Messages to the Labels
Show your customers an additional level of care and detail by adding a personal or customized message. Custom Label Messages article.