'usps-webtools authentication fails

I have a nodejs javascript test program as follows:

const USPS = require('usps-webtools');

const usps = new USPS({
    server: 'https://production.shippingapis.com/ShippingAPI.dll',
    userId: 'user:passwd',
    ttl: 10000 //TTL in milliseconds for request
    });
usps.verify({
    street1: '1234 Some Lane',
    city: 'AnyTown',
    state: 'MI',
    zip: '12345'
    }, function(err, address){
      console.log(err)
      console.log(address);
      });

It always returns with:

Authorization failure. Perhaps username and/or password is incorrect.

USPSCOM::DoAuth

But I can go to usps.gov and login with the same account name and password.
How does it want me to pass the username and password to it?



Solution 1:[1]

I just tested your code and the problem appears to be the value you are passing for the userId

Instead of passing your username and password in this format userId: 'user:passwd',

Set the userId equal to your WebTools username only.

Here is a screenshot of the email you'll receive once you register at the USPS website.

enter image description here

The docs for the USPS APIs aren't great, so we created some modern ones using Redocly at https://www.uspsweb.tools and create a public postman collection for developers to explore the APIs at https://www.postman.com/lobteam/workspace/usps-web-tools-public-workspace/overview

Best of Luck!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sid Maestre