Site Logo

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:

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 HeaderDesription
Content-TypeThe 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.

HTTP HeaderDesription
API-KeyFor 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:

FieldValue
Delivery ServiceUPS Ground
Ship from addressJohn Doe
4301 Bull Creek Rd
Austin, TX 78731
+1 555-555-5555
Ship to addressJane Doe
525 S Winchester Blvd
San Jose, CA 95128
+1 444-444-4444
Package weight20 ounces
Package dimensions12 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. There are additional optional fields that are left out of this request, but it does have the minimum fields recommended for shipping a package. Notice that it contains all of the information listed above:

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
{
"shipment": {
"service_code": "ups_ground",
"ship_to": {
"name": "Jane Doe",
"phone": "+1 444-444-4444",
"address_line1": "525 S Winchester Blvd",
"city_locality": "San Jose",
"state_province": "CA",
"postal_code": "95128",
"country_code": "US",
"address_residential_indicator": "yes"
},
"ship_from": {
"name": "John Doe",
"company_name": "Example Corp",
"phone": "+1 555-555-5555",
"address_line1": "4301 Bull Creek Rd",
"city_locality": "Austin",
"state_province": "TX",
"postal_code": "78731",
"country_code": "US",
"address_residential_indicator": "no"
},
"packages": [
{
"weight": {
"value": 20,
"unit": "ounce"
},
"dimensions": {
"height": 6,
"width": 12,
"length": 24,
"unit": "inch"
}
}
]
}
}

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

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
POST /v1/labels HTTP/1.1
Host: api.shipengine.com
API-Key: __YOUR_API_KEY_HERE__
Content-Type: application/json
{
"shipment": {
"service_code": "ups_ground",
"ship_to": {
"name": "Jane Doe",
"phone": "+1 444-444-4444",
"address_line1": "525 S Winchester Blvd",
"city_locality": "San Jose",
"state_province": "CA",
"postal_code": "95128",
"country_code": "US",
"address_residential_indicator": "yes"
},
"ship_from": {
"name": "John Doe",
"company_name": "Example Corp",
"phone": "+1 555-555-5555",
"address_line1": "4301 Bull Creek Rd",
"city_locality": "Austin",
"state_province": "TX",
"postal_code": "78731",
"country_code": "US",
"address_residential_indicator": "no"
},
"packages": [
{
"weight": {
"value": 20,
"unit": "ounce"
},
"dimensions": {
"height": 6,
"width": 12,
"length": 24,
"unit": "inch"
}
}
]
}
}

Example Response

If your request was successful, you'll receive an HTTP 200 response that looks similar to this:

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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
{
"label_id": "se-396884371",
"status": "completed",
"shipment_id": "se-1080108982",
"ship_date": "2024-01-03T08:00:00Z",
"created_at": "2024-01-03T17:37:21.6482315Z",
"shipment_cost": {
"currency": "usd",
"amount": 17.58
},
"insurance_cost": {
"currency": "usd",
"amount": 0.0
},
"requested_comparison_amount": null,
"rate_details": [],
"tracking_number": "1ZYF85760394283643",
"is_return_label": false,
"rma_number": null,
"is_international": false,
"batch_id": "",
"carrier_id": "se-5904054",
"service_code": "ups_ground",
"package_code": "package",
"voided": false,
"voided_at": null,
"label_format": "pdf",
"display_scheme": "label",
"label_layout": "4x6",
"trackable": true,
"label_image_id": null,
"carrier_code": "ups",
"tracking_status": "in_transit",
"label_download": {
"pdf": "https://api.shipengine.com/v1/downloads/10/N7a1AuQIwk2PjYM2H2KVrA/label-396884371.pdf",
"png": "https://api.shipengine.com/v1/downloads/10/N7a1AuQIwk2PjYM2H2KVrA/label-396884371.png",
"zpl": "https://api.shipengine.com/v1/downloads/10/N7a1AuQIwk2PjYM2H2KVrA/label-396884371.zpl",
"href": "https://api.shipengine.com/v1/downloads/10/N7a1AuQIwk2PjYM2H2KVrA/label-396884371.pdf"
},
"form_download": null,
"qr_code_download": null,
"insurance_claim": null,
"packages": [
{
"package_id": 415397454,
"package_code": "package",
"weight": {
"value": 20.00,
"unit": "ounce"
},
"dimensions": {
"unit": "inch",
"length": 24.00,
"width": 12.00,
"height": 6.00
},
"insured_value": {
"currency": "usd",
"amount": 0.00
},
"tracking_number": "1ZYF85760394283643",
"label_download": {
"pdf": "https://api.shipengine.com/v1/downloads/10/HKNTqQS9yEq7rWuATnCSqQ/labelpackage-415397454.pdf",
"png": "https://api.shipengine.com/v1/downloads/10/HKNTqQS9yEq7rWuATnCSqQ/labelpackage-415397454.png",
"zpl": "https://api.shipengine.com/v1/downloads/10/HKNTqQS9yEq7rWuATnCSqQ/labelpackage-415397454.zpl"
},
"qr_code_download": null,
"label_messages": {
"reference1": null,
"reference2": null,
"reference3": null
},
"external_package_id": null,
"content_description": null,
"sequence": 1,
"alternative_identifiers": []
}
],
"charge_event": "carrier_default",
"alternative_identifiers": []
}

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

1
2
3
4
5
6
7
8
{
"label_download": {
"pdf": "https://api.shipengine.com/v1/downloads/10/XNGDhq7uZ0CAEt5LOnCxIg/label-7764944.pdf",
"png": "https://api.shipengine.com/v1/downloads/10/XNGDhq7uZ0CAEt5LOnCxIg/label-7764944.png",
"zpl": "https://api.shipengine.com/v1/downloads/10/XNGDhq7uZ0CAEt5LOnCxIg/label-7764944.zpl",
"href": "https://api.shipengine.com/v1/downloads/10/XNGDhq7uZ0CAEt5LOnCxIg/label-7764944.pdf"
}
}

The label download formats include:

FormatDescriptionUses
pdfAdobe PDF fileA common format that's supported by most printers. Also a good format for email attachments when sending shipping labels to customers.
pngPNG image filePNG images are great for embedding in emails, web pages, or mobile apps.
zplZebra Printer fileIf 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:

1
curl -iOX GET __YOUR_LABEL_URL_HERE__

Congratulations! You've now downloaded a label!

Cancel a Label

We all make mistakes - or maybe something about the package changes after you've created your label! When these things happen you may want to cancel or void the label you've created. Check out our guide on voiding a label to learn more.

Advanced Features

Review the options below for ways to improve your label flow.

Ship Engine has three other ways to create 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.