USPSv3 REST Shipping Rates

for Magento 2

Version 3.0.0

1. Overview

Jscriptz USPSv3 is a modern USPS shipping integration for Magento 2 that uses the new USPS REST APIs with OAuth2 authentication. This module provides real-time shipping rates, transit time information, and address validation capabilities using USPS's Shipping Options API.

Why "USPSv3"? This module uses USPS's newer REST APIs (v3) with OAuth2 authentication, as opposed to the legacy XML Web Tools APIs used by Magento's built-in USPS integration. The REST APIs are faster, more reliable, and return pricing AND transit times in a single API call.

REST APIs

Modern JSON-based APIs with OAuth2 authentication

Real-Time Rates

Get live shipping rates directly from USPS

Transit Times

Display estimated delivery dates at checkout

Rate Caching

Intelligent caching for improved performance

2. Features

3. Requirements

No Account Number Required! Unlike UPS and FedEx, USPS does not require a shipping account number to use their APIs. You only need API credentials from the Developer Portal.

4. Installation

1 Get Your Composer Access Token

After purchasing the extension, log in to your Jscriptz account to get your Composer authentication token:

  1. Go to mage.jscriptz.com/customer/account
  2. Click on GitHub Access in the left sidebar
  3. Click Generate New Token if you don't have one
  4. Copy your access token (it will look like a long string of characters)
Note: Your token is valid for 50 minutes. You can generate a new one anytime from your account.

2 Configure Composer Authentication

Create or update your auth.json file in your Magento root directory:

{
    "http-basic": {
        "packages.jscriptz.com": {
            "username": "YOUR_LICENSE_KEY",
            "password": "YOUR_ACCESS_TOKEN"
        }
    }
}

Replace:

3 Add Repository & Install Package

Add the Jscriptz package repository and install the module:

# Add the Jscriptz repository (first time only)
composer config repositories.jscriptz composer https://packages.jscriptz.com

# Install USPSv3 (includes ShippingCore dependency)
composer require jscriptz/module-uspsv3

4 Run Magento Setup

# Enable the modules
bin/magento module:enable Jscriptz_ShippingCore Jscriptz_USPSv3

# Run setup upgrade
bin/magento setup:upgrade

# Compile DI (production mode)
bin/magento setup:di:compile

# Deploy static content (production mode)
bin/magento setup:static-content:deploy -f

# Clear cache
bin/magento cache:flush

5 Activate Your License

After installation, you need to activate your license in the Magento admin:

  1. Go to Stores → Configuration → Sales → Shipping Methods → Jscriptz USPSv3
  2. Expand the License section
  3. Enter your License Key from your Jscriptz License Account
  4. Click Save Config
  5. Click Verify License to confirm your license is active
Success! When verified, you'll see a green "Active" badge indicating your license is valid.
Domain Verification: Your license is tied to the domain(s) you specified during purchase. If you see a "Domain mismatch" error, update your domains in your License Account.

5. USPS Developer Portal Setup

Before configuring the module in Magento, you need to create an API project in the USPS Developer Portal to obtain your API credentials.

1 Create a USPS Developer Account

Visit developers.usps.com and create a free developer account if you don't already have one.

USPS Business Customer Gateway
USPS Business Customer Gateway homepage

2 Register for API Access

Complete the registration process to get access to the USPS APIs. You'll need to provide basic business information.

USPS Registration
Complete the USPS developer registration

3 Follow the Getting Started Steps

After registering, USPS provides a guided setup process to help you create your API credentials.

Getting Started Steps
USPS Getting Started guide for API setup

4 Select Required APIs

When creating your API project, select the following APIs:

Shipping Options API
USPS Shipping Options API documentation
API Catalog
USPS API Catalog showing available APIs

5 Retrieve Your API Credentials

After your project is created, you'll receive your API credentials. You'll need:

Important: Keep your Consumer Secret confidential. Never share it or commit it to version control.

API Endpoints

Environment Token URL API Base URL
Sandbox https://apis-tem.usps.com/oauth2/v3/token https://apis-tem.usps.com
Production https://api.usps.com/oauth2/v3/token https://api.usps.com

