'Why am I getting this FedEx API error 'The given grant_type is not supported. Please modify your request and try again'

I'm using this PHP code:

$service_url = 'https://apis-sandbox.fedex.com/oauth/token';
   $curl = curl_init($service_url);
   $curl_post_data = array(
       "content-type" => 'application/json',
        "grant_type" => 'client_credentials',
        "client_id" => '<client_id>',
        "client_secret" => '<client_secret>',
        );
   curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
   curl_setopt($curl, CURLOPT_POST, true);
   curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
   $curl_response = curl_exec($curl);
   curl_close($curl);

echo $curl_response; 

And getting this response:

{"transactionId": "e147dc65-b09c-4586-be2d-4da3beafa8ed","errors":[{"code":"BAD.REQUEST.ERROR","message":"The given grant_type is not supported. Please modify your request and try again."}]}%

I have the service_url, client_id, and client_secret as they are in the FedEx developer site. I'm not sure where the issue is.



Solution 1:[1]

I got a similar error when working with Postman because I was using the wrong content-type (form-data instead of x-www-form-urlencoded). Make sure to set your content-type header to application/x-www-form-urlencoded.

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 Alex