Quote Originally Posted by retched View Post
Additionally, did you also set up your module by providing it a API Key and Secret in the ZenCart admin panel?

That line

Code:
        $token = $body['access_token'];
is asking for the access_token from the response.

If possible, can you enable debugging and send me the log file that's generated from the USPSr module?
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