Missing parameter: `grant_type`

#1

Hello,

I’m currently trying to get the refresh_token and access_token and I’m stuck at the step 4 : https://pipedrive.readme.io/docs/marketplace-oauth-authorization

I’m sending my request with the following headers :

‘Content-Type: application/x-www-form-urlencoded’

‘Authorization: Basic ‘.base64_encode($infoClient[‘client_id’].’:’.$infoClient[‘client_secret’])’

And the following postfields :

‘grant_type’ => ‘authorization_code’,
‘code’ => $_GET[‘code’],
‘redirect_uri’ => $infoClient[‘redirect_uri’]

But I’m still geting a 400 code with the message : "Missing parameter: grant_type".

Can you help here?

#2

I suspect there might be some issue in the way the request is built. :thinking:
Can you post a snippet of your code?

#3

Sure, this is pretty much what I’m doing here :

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, "https://oauth.pipedrive.com/oauth/token");
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, array(
        'grant_type' => 'authorization_code',
        'code' => $_GET['code'],
        'redirect_uri' => "https://myapp.com/callback"
    ));
    curl_setopt($curl, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/x-www-form-urlencoded',
        'Authorization: Basic '.base64_encode($client_id.':'.$client_secret)
    ));
    curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $response = json_decode(curl_exec($curl), 1);
    if ($response == null) {
        throw new Exception(curl_error($curl), curl_errno($curl));
    }
    curl_close($curl);
#4

here’s the problem :slight_smile:
You forgot to prepare the data with http_build_query()

Try

curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query(array(
   'grant_type' => 'authorization_code',
   'code' => $_GET['code'],
   'redirect_uri' => "https://myapp.com/callback"
)));
1 Like
#5

Thanks a lot Dani it worked!

1 Like