Integrating USPS Domestic Shipping Rates API into Optimizely Configured Commerce

USPS Shipping API
Integrating USPS Domestic Shipping Rates API into Optimizely Configured Commerce
Sahil Rajaram
Sahil Majalkar

Senior Software Engineer - Optimizely

June 27, 2025

AI-Driven Enterprise Chatbot Implementation

Introduction

Optimizely Configured Commerce provides powerful out-of-the-box (OOTB) capabilities for eCommerce businesses. However, when it comes to shipping carrier integrations, it only natively supports FedEx and UPS. For organizations relying on the United States Postal Service (USPS) for domestic deliveries, this limitation poses a real challenge—until now.

What Issue We Faced?

Optimizely Configured Commerce does not support USPS integration out-of-the-box. Businesses relying on USPS for competitive domestic shipping rates couldn’t leverage USPS services directly within the platform. This often meant managing shipping rates manually or externally reducing efficiency and accuracy during checkout.

What We Achieved?

We successfully extended Optimizely’s carrier framework to support USPS for domestic shipping rates. This solution fully integrates Optimizely’s shipping architecture, retrieves real-time USPS domestic shipping rates using the official RateV4 API, and maps those rates to configure Ship-Via’s in the admin.

Why It Was Needed?

  • Cost Optimization: USPS often provides more economical rates for small and medium-sized domestic shipments.
  • Business Flexibility: Clients require multiple shipping options to meet their operational and customer needs.
  • Seamless Checkout Experience: Accurate, real-time USPS rates improve customer experience and prevent shipping cost discrepancies.
Discover Our Optimizely Solutions Today!

Solution We Made

We built a custom RatingServiceUsps plugin that integrates directly with USPS’s RateV4 API. This service reads package weights, builds an XML request, fetches rates, and maps USPS services to Optimizely ShipVias based on service codes.
The integration includes:
  • Custom RatingServiceUsps implementing IRatingService
  • Pipeline-based architecture using Optimizely’s dependency injection
  • Real-time request to USPS RateV4 API with logging
  • Extraction and mapping of USPS service rates to platform-configured ShipVias

Code Explanation

1. Main Rating Service Implementation

This class implements IRatingService and is the entry point to trigger USPS rating logic. Please refer to the following URL for code snippet: RatingServiceUsps.cs

2. Pipeline Interface and Implementation

Defines the USPS pipeline contract and executes the pipeline for fetching rates. Please refer to the following URL for code snippet:

3. Parameter and Result Objects

Encapsulate required data and results for the USPS pipeline. Please refer to the following URL for code snippet:

4. Pipe to Call USPS API

Builds USPS XML request, sends it via HTTP, and parses the response into shipping rates. Please refer to the following URL for code snippet:

Admin Configuration

Step 1: Configure the Carrier

AI-Driven Enterprise Chatbot Implementation

Step 2: Configure the services

AI-Driven Enterprise Chatbot Implementation

Step 3: Create custom property against “shipvia” entity under application dictionary in admin

AI-Driven Enterprise Chatbot Implementation

API Request

Method: HTTPPOST Please refer to the following URL for code snippet: API Request

API Response

Please refer to the following URL for code snippet: API Response
Note: The API returns rates for all available USPS services, but only the services configured in the admin panel are displayed on the website.
We have implemented logging for the API requests and responses, which are recorded in the application logs accessible through the admin panel.

Conclusion

By extending Optimizely’s carrier framework, we successfully integrated USPS domestic shipping rates into the platform. This integration allows merchants to dynamically retrieve and display USPS rates at checkout, increasing flexibility and cost-efficiency. The solution remains consistent with Optimizely’s architecture and adheres to USPS’s official Web Tools API.

References

How to Get USPS API Credentials?

To begin using the USPS RateV4 API for retrieving shipping rates, you need valid credentials.
You can obtain these by registering for the USPS Web Tools APIs

Important Note

The Web Tools API platform will be retired on January 25, 2026. To avoid any service disruptions, migrate to the new USPS APIs. Contact API Support for help and provide any feedback via the feedback form.

Author

Poonam Chandersy
Talk To Our Experts

    [recaptcha]

    Recent Blogs

    Agentforce and Microsoft Copilot Studio are the two dominant enterprise…

    Read More »
    copilot-azure-logic-apps-workflow-automation

    Websites used to be something you built once and basically…

    Read More »

    Websites used to be something you built once and basically…

    Read More »