Problem/Motivation
The USPS web tools API is technically still functioning but no longer guaranteed to continue to operate.
https://www.usps.com/business/web-tools-apis/welcome.htm
The deadline for migrating to the new USPS Label APIs was July 14, 2024. If you're still using Web Tools Label APIs, you risk service interruptions.
Proposed resolution
We need to create a new major version that supports the new OAuth API
Remaining tasks
Create a new development branch
Find an API library that supports the new API
Change shipping method definitions to use the new service class labels (instead of numbers)
Change authentication method to OAuth
API Details
The API provides the Shipping Options API for getting a list of possible services for an origin and destination zipcode
https://developer.usps.com/api/99
Use this to get a list of rates then map the ones that were enabled in the shipping method configuration.
This API doesn't seem to support international shipments...
Can use the International Prices API to get them but each service has to be requested separately
https://developer.usps.com/api/77
Issue fork commerce_usps-3470815
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
rhovlandComment #3
rhovlandI have not found any PHP projects that implement the API in PHP
except this one which is more of a script than a libraryactually this is UPS not USPShttps://github.com/JohnAwesomeJr/php-ups-api-rate-oauth2
However I did come across this project for UPS which mentions it was partly generated using Jane using the published UPS OpenAPI spec.
https://github.com/ShipStream/ups-rest-php-sdk#development
USPS publishes OpenAPI spec files for their API. We could use that to generate most of the code for a library using Jane.
https://developer.usps.com/sites/default/files/apidoc_specs/US_Postal_Se...
https://github.com/janephp/janephp
There is also OpenAPI Generator
https://github.com/OpenAPITools/openapi-generator
Comment #4
bill.zero commentedThey may have turned off the Web Tools API last night. My rate requests are not getting responses.
Comment #5
bill.zero commentedThey apparently turned Web Tools back on. Watchdog has 200 status on USPS responses since 14 Jan 2025.
Comment #6
bobburns commentedIt seems easiest to use the Oauth2_client to authenticate integrating the existing Commerce USPS module and adding the new API calls.
Is anyone working on this???
Comment #7
kevinhbruce commentedWe're using the USPS module in our bookstore, so we're interested in the update as well.
Comment #8
rhovlandOk looks like we now have a end of service date
"The Web Tools API platform will be retired on January 25, 2026."
https://www.usps.com/business/web-tools-apis/welcome.htm
The first thing that needs to happen is a PHP API client being made
Once there is a client (the script I linked is not sufficient) then a new major version of this module can be created and adjusted to use the API client.
Comment #9
rhovlandI'm going to put some time into evaluating janephp and openapi-generator and create a library for USPS using one of these generators. Using a generator will also help with adapting to subsequent changes to the API as we can just feed the new spec into it and audit the changes made for accuracy.
Once the library is made I'll create a new version of the USPS module and have the maintainers merge that into this project.
This is going to take a few months as I will be working on this in the spare time between projects at work. But now that there's an end date the urgency of this has placed this higher on my list.
Comment #10
bobburns commentedThe first issue is Oauth2 authentication. I have installed the Oauth2_client and modified the schema yml file to add the crid and mid needed to get a token, and uspsbase php and one other file. The form did change so I am working on the proper USPS api authorization pages
It appears the API is the same but there is an issue of xml along with the Oauth2 authentication.
USPS lists the deprecated and new calls that can be manually changed.
There is a notice that USPS works with Oauth2 v3 and it appears Drupal 10 Oauth2_client is v4 possibly. Do not know if it is backward compatible if so.
My credentials work as I used that first script to test a flow connection - it connected but threw an error on the code for request
I have not modified the Oauth2 client for the USPS requests in commerce_usps yet because until I get the API information config section working with the four values I have ready to there it matters not. There is also an issue it may use the "key" module.
Once I do that the Oauth2_client will see the client and register it.
Where is the live and test mode urls stored or entrered???
Any ideas and suggestions are welcome
Comment #11
bill.zero commented@bobburns asked "Where is the live and test mode urls stored or entrered?"
[site-root]/admin/commerce/config/shipping/methods/usps/edit is where the live url and username are stored, under the form field names "commerce_usps_connection_address" and "commerce_usps_user", respectively.
I don't remember where the test url is.
Comment #12
bill.zero commentedI just received my biweekly warning from USPS API Communications about their Web Tools platform shutdown in Jan 2026.
If I was capable of programming a new module to replace Commerce USPS, I would, but I just don't know PHP well enough to do that. I've done a few alters, but that's about it.
Is there going to be a 7.x-capable replacement for it with OAuth 2 login in time? It's ok if there won't be; I can develop some conditions in a rule and create our own estimates of customer shipping costs. In time those will get close to actual shipping costs.
If someone were to update Commerce USPS, however, I may be capable of semi-duplicating those to update the Commerce UPS module that has been non-function due to failed OAuth 2 logins since January of this year.
I truly appreciate the work of anyone who has this or is putting this on their plate!
Cheers
Comment #13
rhovlandA 7.x compatible version is definitely not going to happen with it being EOL. I have no knowledge of it either. I've finished up my current project and this is my next project.
Comment #14
astringer commented@rvhovland -- does it look like the change to the new USPS API (in D10/11) will happen in time? (I won't hold you to it. :-) Feel free to give me odds rather than a yes/no.
I ask because I have a small non-profit still on Drupal and if it's unlikely, I need to prepare my client so they can can change to UPS or Fedex, and this will be a workflow change for them, so I want to give them time to prepare.
I really appreciate that you're working on it. Happy to test or help in any way.
Thanks.
Comment #15
rhovlandA substantial number of packages are shipped via USPS for us, especially internationally. This is critical to our business. We ship around 200-400 packages a day.
The big maybes here are that building a PHP API is not something I have done before. It helps that there are generators I can use because UPS provides an OpenAPI spec.
The actual job of modifying this module to use the new API should be within my skillset.
The last challenge will be either getting maintainer status or having the cooperation of existing maintainers to publish the module. I have experience with both of these things.
At this point in time I'm confident I can make the end of year deadline. I would however encourage everyone who uses USPS to have a backup available due to potential volatility of the company's future itself.
Comment #16
bobburns commentedThe existing code can be used once authentication is complete to Oauth2. I have completed this step using the Oauth2_client.
A PHP API is not needed in actuality as the new USPS API does both PHP or XML
I went through a challenge to get the first authentication to wotk from USPS.
The existing in API can modified.
You need a usps business account to even get API credentials to request Oauth2 access, so I am not holding my breath this upgrade will get done by the maintainers
Is anyone actually working on this besides me, and I am sorry I cannot share code.
Comment #17
dastan56 commentedhi, any update on this?
Comment #18
damienmckennaComment #19
rhovlandI have begun work on the API client.
How to create an account and get API access for shipping rates has been documented.
I am currently evaluating the two above mentioned client generators. USPS publishes YAML files for their OpenAPI specs but the generators expect json so I'm currently using Swagger Editor to convert them to json. I will need to figure out how to combine the spec documents into one so I can get a coherent client instead of 6 separate ones. UPS seems to do the same thing and this project has found a solution to this so I can probably use it as an example: https://github.com/ShipStream/ups-rest-php-sdk
Why am I using a code generator? Easier to keep code updated both when the API changes and also when depreciations happen upstream in php/guzzle/etc.
USPS also provides guides on mapping their old API calls to the new ones and I could potentially update the module's current dependency, genyaa/usps-php-api to map to the new API. However, the oauth API would still need to be added and there is significant differences in the APIs. That's still an option to pursue if needed though.
Once the API client is done, the USPS module can be modified to add the needed code for handling OAuth (probably borrow from the UPS module) and make adjustments to use the new API library.
Comment #20
rhovlandWork on merging the yaml files is done. Used openapi-merge to do that. Fed the resulting file into jane to generate and am learning how to use the generated code.
Comment #21
webengr commentedDo I understand correctly, version 8.x-1.8 will stop working Jan 2026 because it is using USPS Web Tools API which is obsolete and this module does not use new USPS Label APIs?
Comment #22
rhovlandJanuary 25 2026 is when the Web Tools API is scheduled to be turned off yes. This module currently uses that.
I'm still in progress on getting the new API integrated. I'm learning how to use the API client I generated with jane-php and making sure everything works correctly with that before publishing it and integrating that into this module.
Comment #23
damienmckennaAny progress on the rewrite?
Comment #25
rhovlandI believe that the maintainers have taken charge of the module update but nothing has been confirmed yet.
Comment #26
kevinhbruce commentedThank you, rhovland, for taking on this task, and thanks to the Commerce USPS for integration! We are biting our nails in anticipation out here!
Comment #27
damienmckennarszrama: Any update yet?
Comment #29
jsacksick commentedOpened a 2.x branch for this as it contains breaking changes.
Comment #30
damienmckennaThere's a typo in the MR - USPSRateRequest extends UspsRateRequestInterface, but the actual class is named USPSRateRequestInterface.
Comment #31
damienmckennait might be useful to add a link to https://developers.usps.com/ in the configuration form.
Comment #32
damienmckennaAn amusing detail - https://developers.usps.com is a Drupal site :-)
Comment #33
damienmckennaThe setup instructions says you need to create an account on https://cop.usps.com/cop-navigator, which results in an infinite redirect loop.
Comment #34
bobburns commentedI downloaded the posted version 2 tar but it didn't have any merge requests in it. Basically a 1.8 version. The git hub version was the same.
I manually applied the changes figuring I could see how the code worked.
I copied my working version 1 and and blinded the info. yml to info__yml and named the directory similarly
Maybe I made an error applying the merges but iti nstalled but accssing the shipping method page it white screened as not working
Also someone hard coded client credentials in the test files
I see it works with factory fles and stansbury oauth plugin, 3 and greater which I have installed
I did not do a composer install because backing out of that is more involved if the modules fails
I will try a composer install but a working tar gz file should exist
I have a proper USPS API credentials account
Is there a tar gz file that is current posted somewhere???
Comment #35
webengr commentedYesterday USPS is sent additional warning emails to Web Tools API users:
"The USPS Web Tools API platform will be retired on January 25, 2026. To avoid service disruptions, migrate now to the new USPS APIs."
If this module's stable version is not going to be completed by Jan 25, it needs to be marked obsolete.
Comment #36
jsacksick commentedTo facilitate testing, I merged the MR into the 2.x branch.
The latest USPS dev version can be tested.
Comment #37
bobburns commentedI downloaded and installed the working uploaded version 2 with the merge requests incorporated.
https://www.drupal.org/project/commerce_usps/issues/3470815#comment-1640...
It seems to be working
The shipping dows not show in the review page, but in the total order it does
I have not tested through Stripe to see if it is adding the full amount for charging yet
The "Account number" does not exist according to the USPS delevoper Documentation - it apparently should be "MID" for Mailer ID, so I used that in the account number place. Account Number can mean three different things depending on if one is a Business or an Individual.
Also I changed the hardcoded client id and secret in the USPSRateRequestTestBase.php file to my own in tests/src/Kernel
Dont know if anything but a true MID would work there.
That is a releif that beats the Janauary 25, 2026 deadline
Great work!!! Elegant code
Comment #39
damienmckennaThanks for getting the module to this point, it's truly appreciated.
Looking at the module setup it's not clear what should be set for these fields:
I added a MR with some improvements to the README.md and adds links to the setup form.
Comment #40
damienmckennaI've done some testing with the module and it seems to be working correctly - in "test" mode at least, API requests are returning shipping options for both domestic and international orders. Great work tBKoT!
Comment #41
bobburns commentedThe checkbox options for filtering the mail classes displayed to customer seems to be missing
Because I have a full USPS EPS business and developer account I am running "live"
Certain mail class options I dont want displayed like "Mefia Mail" etc
Because someone had put a clientid and secret in the Krrnel Test file, test likely will work without a real sccount.
See also my post at https://www.drupal.org/project/commerce_usps/issues/3470815#comment-1640...
Can someone restore the mail class filter options to the shipping methods config page?? - or are they now located elsewhere???
Comment #42
damienmckennaOur client has also asked about being able to filter the list of available rates, similar to #41.
It might be worth marking this issue fixed, tagging a beta release, and then doing separate issues for improvements, maybe add a plan issue to coordinate the list of tasks that need to be completed.
Comment #43
bobburns commentedI manually added the merge requests - the filter appears is working properly
Thank you
Comment #44
sah62 commentedWill a stable release be available for installation before 25 January? If not, can someone provide a detailed description of what needs to be done to install the needed updates?
Comment #46
jsacksick commentedChanges are merged. Followup improvements should be made in separate issues.
Comment #48
jsacksick commentedI'm thinking of tagging a beta1.
Comment #49
webengr commented3 days till drop dead. Status for this is FIXED, above states changes are merged, but no release, no beta, not even a recent devel listed yet on project page?
Comment #50
sah62 commentedInformation describing the 2.x development release can be found here:
https://www.drupal.org/project/commerce_usps/releases/2.x-dev
I just installed it using composer. That process went smoothly. I also had to follow the steps described here to re-create my USPS API credentials:
https://git.drupalcode.org/project/commerce_usps/-/blob/2.x/README.md?re...
You then need to add those credentials to your store's USPS shipping method configuration:
admin/commerce/shipping-methods
I've done some basic testing, and I'm able to retrieve both domestic and international rate information. Thank you! As described above, there's still some work to do in terms of filtering rates that are shown to your customers. For example, if you enable the Priority Mail rates, your customers will see all of the available Priority Mail options (Priority Mail, Priority Mail Flat Rate Envelope, Priority Mail Large Flat Rate APO/FPO/DPO, etc.). That may cause some confusion until we have the ability to be more selective about the specific rates exposed for customer selection. That issue is being tracked.
Comment #51
trobey commentedWhen I try to create an app I get the message:
| You are currently NOT Enrolled in USPS SHIP Outbound and Returns.Enroll in USPS SHIP to get access to the Shipping Suite API products.
I did not see "Select the APIs Available."
I tried creating the app anyway but it is not working. Is there a step missing somewhere?
Comment #52
webengr commentedIt would be helpful to update the project page explaining that only the 2.0 will work after Jan25 and link to dev.
Comment #53
rhovlandMy quickly thrown together guide on upgrading to the dev release.
1. Before upgrading make a note of the shipping services & conditions configured in any shipping methods that use USPS or USPS International because these might need to be reconfigured.
2. Install the dev version of 2.x
To enable filtering of rates by category add this patch.
Add the following to the
"extra": {section of composer.jsonInstall the dev branch with composer:
composer require 'drupal/commerce_usps:2.x-dev@dev'3. Clear the site cache
4. Go to your shipping methods and edit any that used USPS shipping plugins. Fill in the API information obtained for your APP from the USPS COP site.
To reproduce the same results that the old module did set the following for the "Processing categories"
To offer plain shipping methods check "Flats"To offer flat rate boxes check "Machinable"
USPS changed their API over the weekend and now the behavior is no longer the same. They are reversed (probably a bug fix) but Machinable includes flat rate boxes so it's useless as a filter category now.
Check all of the options for "Destination entry facility types"
Note that once a beta version is released you may have to reconfigure your shipping methods a second time depending on if there's any changes to the module between now and then. Also you will want to remove the patch above once #3568335: Implement additional service filtering options is fixed.
Comment #54
rhovlandObtaining credentials to use USPS APIs
For the most up to date instructions see https://developers.usps.com/getting-started
A summary of the process including helpful information that is missing in the getting started guide:
1. Create a USPS account.
2. Use the USPS Customer Onboarding Portal to configure your account for access to the USPS APIs. https://cop.usps.com
3. Once you reach the step where it asks you to add a payment method you can click the skip link to go to the developer portal.
If you need access to paid APIs (such as labels) you will need to add a payment method. Once you are done you will receive a welcome email which has information about requesting access to restricted APIs or increasing API quotas.
4. On https://cop.usps.com: click Apps in the top bar. Create an app. You do not need to specify a callback URL for this API to work.
The "Public Access I" API listed in the available APIs gives you access to the following APIs, each with a quota of 60 calls per hour:
OAuth
Addresses
Service Standards
Service Standards File Download
International Pricing
Domestic Pricing
Shipping Options
Locations
UserInfo
5. Back on the Apps screen click the name of your app to view the credentials you will need to use to request OAuth tokens to use the API.
Comment #55
damienmckennaYou shouldn't do this. This sets the default allowed release on all dependencies, so the next time you do "composer update -W" you'll give it permission to install dev versions of everything it wants to, which is a bad idea.
The single "composer require" line is enough to make your site download the dev version.
Comment #56
rhovlandWeird composer refused to install it without doing that. If it's just a me problem I'll remove it.
Comment #57
damienmckennaWhen you add the module via "composer require 'drupal/commerce_usps:2.x-dev@dev'" the "@dev" part tells Composer to ignore the normal "minimum-stability" setting and install the dev version, it should just work that way.
Comment #58
rhovlandThe beta release of the module includes filtering so I'd encourage everyone that added the patch to remove it and upgrade to the beta.
You can find information on how to configure the filters here: #3569991: Provide guidance to site builders on categories and rate indicators