ON THIS PAGE
What is UPS?
UPS (United Parcel Service) is a global shipping and logistics company that provides parcel delivery, freight transportation, and supply chain management services. UPS is one of the world’s largest and most trusted shipping carriers, known for its fast and reliable delivery services.
UPS offers various shipping options, including ground, air, and international shipping, and provides businesses with tools like tracking, shipping rate calculation, and API integrations to support businesses.
How to Get Shipping Rates Using UPS API (XML & REST)?
UPS provides two primary methods for retrieving shipping rates: the UPS XML API and the UPS REST API. The XML API is an older method that requires an Access Key, Username, and Password for authentication, while the REST API is a modern alternative that uses OAuth 2.0 authentication. Both methods allow businesses to calculate shipping costs based on package details, weight, and destination.
Problem Statement
XML and REST APIs allow you to fetch UPS shipping rates, but REST is more modern and preferred for new applications. If you’re integrating with an older system, XML might still be necessary.
Businesses need a way to get accurate UPS shipping rates for their packages. UPS offers two APIs XML and REST but they work differently.
Picking the right one and setting it up correctly can be tricky. The goal is to find the best option for easy and simplifying shipping cost calculations for smooth operations.
Integrating UPS Shipping Rates: XML vs. REST API
When integrating UPS shipping rates into your application, you have two options:
- UPS XML API – Uses XML requests and requires an Access Key.
- UPS REST API – Uses JSON and requires OAuth 2.0 authentication.
1. Getting Started with UPS API
Before making requests, you need:
- A UPS Developer Account → Register Here
- API credentials (Access Key, Username, Password for XML or Client ID, Secret for REST)
- The correct API Endpoint (Testing vs. Production)
2. Using UPS XML API for Rates
API Endpoints:
- Sandbox (Testing): https://wwwcie.ups.com/ups.app/xml/Rate
- Production: https://onlinetools.ups.com/ups.app/xml/Rate
To use the UPS XML API, send an XML request to the appropriate endpoint, either sandbox (https://wwwcie.ups.com/ups.app/xml/Rate) for testing or production (https://onlinetools.ups.com/ups.app/xml/Rate) for live shipping rates.
The request includes shipment details such as the shipper’s address, recipient’s address, package weight, and service type (e.g., UPS Ground, UPS 2nd Day Air, UPS Next Day Air, etc.).
The API responds with an XML-formatted shipping rate, which must be parsed to extract the required information. The XML method is widely used in legacy systems but requires handling complex XML structures.
Example XML Request
<AccessRequest>
<AccessLicenseNumber>YOUR_ACCESS_KEY</AccessLicenseNumber>
<UserId>YOUR_USERNAME</UserId>
<Password>YOUR_PASSWORD</Password>
</AccessRequest>
<RatingServiceSelectionRequest>
<Request>
<RequestAction>Rate</RequestAction>
<RequestOption>Shop</RequestOption>
</Request>
<Shipment>
<Shipper>
<Address>
<PostalCode>10001</PostalCode>
<CountryCode>US</CountryCode>
</Address>
</Shipper>
<ShipTo>
<Address>
<PostalCode>90001</PostalCode>
<CountryCode>US</CountryCode>
</Address>
</ShipTo>
<Package>
<PackagingType>
<Code>02</Code>
</PackagingType>
<PackageWeight>
<Weight>10</Weight>
</PackageWeight>
</Package>
</Shipment>
</RatingServiceSelectionRequest>
Note: “RequestOption”: “Shop” returns multiple shipping rates.
3. Using UPS REST API for Rates
On the other hand, the UPS REST API provides a modern and flexible way to retrieve shipping rates using JSON-based requests.
Before calling the rate API, authenticate using OAuth 2.0 by sending a POST request to https://onlinetools.ups.com/security/v1/oauth/token with your client ID and client secret.
The response contains an access token, which must be included in subsequent API requests as a Bearer token. The REST API allows you to send a JSON request containing shipment details to the sandbox (https://wwwcie.ups.com/api/rating/) or production (https://onlinetools.ups.com/api/rating/) endpoint.
The response returns the available shipping services along with their respective rates in a structured JSON format, making it easier to parse and integrate into modern web applications.
Step 1: Get OAuth Token
First, authenticate using OAuth 2.0.
OAuth Request
POST: https://onlinetools.ups.com/security/v1/oauth/token
Content-Type: application/x-www-form-urlencoded
Body:
grant_type=client_credentials
&client_id=YOUR_CLIENT_ID
&client_secret=YOUR_CLIENT_SECRET
Step 2: Request Shipping Rates
API Endpoints:
- Sandbox: https://wwwcie.ups.com/api/rating/
- Production: https://onlinetools.ups.com/api/rating/
Example JSON Request
{
"RateRequest": {
"Shipment": {
"Shipper": { "Address": { "PostalCode": "10001", "CountryCode": "US" } },
"ShipTo": { "Address": { "PostalCode": "90001", "CountryCode": "US" } },
"Package": [{ "PackagingType": { "Code": "02" }, "PackageWeight": { "Weight": "10" } }]
}
}
}
Key Differences: XML vs. REST API
The key differences between XML and REST APIs are in their authentication, request format, and response format. While the XML API relies on a static Access Key, Username, and Password, the REST API uses OAuth 2.0, which provides a more secure way to manage authentication. Additionally, XML requires more complex parsing, whereas JSON in the REST API is more readable and easier to work with.
The REST API is recommended for new implementations, while the XML API is still supported for backward compatibility. Businesses integrating UPS shipping rates into their ecommerce platforms, order management systems, or logistics applications should choose the API method that best suits their technological stack and security requirements.
Feature | XML API | REST API |
Authentication | API Key, Username, Password | OAuth 2.0 |
Request Format | XML | JSON |
Response Format | XML | JSON |
Sandbox URL | https://wwwcie.ups.com/ups.app/xml/Rate | https://wwwcie.ups.com/api/rating/ |
Production URL | https://onlinetools.ups.com/ups.app/xml/Rate | https://onlinetools.ups.com/api/rating/ |
Conclusion
Choosing between the UPS XML API and REST API depends on your system’s needs. The REST API is recommended for modern applications due to its secure OAuth authentication and easy-to-use JSON format, while the XML API remains useful for legacy systems. Selecting the right API ensures accurate shipping rate calculations and seamless logistics integration.Contact Klizer, an ecommerce development agency as well as for ecommerce QA services, If you need any assistance with strategizing businesses your shipping rates using UPS API.