PHP code example of crashingberries / pipedrive

1. Go to this page and download the library: Download crashingberries/pipedrive 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/ */

    

crashingberries / pipedrive example snippets




_start();

// Client configuration
$apiToken = 'YOUR_API_TOKEN_HERE';

$client = new Pipedrive\Client(null, null, null, $apiToken); // First 3 parameters are for OAuth2

try {
    $response = $client->getUsers()->getCurrentUserData();
    echo '<pre>';
    var_dump($response);
    echo '</pre>';
} catch (\Pipedrive\APIException $e) {
    echo $e;
}

$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

$client = new Pipedrive\Client($oAuthClientId, $oAuthClientSecret, $oAuthRedirectUri);

$authUrl = $client->auth()->buildAuthorizationUrl();
header('Location: ' . filter_var($authUrl, FILTER_SANITIZE_URL));

try {
    $client->auth()->authorize($_GET['code']);
} catch (Pipedrive\Exceptions\OAuthProviderException $ex) {
    // handle exception
}

if ($client->auth()->isTokenExpired()) {
    try {
        $client->auth()->refreshToken();
    } catch (Pipedrive\Exceptions\OAuthProviderException $ex) {
        // handle exception
    }
}

// store token
$_SESSION['access_token'] = Pipedrive\Configuration::$oAuthToken;

Pipedrive\Configuration::$oAuthTokenUpdateCallback = function($token) {
    // use session or some other way to persist the $token
    $_SESSION['access_token'] = $token;
};

// load token later...
Pipedrive\Configuration::$oAuthToken = $_SESSION['access_token'];

// Set other configuration, then instantiate client
$client = new Pipedrive\Client();



_start();

// Client configuration
$oAuthClientId = 'oAuthClientId';
$oAuthClientSecret = 'oAuthClientSecret';
$oAuthRedirectUri = 'http://' . $_SERVER['HTTP_HOST'] . '/authcallback.php';

$client = new Pipedrive\Client($oAuthClientId, $oAuthClientSecret, $oAuthRedirectUri);

// callback stores token for reuse when token is updated
Pipedrive\Configuration::$oAuthTokenUpdateCallback = function($token) {
    $_SESSION['access_token'] = $token;
};

// check if a token is available
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
    // set access token in configuration
    Pipedrive\Configuration::$oAuthToken = $_SESSION['access_token'];

    try {
        $response = $client->getUsers()->getCurrentUserData();
        echo '<pre>';
        var_dump($response);
        echo '</pre>';
    } catch (\Pipedrive\APIException $e) {
        echo $e;
    }

    // now you can use $client to make endpoint calls
    // client will automatically refresh the token when it expires and call the token update callback
} else {
    // redirect user to a page that handles authorization
    header('Location: ' . filter_var($oAuthRedirectUri, FILTER_SANITIZE_URL));
}


on_start();

// Client configuration
$oAuthClientId = 'oAuthClientId';
$oAuthClientSecret = 'oAuthClientSecret';
$oAuthRedirectUri = 'http://' . $_SERVER['HTTP_HOST'] . '/authcallback.php';

$client = new Pipedrive\Client($oAuthClientId, $oAuthClientSecret, $oAuthRedirectUri);

// callback stores token for reuse when token is updated
Pipedrive\Configuration::$oAuthTokenUpdateCallback = function($token) {
    $_SESSION['access_token'] = $token;
};

if (! isset($_GET['code'])) {
    // if authorization code is absent, redirect to authorization page
    $authUrl = $client->auth()->buildAuthorizationUrl();
    header('Location: ' . filter_var($authUrl, FILTER_SANITIZE_URL));
} else {
    try {
        // authorize client (calls token update callback as well)
        $token = $client->auth()->authorize($_GET['code']);

        // resume user activity
        $redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . '/';
        header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
    } catch (Pipedrive\Exceptions\OAuthProviderException $ex) {
        // handle exception
    }
}

$activities = $client->getActivities();

function deleteMultipleActivitiesInBulk($ids)

$ids = 'ids';

$activities->deleteMultipleActivitiesInBulk($ids);


function getAllActivitiesAssignedToAParticularUser($options)

$userId = 119;
$collect['userId'] = $userId;

$filterId = 119;
$collect['filterId'] = $filterId;

$type = 'type';
$collect['type'] = $type;

$start = 0;
$collect['start'] = $start;

$limit = 119;
$collect['limit'] = $limit;

$startDate = date("D M d, Y G:i");
$collect['startDate'] = $startDate;

$endDate = date("D M d, Y G:i");
$collect['endDate'] = $endDate;

$done = int::ENUM_0;
$collect['done'] = $done;


$activities->getAllActivitiesAssignedToAParticularUser($collect);


function addAnActivity($options)

$subject = 'subject';
$collect['subject'] = $subject;

$type = 'type';
$collect['type'] = $type;

$done = int::ENUM_0;
$collect['done'] = $done;

$dueDate = date("D M d, Y G:i");
$collect['dueDate'] = $dueDate;

$dueTime = 'due_time';
$collect['dueTime'] = $dueTime;

