Authorization exception using https://github.com/pipedrive/client-php

Hello guys! I was building integration to my backend using PHP, I did everything by this guide, but when I try to make a request to API I get Authorization Exception. I used oAuth, I even got access token, I tried hard code this token to my code, but get Authorization Exception.
Here I’ll show my simplified version of code:

use Pipedrive\Client;
use Pipedrive\Configuration;

class PipedriveAuthService
{
    public function addDeal()
    {
        Configuration::$oAuthToken = '333333333333333333333333333333333333333333333333';
        $client = new Client(config('pipedrive.client_id'), config('pipedrive.client_secret'), url('/') . '/auth/pipedrive/callback');
        $client->getDeals()->addADeal(['title' => 'awesome deal']);
    }
}

If someone could help, it would be nice, thank you for your time.

Hey @elijah

Welcome to the community :wave:

I assume you have an OAuth callback handler similar to GitHub - pipedrive/client-php: Pipedrive API client for PHP. In that case, the access token will usually be set as part of the session variables (along with refresh token, scopes, and other details) & the token updation is taken care of by oAuthTokenUpdateCallback.

Thanks for sharing the code snippet. I suspect if the value for oAuthToken is properly assigned.

Fom client-php/Client.php at 93fd572a423d797e525a77bfe33ce94a0571edeb · pipedrive/client-php · GitHub

You would notice that Configuration::$oAuthToken actually contains an object, similar to the one below

object(Pipedrive\Models\OAuthToken)#3 (6) { 
["accessToken"]=> string(58) "1037lollol:lololololo:mysecrettokenthingob80ef888a9" 
["tokenType"]=> string(6) "Bearer" 
["expiresIn"]=> int(3599) 
["scope"]=> string(4) "base" 
["expiry"]=> int(1639488502) 
["refreshToken"]=> string(58) "11037lollol:lololololo:mysecretrefreshtokenthingob80ef8" 
}

I guess what you have been attempting to do is to set the value of Configuration::$oAuthToken->accessToken ? I would recommend obtaining the access token via the OAuth callback handler as it is much cleaner and takes care of refreshes automatically.

Feel free to share the details of the error that you are facing

Let me know if it helps :slight_smile:

Hey hem! Thanks for your response! Actually I got through this issue by making request for deal creation using Guzzle Http Client. Now I encounter new problem, I’ve finished working with pipedrive in sandbox mode, everything I needed is now done, but I can’t find a way to switch from sandbox mode to production. In my sandbox account I can see client_id & client_secret, in my production account there is no such thing, so it probably as it should be by design, but what do I do to start using my app with production environment account? Google didn’t tell me. Thanks again!