doh2122
doh2122

Reputation: 51

Getting the OAuth Token from FedEx to use for Track API

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)

Upvotes: 2

Views: 5991

Answers (2)

Mike Volmar
Mike Volmar

Reputation: 2093

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'];

Upvotes: 1

pkarnia
pkarnia

Reputation: 41

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.

Upvotes: 4

Related Questions