I was able to download a Encapsualted version from Gethub.
I was able to download a Encapsualted version from Gethub.
I used the same setup that my 2.0.1 version uses successfully and I get an error in the new USPSr 0.2.1 version.
Error: Missing or malformed access token.
Is the error referring to the USPS API Consumer Key?
I am using the same USPS API Consumer Key in both Zencart versions.
​[12-Feb-2025 16:38:27 Europe/Berlin] Request URI: /tennesseetraditionalflies.com/index.php?main_page=checkout_shipping, IP address: ::1, Language id 1#0 C:\xampp\htdocs\tennesseetraditionalflies.com\zc_plugins\USPSRestful\v0.2.1\cata log\includes\modules\shipping\uspsr.php(1706): zen_debug_error_handler()
#1 C:\xampp\htdocs\tennesseetraditionalflies.com\zc_plugins\USPSRestful\v0.2.1\cata log\includes\modules\shipping\uspsr.php(376): uspsr->getBearerToken()
#2 C:\xampp\htdocs\tennesseetraditionalflies.com\includes\classes\shipping.php(257) : uspsr->quote()
#3 C:\xampp\htdocs\tennesseetraditionalflies.com\includes\modules\pages\checkout_sh ipping\header_php.php(185): shipping->quote()
#4 C:\xampp\htdocs\tennesseetraditionalflies.com\index.php(35): require('C:\\xampp\\htdocs...')
--> PHP Warning: Undefined array key "access_token" in C:\xampp\htdocs\tennesseetraditionalflies.com\zc_plugins\USPSRestful\v0.2.1\cata log\includes\modules\shipping\uspsr.php on line 1706.
Hi. You're using one of the unstable versions. 0.2.1 isn't released yet. Can you try to download one of the releases? 0.2.0 is the current version. Meanwhile I'll look into why that error is coming up at all.
Last edited by retched; 12 Feb 2025 at 07:02 PM.
Additionally, did you also set up your module by providing it a API Key and Secret in the ZenCart admin panel?
That line
is asking for the access_token from the response.Code:$token = $body['access_token'];
If possible, can you enable debugging and send me the log file that's generated from the USPSr module?
Last edited by retched; 12 Feb 2025 at 07:13 PM.
Yes, I used the same setup from my Zencart 2.0.1
Below is the debug.
2025-02-12 19:38:53:
Requesting Token from USPS
Token Request
{
"grant_type": "client_credentials",
"client_id": "725TENNE5719",
"client_secret": "lgf@USPS9491",
"scope": "domestic-prices addresses international-prices service-standards shipments"
}
2025-02-12 19:38:53:
==================================
TOKEN RESPONSE FROM USPS:
{
"error": "invalid_client",
"error_description": "InvalidApiKey: The client application credentials provided in the request are missing, invalid, inactive or not approved for access.",
"error_uri": "https://datatracker.ietf.org/doc/html/rfc6749#page-45"
}
---------------------------------
CommErr (should be 0): 0 -
==================================
USPS Country - $order->delivery[country][iso_code_2]: US
2025-02-12 19:38:53:
USPSRestful Configuration Report
=========================================================
USPSr build: 0.2.1
Quote Request Rate Type: Retail
Quote from main_page: checkout_shipping
Display Transit Time: No
Site Weights Based in: lbs (Pounds)
Site Measurements Based in: Inches
Shipping ZIP Code Origin: 37135
Cart Weight: 0.01 lbs
Total Quote Weight: 0.0165 lbs. , Pounds: 0, Ounces: 0.264
Maximum: 50 Tare Rates: Small/Medium: 65:0 Large: 0:2
Order Handling method: Box, Handling fee Domestic (Order): $1.25, Handling fee International (Order): $5.00
Services Selected:
Domestic Methods: Ground Advantage, Priority
International Methods: - None -
Categories Excluded from Media Mail: - None -
Zip Codes Allowed for USPS Connect : - None -
Add-Ons Enabled (Domestic): - None -
Add-Ons Enabled (International): - None -
Assumed Domestic Package Size - Length: 8.625, Width: 5.375, Height: 1.625
Assumed International Package Size - Length: 8.625, Width: 5.375, Height: 1.625
Are Packages are Machinable? : Irregular
Sort the returned quotes by: Price-LowToHigh
Order is eligible for Media Mail ? YES
Order SubTotal: $3.00
Order Total: $3.29
Uninsurable Portion: $0.00
Insurable Value: $3.29
2025-02-12 19:38:53: Sending Services request to USPS
2025-02-12 19:38:54:
==================================
REQUEST FROM STORE:
{
"originZIPCode": "37135",
"destinationZIPCode": "37135",
"weight": 0.0165,
"length": 8.625,
"width": 5.375,
"height": 1.625,
"mailClasses": [
"USPS_GROUND_ADVANTAGE",
"PRIORITY_MAIL",
"PRIORITY_MAIL_EXPRESS",
"MEDIA_MAIL"
],
"priceType": "RETAIL",
"extraServices": [
],
"itemValue": 3.2924999999999995,
"mailingDate": "2025-02-13"
}
---------------------------------
CommErr (should be 0): 0 -
==================================
USPS Country - $order->delivery[country][iso_code_2]: US
2025-02-12 19:38:54:
==================================
RAW JSON FROM USPS:
{
"apiVersion": "/prices/v3",
"error": {
"code": "401",
"message": "Missing or malformed access token.",
"errors": [
{
"title": "invalid_token",
"detail": "The access token presented with the request is missing or malformed (not a JWT).",
"source": "Access Token"
}
]
}
}
2025-02-12 19:38:54:
===============================================
Reviewing selected method options...
Array
(
[0] => Array
(
[method] => USPS Ground Advantage Machinable Single-piece
[handling] => 1.30
)
[1] => Array
(
[method] => Priority Mail Machinable Single-piece
[handling] => 1.30
)
)
2025-02-12 19:38:54:
===============================================
Building options...
2025-02-12 19:38:54:
===============================================
Revoking Bearer Token...
2025-02-12 19:38:54: Revoking a Token from USPS
Revocation Request
{
"client_id": "725TENNE5719",
"client_secret": "lgf@USPS9491",
"revoke_token": null,
"token_type": "access_token"
}
2025-02-12 19:38:54:
==================================
TOKEN RESPONSE FROM USPS:
{
"error": "invalid_client",
"error_description": "InvalidApiKey: The client application credentials provided in the request are missing, invalid, inactive or not approved for access.",
"error_uri": "https://datatracker.ietf.org/doc/html/rfc6749#page-45"
}
---------------------------------
CommErr (should be 0): 0 -
==================================
USPS Country - $order->delivery[country][iso_code_2]: US
Yup, like I thought. You're using the old WebTools API login details. As stated on the readme:
I already have a USERID and PASSWORD under the old system, but I'm getting error messages while I try to retrieve quotes.
The older USERID and PASSWORD are not valid for the new system. You will need to provision new credentials under the new USPS API system. Additionally, you SHOULD create an entire new USPS Business Account provided that you don't already have one for your business.
You may want to head over to this page and read how to obtain valid API Credentials: https://github.com/retched/ZC-USPSRe...ted#installing
Let me know if you need help. Send me a DM or @retched on Discord.
Last edited by retched; 12 Feb 2025 at 08:12 PM.
Using 1.5.7c and installed the non-encapsulated version. Couple of issues. In the admin panel the module didn't show and it gave an error because it was looking for uspsr.php in the languages>english>modules>shipping folder. The file is actually named lang.uspsr.php. So I just renamed it to uspsr.php and then the module showed up and I was able to configure it. The module works but it also is not grabbing some of the names correctly. For instance when you get a quote it would show MODULE_SHIPPING_USPSR_TEXT_SHORT_TITLE (Ground Advantage) to the user.
I edited line 245 in the module and just changed it to $this->title = 'United States Postal Service';
It does something similar with the name of the module under the admin>module>shipping.
I was able to edit those to get things looking right. Not sure why its not getting the data from the other files. My issue is with the other usps module you could select the weight for each shipping type. For instance I only want up to 1 lb for ground advantage and priority limited to 1 lb or more. Is there a way to put that option back in or any idea where to edit the files to manually put that back in?
Bookmarks