$duration = 'duration';
$collect['duration'] = $duration;

$userId = 119;
$collect['userId'] = $userId;

$dealId = 119;
$collect['dealId'] = $dealId;

$personId = 119;
$collect['personId'] = $personId;

$participants = 'participants';
$collect['participants'] = $participants;

$orgId = 119;
$collect['orgId'] = $orgId;

$note = 'note';
$collect['note'] = $note;


$activities->addAnActivity($collect);


function deleteAnActivity($id)

$id = 119;

$activities->deleteAnActivity($id);


function getDetailsOfAnActivity($id)

$id = 119;

$activities->getDetailsOfAnActivity($id);


function updateEditAnActivity($options)

$id = 119;
$collect['id'] = $id;

$subject = 'subject';
$collect['subject'] = $subject;

$type = 'type';
$collect['type'] = $type;

$done = int::ENUM_0;
$collect['done'] = $done;

$dueDate = date("D M d, Y G:i");
$collect['dueDate'] = $dueDate;

$dueTime = 'due_time';
$collect['dueTime'] = $dueTime;

$duration = 'duration';
$collect['duration'] = $duration;

$userId = 119;
$collect['userId'] = $userId;

$dealId = 119;
$collect['dealId'] = $dealId;

$personId = 119;
$collect['personId'] = $personId;

$participants = 'participants';
$collect['participants'] = $participants;

$orgId = 119;
$collect['orgId'] = $orgId;

$note = 'note';
$collect['note'] = $note;


$activities->updateEditAnActivity($collect);


$activityFields = $client->getActivityFields();

function getAllFieldsForAnActivity()


$activityFields->getAllFieldsForAnActivity();


$activityTypes = $client->getActivityTypes();

function deleteMultipleActivityTypesInBulk($ids)

$ids = 'ids';

$activityTypes->deleteMultipleActivityTypesInBulk($ids);


function getAllActivityTypes()


$activityTypes->getAllActivityTypes();


function addNewActivityType($options)

$name = 'name';
$collect['name'] = $name;

$iconKey = string::TASK;
$collect['iconKey'] = $iconKey;

$color = 'color';
$collect['color'] = $color;


$activityTypes->addNewActivityType($collect);


function deleteAnActivityType($id)

$id = 119;

$activityTypes->deleteAnActivityType($id);


function updateEditActivityType($options)

$id = 119;
$collect['id'] = $id;

$name = 'name';
$collect['name'] = $name;

$iconKey = string::TASK;
$collect['iconKey'] = $iconKey;

$color = 'color';
$collect['color'] = $color;

$orderNr = 119;
$collect['orderNr'] = $orderNr;


$activityTypes->updateEditActivityType($collect);


$callLogs = $client->getCallLogs();

function getAllCallLogsAssignedToAParticularUser($options)

$start = 0;
$options['start'] = $start;

$limit = 119;
$options['limit'] = $limit;

$callLogs->getAllCallLogsAssignedToAParticularUser($options);


function getDetailsOfACallLog($id)

$id = 1;

$callLogs->getDetailsOfACallLog($id);


function addACallLog($collect)


$subject = 'subject';
$collect['subject'] = $subject;

$duration = 60;
$collect['duration'] = $duration;

$outcome = 'connected'
$collect['outcome'] = $connected;

$fromPhoneNumber = '+55 555 5555';
$collect['from_phone_number'] = $fromPhoneNumber;

$fromPhoneNumber = '+55 555 5556';
$collect['to_phone_number'] = $fromPhoneNumber;

$startTime = '2021-01-30 22:30:00';
$collect['start_time'] = $startTime;

$endTime = '2021-01-30 22:31:00';
$collect['end_time'] = $endTime;

$personId = 1;
$collect['person_id'] = $personId;

$orgId = 1;
$collect['org_id'] = $orgId;

$dealId = 1;
$collect['deal_id'] = $dealId;

$note = 'note';
$collect['note'] = $note;

$callLogs->addACallLog($collect);


function attachAnAudioFileToTheCallLog($id, $collect)


$id = 'id';

$file = "PathToFile";
$collect['file'] = $file;

$callLogs->attachAnAudioFileToTheCallLog($id, $collect);


function deleteACallLog($id)


$id = 'id';

$callLogs->deleteACallLog($id);


$currencies = $client->getCurrencies();

function getAllSupportedCurrencies($term = null)

$term = 'term';

$result = $currencies->getAllSupportedCurrencies($term);


$dealFields = $client->getDealFields();

function deleteMultipleDealFieldsInBulk($ids)

$ids = 'ids';

$dealFields->deleteMultipleDealFieldsInBulk($ids);


function getAllDealFields($options)

$start = 0;
$collect['start'] = $start;

$limit = 119;
$collect['limit'] = $limit;


$dealFields->getAllDealFields($collect);


function addANewDealField($body = null)

$body = array('key' => 'value');

$dealFields->addANewDealField($body);


function deleteADealField($id)

$id = 119;

$dealFields->deleteADealField($id);


function getOneDealField($id)

$id = 119;

$dealFields->getOneDealField($id);


function updateADealField($options)

