Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 47 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,67 @@
PipeDrive-api-php
============
=================

PHP API client library for the PipeDrive CRM
PHP API client library for the PipeDrive CRM.

Only some basic functionality required for my current project has been added. However the basic blocks are to make use of the whole API including file uploading.

Recommend you install this library through composer. https://packagist.org/packages/benhawker/pipedrive
Recommend you install this library through composer: https://packagist.org/packages/benhawker/pipedrive

composer require benhawker/pipedrive dev-master

API Docs can be found here: https://developers.pipedrive.com/v1

Example:

Example:
--------

```php
use Benhawker\Pipedrive\Pipedrive;
use Benhawker\Pipedrive\Pipedrive;

$pipedrive = new Pipedrive('0deceea867202fcf3889cd507ef93a91789f7e3a');

/**
* Add company.
*/
$organization['name'] = 'Explorer';

$pipedrive = new Pipedrive('0deceea867202fcf3889cd507ef93a91789f7e3a');
$organization = $pipedrive->organizations()->add($organization);

//add user
$person['name'] = 'John Smith';
/**
* Add customer.
*/
$person['name'] = 'John Smith';
$person['org_id'] = $organization['data']['id'];

$person = $pipedrive->persons()->add($person);
$person = $pipedrive->persons()->add($person);

//add note to user
$note['content'] = 'example note';
$note['person_id'] = $person['data']['id'];
/**
* Add note to customer.
*/
$note['content'] = 'example note';
$note['person_id'] = $person['data']['id'];

$pipedrive->notes()->add($note);
$pipedrive->notes()->add($note);

//add deal to user
deal['title'] = 'example title';
$deal['stage_id'] = 8;
$deal['person_id'] = $person['data']['id'];
/**
* Add deal to customer.
*/
$deal['title'] = 'example title';
$deal['stage_id'] = 8;
$deal['person_id'] = $person['data']['id'];

$pipedrive->deals()->add($deal);
$pipedrive->deals()->add($deal);

//add activity
$activity = array(
'subject' => 'Example send brochure',
'type' => 'send-brochure',
'person_id' => 17686,
'user_id' => 190870,
'deal_id' => 88,
'due_date' => date('Y-m-d')
);
/**
* Add activity.
*/
$activity = array(
'subject' => 'Example send brochure',
'type' => 'send-brochure',
'person_id' => 17686,
'user_id' => 190870,
'deal_id' => 88,
'due_date' => date('Y-m-d')
);

$pipedrive->activities()->add($activity);
```
7 changes: 3 additions & 4 deletions src/Benhawker/Pipedrive/Library/Activities.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Activities
protected $curl;

