Getting started overview
This guide outlines the essential steps for developers to begin using the EasyPost API. It covers account creation, obtaining API credentials, and executing a foundational API request to generate a shipping label. EasyPost provides a unified interface for integrating with multiple shipping carriers, enabling programmatic access to services such as rate shopping, label generation, and package tracking [1].
The primary goal for initial setup is to successfully make an authenticated API call that returns a valid response, often involving the creation of a test shipping label. EasyPost offers client libraries (SDKs) in several programming languages to streamline integration [1]. For this guide, we will focus on the general API interaction principles that apply across these SDKs.
Quick reference table
| Step | What to do | Where |
|---|---|---|
| 1. Create Account | Register for an EasyPost developer account. | EasyPost homepage |
| 2. Get API Keys | Locate your Sandbox and Production API keys in the dashboard. | EasyPost Dashboard > API Keys |
| 3. Install SDK (Optional but Recommended) | Install the EasyPost client library for your chosen language. | EasyPost documentation > SDKs |
| 4. Configure Client | Initialize the SDK or set up HTTP client with your Sandbox API key. | Your development environment |
| 5. Make First Request | Send a request to create a test shipping label. | Your development environment |
| 6. Verify Response | Confirm a successful API response and label creation. | Your development environment / EasyPost Dashboard |
Create an account and get keys
Access to the EasyPost API requires an account. This account provides the necessary API keys for authentication and access to the EasyPost dashboard for managing shipments, tracking, and billing.
- Sign up for an EasyPost account: Navigate to the EasyPost website and complete the registration process. This typically involves providing an email address and creating a password.
- Access API Keys: Once logged in to your EasyPost dashboard, locate the API Keys section. EasyPost distinguishes between two types of keys:
- Test (Sandbox) Keys: Used for development and testing purposes. Requests made with these keys do not incur charges and simulate real transactions without actually creating live shipments.
- Production (Live) Keys: Used for live applications and actual shipping. Requests made with production keys will result in charges and generate real shipping labels.
TestAPI key [2]. - Secure your API Keys: Treat your API keys as sensitive credentials. Do not hardcode them directly into your application code, commit them to public version control systems, or expose them in client-side code. Best practices include using environment variables or a secure configuration management system to store and access keys [3].
Your first request
The objective of your first request is to generate a test shipping label. This demonstrates successful authentication and interaction with the core shipping functionality of the EasyPost API. This example uses a generic structure, assuming you've installed an EasyPost SDK or are making direct HTTP requests.
Prerequisites
- An EasyPost account with access to your Test API key.
- A development environment with your preferred programming language.
- (Recommended) The EasyPost SDK for your chosen language installed. For example, in Python:
pip install easypost.
Example code: shipping label creation
The following conceptual code demonstrates the process. Specific syntax will vary based on the SDK and language used. This example shows the creation of an Address, Parcel, and finally a Shipment object, which encompasses all details required for a label.
import easypost
easypost.api_key = "YOUR_TEST_API_KEY" # Replace with your actual Test API Key
# 1. Create 'From' and 'To' Addresses
from_address = easypost.Address.create(
street1='179 N Moorpark Rd',
city='Thousand Oaks',
state='CA',
zip='91360',
country='US',
company='EasyPost',
phone='805-443-4400',
name='EasyPost Support',
)
to_address = easypost.Address.create(
street1='417 Montgomery St',
city='San Francisco',
state='CA',
zip='94104',
country='US',
company='EasyPost',
phone='415-456-7890',
name='Dr. Steve Brule',
)
# 2. Create a Parcel
parcel = easypost.Parcel.create(
length=20.2,
width=10.9,
height=5,
weight=65.9,
)
# 3. Create a Shipment
# Specify desired carriers or let EasyPost rate shop
shipment = easypost.Shipment.create(
to_address=to_address,
from_address=from_address,
parcel=parcel,
carrier_accounts=['ca_YOUR_CARRIER_ACCOUNT_ID'] # Optional: Specify a carrier account
)
# 4. Buy the cheapest rate (or a specific rate)
# This step generates the label
shipment.buy(rate=shipment.lowest_rate())
# 5. Print the label URL and tracking code
print(f"Label URL: {shipment.postage_label.label_url}")
print(f"Tracking Code: {shipment.tracking_code}")
Explanation of steps:
- Set API Key: Your test API key authenticates your request.
- Create Addresses: Define the sender (
from_address) and recipient (to_address) details. This is crucial for accurate rating and delivery. - Create Parcel: Define the physical dimensions and weight of the package. These attributes directly influence shipping rates.
- Create Shipment: Combine the addresses and parcel into a
Shipmentobject. At this stage, EasyPost will retrieve available rates from configured carriers. You can optionally specify acarrier_accountsarray if you have specific carrier accounts linked. - Buy Shipment: Select a rate (e.g., the
lowest_rate()) and purchase the label. This action finalizes the shipment and generates a postage label. - Retrieve Label Data: The resulting
shipmentobject will contain apostage_labelwith alabel_url(typically a PDF) and atracking_code.
Upon successful execution, you should receive a URL to a test shipping label and a tracking code. You can verify this label in your EasyPost dashboard under the Shipments section [1].
Common next steps
After successfully generating your first test label, consider these common next steps to further integrate with EasyPost:
- Explore other APIs: EasyPost offers various APIs beyond shipping labels, including Tracking API, Rating API, and Address Verification API. Integrate these to enhance your application's functionality.
- Integrate with real carrier accounts: Link your actual carrier accounts (e.g., UPS, FedEx, USPS) within the EasyPost dashboard to get live rates and generate real labels.
- Implement webhooks: Set up webhooks to receive real-time notifications about shipment status changes, tracking updates, and other events. This is a common pattern for asynchronous API interactions [4].
- Error handling: Implement robust error handling mechanisms to gracefully manage API failures, invalid inputs, and other potential issues.
- Go live: Once your integration is thoroughly tested with sandbox keys, switch to your production API keys to begin processing live shipments.
- Review pricing: Understand the EasyPost pricing model, which typically involves a free tier followed by pay-as-you-go per label/transaction, with volume discounts available.
Troubleshooting the first call
Encountering issues during your first API call is common. Here are some troubleshooting tips:
- Incorrect API Key: Double-check that you are using your
TestAPI key, not your Production key, and that it is correctly copied without extra spaces. EasyPost API keys typically start withEZAT...for test andEZAA...for production [2]. - Missing Required Parameters: Ensure all mandatory fields for creating addresses, parcels, and shipments are provided. Refer to the EasyPost API reference for exact requirements.
- Invalid Data Formats: Verify that data types (e.g., strings for names, numbers for weight) and formats (e.g., valid ZIP codes, country codes) match API expectations.
- Network Issues: Confirm your development environment has internet connectivity and can reach the EasyPost API endpoints.
- SDK Configuration: If using an SDK, ensure it's correctly installed and initialized with your API key. Consult the specific SDK documentation for setup instructions.
- Carrier Account Issues: If you are specifying a
carrier_accountsID, ensure it is valid and correctly linked in your EasyPost dashboard. For initial tests, omitting this parameter allows EasyPost to rate shop with any default carriers. - Review EasyPost Dashboard Logs: The EasyPost dashboard often provides detailed logs of API requests and responses, which can help diagnose issues.
- Consult EasyPost Documentation: The official EasyPost documentation is a comprehensive resource for API details, error codes, and examples.