Home > Software design >  UPS API OAuth token request fails
UPS API OAuth token request fails

Time:09-22

In the UPS developer portal, I have created an application that has a Client Id and a Client Secret. Next, I want to obtain an OAuth token so I can use it to access their other APIs. I am creating my token request as per the spec and I am receiving the following error:

{"response":{"errors":[{"code":"10400","message":"Invalid/Missing Authorization Header"}]}}

The spec has a "try it out" feature where you can obtain a test token. It prompts the user to fill in a x-merchant-id parameter and a grant_type form variable and creates a curl request that looks like this:

curl -X POST "https://wwwcie.ups.com/security/v1/oauth/token" 
     -H "accept: application/json" 
     -H "x-merchant-id: {My_Client_Id_Goes_Here}" 
     -H "Content-Type: application/x-www-form-urlencoded" 
     -d "grant_type=client_credentials"

For x-merchant_id, I have used my app’s Client Id. It is not clear if the value for grant_type should be the phrase client_credentials (the page makes it seem like this is the only valid value) or my app’s actual Client Secret. I have tried both and get the same error each time.

There are a million examples out there on how to use their (old style) API keys, but practically nothing about how to obtain an OAuth token except for the instructions linked above!

CodePudding user response:

Your curl looks good to me, just missing the Authorization header which is a base64(id:secret)

curl -X POST "https://wwwcie.ups.com/security/v1/oauth/token" 
     -H "Authorization: Basic {id}:{secret}" 
     -H "accept: application/json" 
     -H "x-merchant-id: {My_Client_Id_Goes_Here}" 
     -H "Content-Type: application/x-www-form-urlencoded" 
     -d "grant_type=client_credentials"

If you're using the 'Try out' feature, select the Authorize button at the top and enter the client id and secret, that's where its used to set the Authorization header. One thing to note, the 'Try out' feature only work with the Test product(s) assigned to your app

Additional info

UPS have 2 environments

  • Testing: wwwcie.ups.com
  • Production: onlinetools.ups.com

Testing env only accepts Test Products, so note the product(s) that was added to your app

  • Related