$id = 119;
$collect['id'] = $id;

$name = 'name';
$collect['name'] = $name;

$options = 'options';
$collect['options'] = $options;


$dealFields->updateADealField($collect);


$deals = $client->getDeals();

function deleteMultipleDealsInBulk($ids)

$ids = 'ids';

$result = $deals->deleteMultipleDealsInBulk($ids);


function getAllDeals($options)

$userId = 119;
$collect['userId'] = $userId;

$filterId = 119;
$collect['filterId'] = $filterId;

$stageId = 119;
$collect['stageId'] = $stageId;

$status = string::ALL_NOT_DELETED;
$collect['status'] = $status;

$start = 0;
$collect['start'] = $start;

$limit = 119;
$collect['limit'] = $limit;

$sort = 'sort';
$collect['sort'] = $sort;

$ownedByYou = int::ENUM_0;
$collect['ownedByYou'] = $ownedByYou;


$result = $deals->getAllDeals($collect);


function searchDeals($options)

$term = 'term';
$collect['term'] = $term;

$results = $deals->searchDeals($collect);


function addADeal($body = null)

$body = array('key' => 'value');

$result = $deals->addADeal($body);


function getDealsSummary($options)

$status = string::OPEN;
$collect['status'] = $status;

$filterId = 119;
$collect['filterId'] = $filterId;

$userId = 119;
$collect['userId'] = $userId;

$stageId = 119;
$collect['stageId'] = $stageId;


$result = $deals->getDealsSummary($collect);


function getDealsTimeline($options)

$startDate = date("D M d, Y G:i");
$collect['startDate'] = $startDate;

$interval = string::DAY;
$collect['interval'] = $interval;

$amount = 119;
$collect['amount'] = $amount;

$fieldKey = 'field_key';
$collect['fieldKey'] = $fieldKey;

$userId = 119;
$collect['userId'] = $userId;

$pipelineId = 119;
$collect['pipelineId'] = $pipelineId;

$filterId = 119;
$collect['filterId'] = $filterId;

$excludeDeals = int::ENUM_0;
$collect['excludeDeals'] = $excludeDeals;

$totalsConvertCurrency = 'totals_convert_currency';
$collect['totalsConvertCurrency'] = $totalsConvertCurrency;


$result = $deals->getDealsTimeline($collect);


function deleteADeal($id)

$id = 119;

$result = $deals->deleteADeal($id);


function getDetailsOfADeal($id)

$id = 119;

$result = $deals->getDetailsOfADeal($id);


function updateADeal($options)

$id = 27;
$collect['id'] = $id;

$title = 'title';
$collect['title'] = $title;

$value = 'value';
$collect['value'] = $value;

$currency = 'currency';
$collect['currency'] = $currency;

$userId = 27;
$collect['user_id'] = $userId;

$personId = 27;
$collect['person_id'] = $personId;

$orgId = 27;
$collect['org_id'] = $orgId;

$stageId = 27;
$collect['stage_id'] = $stageId;

$status = string::OPEN;
$collect['status'] = $status;

$probability = 27.9633801840075;
$collect['probability'] = $probability;

$lostReason = 'lost_reason';
$collect['lost_reason'] = $lostReason;

$visibleTo = int::ENUM_1;
$collect['visible_to'] = $visibleTo;


$result = $deals->updateADeal($collect);


function listActivitiesAssociatedWithADeal($options)

$id = 27;
$collect['id'] = $id;

$start = 0;
$collect['start'] = $start;

$limit = 27;
$collect['limit'] = $limit;

$done = int::ENUM_0;
$collect['done'] = $done;

$exclude = 'exclude';
$collect['exclude'] = $exclude;


$deals->listActivitiesAssociatedWithADeal($collect);


function createDuplicateDeal($id)

$id = 27;

$result = $deals->createDuplicateDeal($id);


function listFilesAttachedToADeal($options)

$id = 27;
$collect['id'] = $id;

$start = 0;
$collect['start'] = $start;

$limit = 27;
$collect['limit'] = $limit;

$tachedToADeal($collect);


function listUpdatesAboutADeal($options)

$id = 27;
$collect['id'] = $id;

$start = 0;
$collect['start'] = $start;

$limit = 27;
$collect['limit'] = $limit;


$deals->listUpdatesAboutADeal($collect);


function listFollowersOfADeal($id)

$id = 27;

$deals->listFollowersOfADeal($id);


function addAFollowerToADeal($options)

$id = 27;
$collect['id'] = $id;

$userId = 27;
$collect['userId'] = $userId;


$result = $deals->addAFollowerToADeal($collect);


function deleteAFollowerFromADeal($options)

$id = 27;
$collect['id'] = $id;

$followerId = 27;
$collect['followerId'] = $followerId;


$result = $deals->deleteAFollowerFromADeal($collect);


function listMailMessagesAssociatedWithADeal($options)

$id = 27;
$collect['id'] = $id;

$start = 0;
$collect['start'] = $start;

$limit = 27;
$collect['limit'] = $limit;


$deals->listMailMessagesAssociatedWithADeal($collect);


function updateMergeTwoDeals($options)