User Tools

Site Tools


magento2:extensions:magento-2-usps-oauth-shipping-extension-real-time-usps-rates-via-rest-api-v3

Magento 2 USPS Shipping Extension – Real-Time USPS Rates (REST API v3)

Extension context

This guide applies to the Toweringmedia USPS Shipping Extension available within the Magento Admin product catalog.

Overview

The Magento 2 USPS Shipping Extension enables real-time USPS shipping rate calculation during cart and checkout using the USPS REST API v3 with OAuth2 authentication.

Designed for production environments, the extension includes rate caching, configurable service controls, and diagnostic tools to ensure reliable shipping calculations.

Key features

  • Real-time USPS shipping rates displayed in cart and checkout
  • OAuth2-based secure integration with USPS REST API v3
  • Built-in rate caching to improve checkout performance and reduce API requests
  • Support for USPS services including Ground Advantage, Priority Mail, Express, and First-Class
  • Configurable handling fees, markups, and shipping method filtering
  • Optional Top-N method display for optimized checkout user experience
  • Flexible dimension handling modes: product_attributes, auto_dim_weight, hybrid_fallback
  • Admin tools for Test Connection, Test Rate, and optional debug logging

Important notice

USPS is deprecating legacy Web Tools APIs. This extension supports migration to the new OAuth-secured USPS REST platform.

Installation

Please refer to the installation guide in the following article https://toweringmedia.com/installation

Configuration

After installation, configure USPS credentials and extension settings from Magento Admin. Validate shipping rates and checkout workflows according to your business requirements.

Validation checklist

  • Configuration values save correctly at the intended scope
  • Shipping rates display properly in cart and checkout
  • Order totals and shipping calculations complete without errors
  • Logs remain clean during standard test scenarios

Troubleshooting

  • Missing functionality: verify module enablement and configuration scope
  • Rate calculation issues: test with only required related modules enabled
  • Frontend outdated data: clear cache and redeploy static content

Readme

USPS made a real access-control change to package tracking, and the key date was April 1, 2026. USPS says requests for tracking data will now be checked against the Mailer ID (MID) in the package barcode, and requests for MIDs the caller is not authorized for will fail

Tracking Ownership Requirement

Successful USPS tracking depends on three things being aligned:

  • Who creates the label
  • Which Mailer ID (MID) is used when the label is created
  • Who is pulling the tracking data via the API call

The tracking number embeds the Mailer ID used to create the label. For USPS tracking API calls to work without error, the party pulling the tracking data must own the Mailer ID embedded in that tracking number.

If these three aspects are misaligned, such as attempting to track a label created under a Mailer ID you do not own, USPS can return an error even when the tracking number itself is valid. This is the core tracking-authorization problem to verify first when tracking requests fail.

Setup instruction

1. Create or access your USPS developer account

Navigate to https://developers.usps.com/ and sign in using your USPS Business Account. If you do not have an account, create a new one. The Customer Onboarding Portal (COP) will guide you through the setup process and enable USPS API access.

2. Create a new application

After completing the account setup in the Customer Onboarding Portal (COP), log in to the Business Portal and navigate to My Apps from the top menu. Alternatively, you can go to the home page and select Build. Create a new application if one does not already exist.

3. Retrieve Consumer Key and Consumer Secret

Within the COP portal, open your created application and navigate to the Credentials section. Copy the Consumer Key and Consumer Secret. These credentials are required to generate OAuth tokens.

4. Generate OAuth token

Use USPS OAuth specifications to generate an access token. Pass the Consumer Key as client_id and Consumer Secret as client_secret.

5. Configure credentials in Magento Admin

Navigate to:

Stores → Configuration → Sales → Delivery Methods → USPS REST API (Toweringmedia)

Enter the Consumer Key and Consumer Secret, then save the configuration.

6. Validate connection and rate calculation

Use the Test Connection and Test Sample Rate options to verify authentication and rate retrieval.

User experience

Shopping cart rate estimation

In the shopping cart, the extension retrieves real-time USPS shipping rates when customers enter their destination in the Estimate Shipping and Tax section.

Available USPS services such as Parcel Select, Ground Advantage, Priority Mail, and Priority Mail Express are dynamically displayed with live pricing. This ensures customers can review accurate shipping costs before proceeding to checkout.

Checkout shipping method selection

During checkout, the extension automatically fetches real-time USPS shipping rates based on the entered shipping address.

All eligible USPS shipping methods are displayed with corresponding live prices, ensuring rate consistency between cart and checkout. Built-in caching mechanisms improve performance and provide a seamless shipping selection experience.

Key user experience benefits

  • Real-time USPS rate visibility improves customer trust and reduces cart abandonment
  • Accurate shipping pricing eliminates manual estimation errors
  • Optimized checkout performance through intelligent rate caching
  • Clear presentation of multiple USPS service levels enables better delivery decisions
magento2/extensions/magento-2-usps-oauth-shipping-extension-real-time-usps-rates-via-rest-api-v3.txt · Last modified: by swatwik