Skip to content

Latest commit

 

History

History
312 lines (237 loc) · 5.47 KB

MIGRATION-5.x.md

File metadata and controls

312 lines (237 loc) · 5.47 KB

Migration Guide from 4.x to 5.x

Configuration

API Token

Configure authorization in case of api_token usage.

4.x 5.x
No configuration needed, api_token should have been set when the Client instance was created.

Default configuration should be updated by setting the api key with the api_token prefix.

use Pipedrive\Configuration;

$config = new Configuration();
$config->setApiKey('api_token', 'YOUR_API_TOKEN');

OAuth

Configure authorization in case of OAuth 2.0 usage.

4.x 5.x
OAuth 2.0 configuration properties should have been set
when Client instance was created.

Stored user tokens have to be set by re-assigning $token object with custom values:

use Pipedrive\Configuration;

Configuration::$token = (object) [
    'accessToken' => 'USER_ACCESS_TOKEN',
    'refreshToken' => 'USER_REFRESH_TOKEN',
    'expiry' => 'USER_ACCESS_TOKEN_EXPIRATION_MS',
    'tokenType' => 'Bearer',
];

$oAuthTokenUpdateCallback has to be defined to handle callback update tokens in storage.

Configuration::$oAuthTokenUpdateCallback = function($token) {
    // use session or some other way to persist the $token
};
Default configuration should be updated with OAuth 2.0 properties.
use Pipedrive\Configuration;

$config = new Configuration();
$config->setClientId('YOUR_APP_CLIENT_ID');
$config->setClientSecret('YOUR_APP_CLIENT_SECRET');
$config->setOauthRedirectUri('YOUR_APP_REDIRECT_URI');
$config->setOAuthTokenUpdateCallback(function () {
    // use session or some other way to persist the $token
});

Stored user tokens have to be set with updateOAuthRelatedFields method of Configuration instance:

$config->updateOAuthRelatedFields([
    'expires_in' => 'USER_ACCESS_TOKEN_EXPIRATION_MS',
    'access_token' => 'USER_ACCESS_TOKEN',
    'refresh_token' => 'USER_REFRESH_TOKEN',
    'api_domain' => 'USER_API_DOMAIN',
]);

Authentication

4.x 5.x
Create an instance of Client and navigate the user to authorization URL:
use Pipedrive\Client;

$client = new Client(/* ... */);

$client->auth()->buildAuthorizationUrl());

Handle the incoming request, exchange code query param and store $token.

use Pipedrive\Client;

$code = /* get query param value */;

$client = new Client(/* ... */);

$token = $client->auth()->authorize($code);
Update config with your app properties.
use Pipedrive\Configuration;

$config = new Configuration();
/* ... */

$config->getAuthorizationPageUrl();

Handle incoming request, exchange code query param and store $token.

use Pipedrive\Configuration;

$config = new Configuration();
/* ... */

$config->authorize($code);

This will automatically set token properties (using updateOAuthRelatedFields) and call setOAuthTokenUpdateCallback callback.


API requests

Here are some examples based on the deal entity.

List deals

4.x 5.x
use Pipedrive\Client;

/* ...configuration needed here... */

$client = new Client(/* ... */);
$client->getDeals()->getAllDeals([
    'limit' => 10,
    'status' => 'open',
]);
use Pipedrive\Client;

$config = new Configuration();

/* ...configuration needed here... */

$dealsApiInstance = new DealsApi(null, $config);
$response = $dealsApiInstance->getDeals(
    null,
    null,
    null,
    'open',
    0,
    10,
);

Add new deal

4.x 5.x
use Pipedrive\Client;

/* ...configuration needed here... */

$client = new Client(/* ... */);
$response = $client->getDeals()->addADeal([
    'title' => 'DEAL_TITLE'
]);
use Pipedrive\Client;
use Pipedrive\Model\NewDeal;

$config = new Configuration();

/* ...configuration needed here... */

$dealsApiInstance = new DealsApi(null, $config);
$response = $dealsApiInstance->addDeal(new NewDeal([
    'title' => 'DEAL_TITLE',
]));

Update deal

4.x 5.x
use Pipedrive\Client;

/* ...configuration needed here... */

$client = new Client(/* ... */);
$response = $client->getDeals()->updateADeal([
    'id' => 'DEAL_ID',
    'title' => 'DEAL_TITLE_UPDATED'
]);
use Pipedrive\Client;
use Pipedrive\Model\NewDeal;

$config = new Configuration();

/* ...configuration needed here... */

$dealId = /* DEAL_ID */;
$dealsApiInstance = new DealsApi(null, $config);
$response = $dealsApiInstance->updateDeal($dealId, new UpdateDealRequest([
    'title' => 'DEAL_TITLE_UPDATED',
]));

Delete deal

4.x 5.x
use Pipedrive\Client;

/* ...configuration needed here... */

$client = new Client(/* ... */);
$response = $client->getDeals()->deleteADeal('DEAL_ID');
use Pipedrive\Client;

$config = new Configuration();

/* ...configuration needed here... */

$dealId = /* DEAL_ID */;
$dealsApiInstance = new DealsApi(null, $config);
$response = $dealsApiInstance->deleteDeal($dealId);