6. Magento Configuration

Configure the module in the Magento Admin at:

Stores > Configuration > Jscriptz > Jscriptz USPSv3

General Settings

Setting Description
Enabled Enable or disable the USPSv3 shipping method
Title The carrier title shown at checkout (default: "USPS")
Environment Select Sandbox for testing or Production for live rates

API Credentials

Setting Description
Consumer Key Your USPS Consumer Key from the Developer Portal
Consumer Secret Your USPS Consumer Secret from the Developer Portal
Critical: Always enter credentials through the Magento Admin interface, not via CLI commands. The credentials are encrypted when saved through the admin, ensuring they work correctly with the API.

Shipping Options

Setting Description
Allowed Methods Select which USPS mail classes to offer (leave empty for all)
Price Type Retail, Commercial, or Commercial Plus pricing
Maximum Package Weight Maximum weight per package in lbs (USPS limit: 70 lbs)
Handling Fee Fixed amount added to each shipping rate
Free Shipping Threshold Cart subtotal for free shipping (0 = disabled)

Rate Caching

Setting Description
Enable Rate Caching Cache API responses to improve performance
Cache TTL How long to cache rates in seconds (default: 3600)
Use Cache on API Failure Return cached rates if USPS API is unavailable

Address Validation

Setting Description
Enable Address Validation Validate shipping addresses using USPS API
Auto-Correct Addresses Automatically apply USPS address corrections

Shipping Restrictions

Setting Description
Ship to Applicable Countries All countries or specific countries only
Ship to Specific Countries Select allowed destination countries
Show Method if Not Applicable Show USPS option even when unavailable
Sort Order Position in shipping method list

Developer Settings

Setting Description
Debug Mode Log API requests and responses to uspsv3.log

7. Testing

Sandbox Testing

  1. Set Environment to Sandbox
  2. Enter your sandbox credentials from the USPS Developer Portal
  3. Add a product to cart and proceed to checkout
  4. Enter a valid US shipping address
  5. USPS shipping methods should appear with rates
Sandbox Rates: Sandbox rates are for testing only and may not match production rates. The sandbox environment uses test endpoints at apis-tem.usps.com.

Debug Mode

Enable Debug Mode to log detailed API information:

  1. Set Debug Mode to Yes
  2. View logs at var/log/uspsv3.log
  3. Look for entries prefixed with [USPSv3]
# View USPSv3 debug logs
tail -f var/log/uspsv3.log

Production Testing

  1. Switch to Production environment
  2. Enter your Production credentials
  3. Clear Magento cache
  4. Test checkout with real shipping addresses
  5. Verify rates match USPS published rates for your price type

8. Supported Services

Domestic Services (US)

Mail Class Code Service Name Transit Time
USPS_GROUND_ADVANTAGE USPS Ground Advantage 2-5 business days
PRIORITY_MAIL Priority Mail 1-3 business days
PRIORITY_MAIL_EXPRESS Priority Mail Express 1-2 days, guaranteed
PARCEL_SELECT Parcel Select 2-8 business days
PARCEL_SELECT_LIGHTWEIGHT Parcel Select Lightweight 2-8 days (items < 1 lb)
MEDIA_MAIL Media Mail 2-8 days (books, CDs only)
LIBRARY_MAIL Library Mail 2-8 days (library materials)
BOUND_PRINTED_MATTER Bound Printed Matter 2-8 days (catalogs, directories)

International Services

Mail Class Code Service Name
PRIORITY_MAIL_INTERNATIONAL Priority Mail International
PRIORITY_MAIL_EXPRESS_INTERNATIONAL Priority Mail Express International
FIRST_CLASS_PACKAGE_INTERNATIONAL First-Class Package International
GLOBAL_EXPRESS_GUARANTEED Global Express Guaranteed

Price Types

Code Description
RETAIL Standard retail pricing (default)
COMMERCIAL Discounted commercial pricing (requires business account)
COMMERCIAL_PLUS Additional discounts for high-volume shippers

