1. Go to this page and download the library: Download christrung/client-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
christrung / client-php example snippets
use Pipedrive\Configuration;
api_key
$config = (new Pipedrive\Configuration())->setApiKey('api_token', 'YOUR_API_KEY');
$apiInstance = new Pipedrive\Api\ActivitiesApi(
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
// This is optional, `GuzzleHttp\Client` will be used as default.
new GuzzleHttp\Client(),
$config
);
try {
$result = $apiInstance->activitiesGet();
echo '<pre>';
print_r($result);
echo '</pre>';
} catch (Exception $e) {
echo 'Exception when calling ActivitiesApi->activitiesDelete: ', $e->getMessage(), PHP_EOL;
}
$oAuthClientId = 'oAuthClientId'; // OAuth 2 Client ID
$oAuthClientSecret = 'oAuthClientSecret'; // OAuth 2 Client Secret
$oAuthRedirectUri = 'https://example.com/oauth/callback'; // OAuth 2 Redirection endpoint or Callback Uri
$config = (new Pipedrive\Configuration());
$config->setClientId($oAuthClientId);
$config->setClientSecret($oAuthClientSecret);
$config->setOauthRedirectUri($oAuthRedirectUri);
$dealsApiInstance = new DealsApi(null, $config);
// load token later...
$config->setAccessToken($_SESSION['token']->access_token);
// If you want to set all of the OAuth2 related fields at once from the token gotten from Pipedrive OAuth server
// you can use the updateOAuthRelatedFields() function
$config->updateOAuthRelatedFields($_SESSION['token']);
// This will set the access token, expiresIn, expiresAt, scope and host attributes in the Configuration class
// In order to get automatic access token refreshing, you will still need the client ID, client secret and redirectURI
// Set other configuration, then instantiate client
$activitiesApiInstance = new ActivitiesApi(null, $config);
$config = (new Pipedrive\Configuration());
$config->updateOAuthRelatedFields(/* ... */);
// this will revoke all user tokens
$config->revokeToken('refresh_token');
/* OR */
// this will revoke only access token
$config->revokeToken('access_token');
use Pipedrive\Api\DealsApi;
use Pipedrive\Configuration;
onfig->setOauthRedirectUri('http://' . $_SERVER['HTTP_HOST'] . '/authcallback.php');
$config->setClientSecret('YOUR_CLIENT_SECRET');
$config->setClientId('YOUR_CLIENT_ID');
//$usersApiInstance = new UsersApi(null, $config);
$dealsApiInstance = new DealsApi(null, $config);
// check if a token is available
if (isset($_SESSION['token']) && $_SESSION['token']) {
// set access token in configuration
$config->updateOAuthRelatedFields($_SESSION['token']);
try {
$dealsResponse = $dealsApiInstance->getDeals();
echo '<pre>';
print_r($dealsResponse);
echo '</pre>';
} catch (Exception $e) {
echo 'Exception when trying to get user info', $e, PHP_EOL;
}
} else {
header('Location: ' . filter_var($config->getAuthorizationPageUrl(), FILTER_SANITIZE_URL));
}