2

I'm trying to get the OAuth Token to get auth access to some of the FedEx APIs ( like Track API for tracking shipments ), but I get a 401 (NOT.AUTHORIZED.ERROR -> "The given client credentials were not valid. Please modify your request and try again") error. (At the moment, I'm using Postman to try and test the APIs.)

Here is the url I'm using, found provided by FedEx: https://apis-sandbox.fedex.com/oauth/token

I've followed ( to my understanding ) how the body and headers should be set:

Headers: Content-Type: application/x-www-form-urlencoded
Body: x-www-form-urlencoded (Postman option): 
   grant_type: client_crendentials
   client_id: ***PROJECT_API_KEY
   client_secret: ***PROJECT_SECRET KEY

After sending, I only get the error message above. I checked / doubled-checked my API keys, but I can't seem to get it to go through. Any ideas?

postman settings:
POST - URL https://apis-sandbox.fedex.com/oauth/token
Headers - Content-Type: application/x-www-form-urlencoded
Body - x-www-form-urlencoded: 
   grant_type: client_credentials
   client_id: *******
   client_secret: *******

(information gotten from https://developer.fedex.com/api/en-us/catalog/authorization/v1/docs.html)

doh2122
  • 51
  • 1
  • 6
  • Welcome to Stack Overflow. Please take the [tour] to learn how Stack Overflow works and read [ask] on how to improve the quality of your question. Then [edit] your question to include your source code as a working [mcve], which can be tested by others. – Progman Dec 26 '21 at 22:54

2 Answers2

4

The sandbox API credentials are not immediately usable when creating a new account. It took >1 hour for me to get a registration complete email from FedEx after which the sandbox credentials became valid.

pkarnia
  • 41
  • 3
  • 2
    This is actually the answer. I had received a registration complete email, but my credentials were not valid when using a basic postman request. Struggled with it all day, then the next day came back to it just working. If you're confident you have the right request, give it ~24 hours then try again. – B-Stewart Apr 19 '22 at 16:41
1

Tried this today for first time, setup my account and got my fedex credentials. I had to use Safari, chrome didn't work, maybe because of my ad blocker. Tested the OAuth request first on the fedex developer site "try this api' and it worked right away. It does not work in postman even several hours later. I am able to use cURL to get an OAuth token from the sandbox.

$url = "https://apis-sandbox.fedex.com/oauth/token";

$payload = "grant_type=client_credentials&client_id=xxxx&client_secret=yyyy";

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$json = json_decode($response, true);
curl_close($ch);
print_r($json);

$token = $json['access_token'];
Benjamin Loison
  • 3,782
  • 4
  • 16
  • 33
Mike Volmar
  • 1,927
  • 1
  • 22
  • 31