/**
* Initialise the object load master class
* Initialize the object load master class
*/
public function __construct(\Benhawker\Pipedrive\Pipedrive $master)
{
Expand All @@ -32,12 +32,11 @@ public function __construct(\Benhawker\Pipedrive\Pipedrive $master)
/**
* Adds a activity
*
* @param array $data activity detials
* @return array returns detials of the activity
* @param array $data activity details
* @return array returns details of the activity
*/
public function add(array $data)
{

//if there is no subject or type set chuck error as both of the fields are required
if (!isset($data['subject']) or !isset($data['type'])) {
throw new PipedriveMissingFieldError('You must include both a "subject" and "type" field when inserting a note');
Expand Down
20 changes: 10 additions & 10 deletions src/Benhawker/Pipedrive/Library/Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ class Curl
public $curl;

/**
* Initialise the cURL session and set headers
* Initialize the cURL session and set headers
*/
public function __construct($url, $apiKey)
{
//set URL and API Key
$this->url = $url;
$this->apiKey = $apiKey;

//Intialise cURL session
//Initialize cURL session
$this->curl = curl_init();
//Set up options for cURL session
$this->setOpt(CURLOPT_USERAGENT, self::USER_AGENT)
Expand Down Expand Up @@ -67,7 +67,7 @@ public function __destruct()
public function get($method, $data = array())
{
//set cURL transfer option for get request
// and get ouput
// and get output
return $this->createEndPoint($method, $data)
->setOpt(CURLOPT_CUSTOMREQUEST, 'GET')
->setopt(CURLOPT_HTTPGET, true)
Expand All @@ -83,7 +83,7 @@ public function get($method, $data = array())
public function post($method, array $data)
{
//set cURL transfer option for post request
// and get ouput
// and get output
return $this->createEndPoint($method)
->setOpt(CURLOPT_CUSTOMREQUEST, 'POST')
->setOpt(CURLOPT_POST, true)
Expand All @@ -100,7 +100,7 @@ public function post($method, array $data)
public function put($method, array $data)
{
//set cURL transfer option for post request
// and get ouput
// and get output
return $this->createEndPoint($method)
->setOpt(CURLOPT_CUSTOMREQUEST, 'PUT')
->setOpt(CURLOPT_POSTFIELDS, http_build_query($data))
Expand All @@ -116,7 +116,7 @@ public function put($method, array $data)
public function delete($method)
{
//set cURL transfer option for delete request
// and get ouput
// and get output
return $this->createEndPoint($method)
->setOpt(CURLOPT_CUSTOMREQUEST, 'DELETE')
->exec();
Expand All @@ -125,7 +125,7 @@ public function delete($method)
/**
* Execute current cURL session
*
* @return array decoded json ouput
* @return array decoded json output
*/
protected function exec()
{
Expand Down Expand Up @@ -203,9 +203,9 @@ protected function createEndPoint($method, $data = array())
protected function postfields($data)
{
if (is_array($data)) {
//if mulitdimensional array
//if multidimensional array
if ($this->isArrayMultiDim($data)) {
// build bultidimensial query
// build multidimensional query
$data = $this->httpBuildMultiQuery($data);
} else {
//loop through array
Expand All @@ -232,7 +232,7 @@ protected function postfields($data)
}

/**
* Build multidimenianl query
* Build multidimensional query
* from: https://github.com/php-curl-class/php-curl-class
*
* @param array $data post data
Expand Down
6 changes: 3 additions & 3 deletions src/Benhawker/Pipedrive/Library/DealFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class DealFields
protected $curl;

/**
* Initialise the object load master class
* Initialize the object load master class
*/
public function __construct(\Benhawker\Pipedrive\Pipedrive $master)
{
Expand All @@ -42,7 +42,7 @@ public function getAll()
{
return $this->curl->get('dealFields');
}

/**
* Returns a deal field
*
Expand All @@ -57,7 +57,7 @@ public function getById($id)
/**
* Adds a dealField
*
* @param array $data deal field detials
* @param array $data deal field details
* @return array returns details of the deal field
*/
public function add(array $data)
Expand Down
22 changes: 11 additions & 11 deletions src/Benhawker/Pipedrive/Library/Deals.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Deals
protected $curl;

/**
* Initialise the object load master class
* Initialize the object load master class
*/
public function __construct(\Benhawker\Pipedrive\Pipedrive $master)
{
Expand All @@ -35,7 +35,7 @@ public function __construct(\Benhawker\Pipedrive\Pipedrive $master)
* Returns a deal
*
* @param int $id pipedrive deals id
* @return array returns detials of a deal
* @return array returns details of a deal
*/
public function getById($id)
{
Expand All @@ -46,7 +46,7 @@ public function getById($id)
* Returns a deal / deals
*
* @param string $name pipedrive deals title
* @return array returns detials of a deal
* @return array returns details of a deal
*/
public function getByName($name, $personId=null, $orgId=null)
{
Expand Down Expand Up @@ -79,8 +79,8 @@ public function products(array $data)
/**
* Adds a deal
*
* @param array $data deal detials
* @return array returns detials of the deal
* @param array $data deal details
* @return array returns details of the deal
*/
public function add(array $data)
{
Expand All @@ -91,13 +91,13 @@ public function add(array $data)

return $this->curl->post('deals', $data);
}

/**
* Adds a product to a deal
*
* @param int $dealId deal id
* @param array $data deal and product detials
* @return array returns detials of the deal-product
* @param array $data deal and product details
* @return array returns details of the deal-product
* @throws PipedriveMissingFieldError
*/
public function addProduct($dealId, array $data)
Expand All @@ -122,8 +122,8 @@ public function addProduct($dealId, array $data)
* Updates a deal
*
* @param int $dealId pipedrives deal Id
* @param array $data new detials of deal
* @return array returns detials of a deal
* @param array $data new details of deal
* @return array returns details of a deal
*/
public function update($dealId, array $data = array())
{
Expand All @@ -135,7 +135,7 @@ public function update($dealId, array $data = array())
*
* @param int $dealId deal id
* @param int $stageId stage id
* @return array returns detials of the deal
* @return array returns details of the deal
*/
public function moveStage($dealId, $stageId)
{
Expand Down
8 changes: 4 additions & 4 deletions src/Benhawker/Pipedrive/Library/Notes.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Notes
protected $curl;

/**
* Initialise the object load master class
* Initialize the object load master class
*/
public function __construct(\Benhawker\Pipedrive\Pipedrive $master)
{
Expand All @@ -31,8 +31,8 @@ public function __construct(\Benhawker\Pipedrive\Pipedrive $master)
/**
* Adds a note
*
* @param array $data note detials
* @return array returns detials of the note
* @param array $data note details
* @return array returns details of the note
*/
public function add(array $data)
{
Expand All @@ -41,7 +41,7 @@ public function add(array $data)
throw new PipedriveMissingFieldError('You must include a "content" field when inserting a note');
}

//if there is no deal, person, organisation id set throw error as one of the fields is required
//if there is no deal, person, organization id set throw error as one of the fields is required
if (!isset($data['deal_id']) && !isset($data['person_id']) && !isset($data['org_id'])) {
throw new PipedriveMissingFieldError('You must include one of the following "deal_id", "person_id", "org_id" field when inserting a note');
}
Expand Down
Loading