Weight Limits

Service Maximum Weight
Most USPS Services 70 lbs
First-Class Package 13 oz
Parcel Select Lightweight 1 lb

9. Troubleshooting

No Shipping Methods Displayed

  1. Verify the module is enabled in configuration
  2. Check that API credentials are entered correctly
  3. Ensure origin address is configured in Shipping Settings
  4. Enable Debug Mode and check uspsv3.log for errors
  5. Verify the destination country is allowed
  6. Check that allowed methods are configured (or leave empty for all)

Authentication Errors

Error: "invalid_client" or "Authentication failed"

Solution:

Empty Shipping Options Response

Error: No rates returned from API

Solution:

Caching Issues

If rates seem outdated:

  1. Clear Magento cache: bin/magento cache:flush
  2. Reduce Cache TTL in configuration
  3. Temporarily disable caching for testing

Missing Transit Times

Transit times come from the USPS Shipping Options API response. If not displayed:

Business Customer Gateway Errors

Note: Some USPS portal features require a Business Customer Gateway (BCG) account. If you see redirect errors, you may need to complete additional USPS registration.
BCG Account Error
Business Customer Gateway may require additional setup for some features

10. FAQ

Can I use this alongside Magento's built-in USPS module?

Yes, Jscriptz USPSv3 uses the carrier code uspsv3 and operates independently of Magento's core USPS module (usps). You can run both simultaneously, though we recommend disabling the core module to avoid customer confusion.

Do I need a USPS business account?

No! Unlike UPS and FedEx, USPS does not require an account number to use their APIs. You only need API credentials from the Developer Portal. However, for Commercial or Commercial Plus pricing, you may need a business relationship with USPS.

What's the difference between Retail and Commercial pricing?

Retail is standard pricing available to everyone. Commercial pricing offers discounts for businesses that ship regularly. Commercial Plus provides additional discounts for high-volume shippers. Most stores start with Retail pricing.

Why use the Shipping Options API instead of separate Rate and Transit APIs?

The Shipping Options API (v3) returns both pricing AND transit times in a single API call, reducing latency and improving checkout performance. This is more efficient than the older approach of making separate calls for rates and delivery estimates.

How often should I refresh cached rates?

The default TTL of 3600 seconds (1 hour) works well for most stores. USPS rates don't change as frequently as carrier rates, so caching is very effective. For high-traffic stores, keep caching enabled to reduce API calls.

Can I offer free shipping for USPS methods?

Yes, set a Free Shipping Threshold amount. When the cart subtotal exceeds this amount, all USPS rates will show as $0.00.

What's the maximum package weight for USPS?

Most USPS services support packages up to 70 lbs. This is lower than UPS and FedEx (150 lbs). First-Class Package is limited to 13 oz.

Why does USPS Ground Advantage show instead of First-Class or Priority Mail?

USPS Ground Advantage replaced several services in 2023, including First-Class Package Service, Parcel Select Ground, and Retail Ground. It's now the primary ground shipping option for packages up to 70 lbs.

Are international shipments supported?

Yes, the module supports international USPS services including Priority Mail International, Priority Mail Express International, First-Class Package International, and Global Express Guaranteed.

11. ShippingCore Integration

USPSv3 works seamlessly with the Jscriptz_ShippingCore module, which provides enhanced shipment management features in the Magento admin.

Enhanced Shipments Grid

When ShippingCore is installed, the Sales > Shipments grid is enhanced with additional columns and mass actions:

Additional Columns

Column Description
Tracking Number Displays tracking number(s) with clickable link to carrier tracking
Carrier Shows carrier name (USPS, UPS, FedEx, etc.)
Label Status Indicates whether a shipping label has been generated
Tracking Status Shows if tracking notification has been sent to customer
Shipping Price Displays the shipping amount charged for the order
Label Action link to view/download shipping label (when available)

Mass Actions

Process multiple shipments at once with these mass actions:

Note: Label generation requires USPS Labels API access and proper account configuration. See the ShippingCore User Guide for complete documentation on label generation and shipment automation.

Related Documentation