Giter VIP home page Giter VIP logo

pipedrive's Introduction

Complete Pipedrive API client for PHP

Latest Stable Version Build Status Total Downloads

Contribute by referral code / link

This won't take much time. You could use my referral code or link to get up to 45 days completely free of charge. Just sign up using this link or add the code to the billing section:

pdp-devio

Consider donating

Do you like this package? Did you find it useful? Donate and support its development.

Donate


This package provides a complete framework agnostic Pipedrive CRM API client library for PHP. It includes all the resources listed on Pipedrive's documentation.

IMPORTANT: If you are using Laravel >= 5.8 make sure your version is > 2.1.0.

Feel free to drop me a message at [email protected] or tweet me at @IsraelOrtuno.

Quick start using API token (read below for OAuth)

$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';
$pipedrive = new Pipedrive($token);

// Easily access a Pipedrive resource and its values
$organization = $pipedrive->organizations->find(1);
var_dump($organization->getData());

// Also simple to update any Pipedrive resource value
$organization = $pipedrive->organizations->update(1, ['name' => 'Big Code']);
var_dump($organization->getData());

// Keep reading this documentation to find out more.

For a deeper knowledge of how to use this package, follow this index:

Important

Versions 1.x do not include OAuth support, update to version 2.x to use this feature.

Installation

You can install the package via composer require command:

composer require devio/pipedrive

Or simply add it to your composer.json dependences and run composer update:

"require": {
    "devio/pipedrive": "^2.0"
}

Usage

Create the Pipedrive instance

Devio\Pipedrive\Pipedrive class acts as Manager and will be responsible of resolving the different API resources available. Pipedrive supports two different authentication methods: via API token (for manual integrations) and with OAuth (for public and private apps). You can read more about it on the official documentation, here: https://pipedrive.readme.io/docs/core-api-concepts-authentication

Using API token

$token = 'PipedriveTokenHere';
$pipedrive = new Pipedrive($token);

NOTE: Consider storing this object into a global variable.

Using OAuth

To understand how the OAuth flow works, please read the documentation first.
You can find it here: https://pipedrive.readme.io/docs/marketplace-oauth-authorization

You will first need to create an app and retrieve client_id and client_secret. Please, read the official documentation to learn how to do that.
You can find all you need here: https://pipedrive.readme.io/docs/marketplace-creating-a-proper-app

Once you have your client_id, client_secret, and redirect_url, you can instantiate the class like this:

$pipedrive = Pipedrive::OAuth([
    'clientId' => '<your-client-id>',
    'clientSecret' => '<your-client-secret>',
    'redirectUrl' => '<your-redirect-url>',
    'storage' => new PipedriveTokenIO() // This is your implementation of the PipedriveTokenStorage interface (example below)
]);

The class will automatically handle the redirect to the authentication server and refresh token requests.

The only thing you need to provide is your own implementation of the PipedriveTokenStorage interface.

The purpose of this class is to read and write a PipedriveToken object, containing access_token, refresh_token, and expiresAt, giving you the ability to handle this information as you prefer (for example storing these properties in your preferred way).

Here's an example of how it can be implemented:

class PipedriveTokenIO implements \Devio\Pipedrive\PipedriveTokenStorage
{
    public function setToken(\Devio\Pipedrive\PipedriveToken $token) {
        $_SESSION['token'] = serialize($token); // or encrypt and store in the db, or anything else...
    }

    public function getToken() { // Returns a PipedriveToken instance 
        return isset($_SESSION['token']) ? unserialize($_SESSION['token']) : null;
    }
}

In this simple example, the PipedriveToken is simply stored and retrieved from the session. Which means that once the session expires, the user will be redirected to the authentication page.

You might want to store this object inside the database. Storing the whole object serialized could be the fastest way to do that, but you can also retrieve access token, refresh token, and the expiration time individually using the methods getAccessToken, getRefreshToken, and expiresAt. Like this:

public function setToken(\Devio\Pipedrive\PipedriveToken $token) {
    $token->getAccessToken(); // save it individually
    $token->getRefreshToken(); // save it individually
    $token->expiresAt(); // save it individually
}

Similarly, the object can be instantiated like so:

$token = new \Devio\Pipedrive\PipedriveToken([
    'accessToken' => 'xxxxx', // read it individually from the db
    'refreshToken' => 'xxxxx', // read it individually from the db
    'expiresAt' => 'xxxxx', // read it individually from the db
]);

Handling the callback

In the callback (the url you specified as redirectUrl), you should call the authorize method on the $pipedrive object, like so:

if(!empty($_GET['code'])) {
    $pipedrive->authorize($_GET['code']);
}

This will exchange the authorization code for the first access token, and store it using the setToken method you provided.

Resolve a Pipedrive API Resource

Once we have our Pipedrive instance, we are able to resolve any Pipedrive API Resource in many ways.

First you could do it calling the make() method:

// Organizations
$organizations = $pipedrive->make('organizations');
// Persons
$persons = $pipedrive->make('persons');
// ...

It also intercepts the magic method __get so we could do:

// Deals
$deals = $pipedrive->deals;
// Activities
$activities = $pipedrive->activities;
// ...

And just in case you prefer __call, you can use it, too:

// EmailMessages
$emailMessages = $pipedrive->emailMessages();
// GlobalMessages
$globalMessages = $pipedrive->globalMessages();
// ...

They are 3 different ways of doing the same thing, pick the one you like the most. It will automatically set the studly case version of the asked resource, so it will work with emailMessages, EmailMessages, email_messages...

IMPORTANT: Navigate to the src/Resources directory to find out all the resources available.

Performing a resource call

Available methods

All resources have various methods for performing the different API requests. Please, navigate to the resource class you would like to work with to find out all the methods available. Every method is documented and can also be found at Pipedrive API Docs page.

Every resource extends from Devio\Pipedrive\Resources\Basics\Resource where the most common methods are defined. Some of them are disabled for the resources that do not include them. Do not forget to check out the Traits included and some resources use, they define some other common calls to avoid code duplication.

Performing the Request

After resolved the resource we want to use, we are able to perform an API request. At this point, we only have to execute the endpoint we would like to access:

$organizations = $pipedrive->organizations->all();
//
$pipedrive->persons->update(1, ['name' => 'Israel Ortuno']);

Any of these methods will perform a synchronous request to the Pipedrive API.

Handling the response

Every Pipedrive API endpoint gives a response and this response is converted to a Devio\Pipedrive\Http\Response object to handle it:

$response = $pipedrive->organizations->all();

$organizations = $response->getData();

Response methods

The Response class has many methods available for accessing the response data:

isSuccess()

Check if the server responded the request was successful.

getContent()

Will provide the raw response provided by the Pipedrive API. Useful if you need specific control.

getData()

Get the response main data object which will include the information about the endpoint we are calling.

getAdditionalData()

Some responses include an additional data object with some extra information. Fetch this object with this method.

getStatusCode()

Get the response status code.

getHeaders()

Get the response headers.

Available resources

Every Resource logic is located at the src/Resources directory. However we'll mention every included resource here:

Resource Methods implemented Notes
Activities ✅ 6/6
ActivityFields ✅ 1/1
ActivityTypes ✅ 5/5
Currencies ✅ 1/1
DealFields ✅ 25/25
Deals ✅ 6/6
EmailMessages ✅ 4/4
EmailThreads ✅ 6/6
Files ✅ 8/8
Filters ✅ 6/6
GlobalMessages ✅ 2/2
Goals ⚠️ 5/6 Missing goal results method
Notes ✅ 5/5
NoteFields ✅ 1/1
OrganizationFields ✅ 6/6
OrganizationRelationships ✅ 5/5
Organizations ✅ 18/18
PermissionsSets ✅ 6/6
PersonFields ✅ 18/20
Persons ⚠️ 18/20 Missing add and delete pictures as getting required fields error.
Pipelines ⚠️ 6/8 Missing deals conversion rates and deals movements
ProductFields ✅ 6/6
Products ✅ 9/9
PushNotifications ✅ 4/4
Recents ✅ 1/1
Roles ⚠️ 0/11 Getting unathorized access
SearchResults ✅ 2/2
Stages ✅ 7/7
UserConnections ✅ 1/1
Users ⚠️ 13/20 Getting unathorized access when playing with roles and permissions
UserSettings ✅ 1/1

✅ Completed / ⚠️ Pipedrive API errors

The File Resource

The File resource is the only one that works a little bit different than others. While other resources may be intuitively used as most of them just require a plain array of tada, the File resource requires an \SplFileInfo instance to make it work:

$file = new \SplFileInfo('document.pdf');

$pipedrive->files->add([
    'file'   => $file,
    'person_id' => 1,
    // 'deal_id' => 1
]);

Actually, it is pretty simple. Just pass a \SplFileInfo instance to the file key of the options array and specify at least one of the elements it goes related to (deal, person, ...).

Configure and use in Laravel

If you are using Laravel, you could make use of the PipedriveServiceProvider and PipedriveFacade which will make the using of this package much more comfortable:

Service Provider and Facade

Include the PipedriveServiceProvider to the providers array in config/app.php and register the Laravel Facade.

'providers' => [
  ...
  Devio\Pipedrive\PipedriveServiceProvider::class,
  ...
],
'alias' => [
    ...
    'Pipedrive' => Devio\Pipedrive\PipedriveFacade::class,
    ...
]

The service configuration

Laravel includes a configuration file for storing external services information at config/services.php. We have to set up our Pipedrive token at that file like this:

'pipedrive' => [
    'token' => 'the pipedrive token'
]

Of course, as many other config parameters, you could store the token at your .env file or environment variable and fetch it using dotenv:

'pipedrive' => [
    'token' => env('PIPEDRIVE_TOKEN')
]

Using it

You could use it using the Laravel facade PipedriveFacade that we have previously loaded:

$organizations = Pipedrive::organizations()->all();
//
Pipedrive::persons()->add(['name' => 'John Doe']);

Also, resolve it out of the service container:

$pipedrive = app()->make('pipedrive');

Or even inject it wherever you may need using the Devio\Pipedrive\Pipedrive signature.

Contribute

Feel free to contribute via PR.

pipedrive's People

Contributors

3mg avatar bmarcinkowski avatar daniti avatar edvinaskrucas avatar fgibaux avatar hlagrid avatar israelortuno avatar janmikes avatar jfoucher avatar joemugen avatar jr-k avatar korridor avatar kw-pr avatar luccasaguilar avatar marivaldojr avatar mauriciovander avatar mstralka avatar orudenko86 avatar poethrenoff avatar rawburner avatar simensen avatar stayallive avatar webklex avatar zaszczyk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pipedrive's Issues

Call to undefined function camel_case()

Hi, thank you a lot for this library 👍
I have started using that, but I am getting error:

Call to undefined function Devio\Pipedrive\Resources\Basics\camel_case()

with code:
$pipedrive->make('organizations');

I see You use function camel_case() in:

src/Resources/Basics/Resource.php:123

However it is not defined anywhere, maybe it should be defined?

Add pagination to ListsActivities

This by default only returns 100 activities. One can improve to 500 activities by including the ["limit"=> 500] param but it will not paginate through additional resources even if they are available via the API. Can pagination be implemented?

Thanks!

Get activities from a deal

Thank you for providing a really simple to use library for Pipedrive.

I'm struggling to get the activities from a deal (according to the docs: https://developers.pipedrive.com/docs/api/v1), I tried it this way:
Pipedrive::deals()->find($dealId)->activities();
But that doesn't work.

Is it possible and how should I do this?

Object to array

is there any way to convert the response object to array recursively ??

Unable to get custom fields data using API

I was going through your API client, trying to use it to get custom fields from organizations and their related data. But i dont see any implementation for getting those fields.

Better/strict typehinting?

Hello there!

I just started using this library - everything works as expected, thought i have a bit pain with typehinting methods, so my IDE understands return types, like this:

screenshot 2018-09-25 17 23 45

As you can see from screenshot, it is not good programmer experience in code like that.

Is there any chance, this will get improved?

vanila php autoload

Hi there,

Great work on your project. I am just using PHP, no composer nor larvel. How do I autoload your files? trying to create instance of Pipedrive using below code but obviously it is throwing errors:

require_once('devio/pipedrive/pipedrive.php');
use Devio\Pipedrive;

$pd = new Pipedrive( "******" );

im getting errors of not finding class: Class 'Devio\Pipedrive'

Delete participants endpoint not working

The method \Devio\Pipedrive\Resources\Deals::deleteParticipant is not working, it produces an error "Participant ID not found". This code is not working:

public function deleteParticipant($id, $deal_participant_id)
{
return $this->request->delete(':id/participants', compact('id', 'deal_participant_id'));
}

But with this fix it works like expected:
public function deleteParticipant($id, $deal_participant_id)
{
return $this->request->delete(':id/participants/:deal_participant_id', compact('id', 'deal_participant_id'));
}

SearchFromField API

The results from the following function returns NULL. Any idea? thanks

$pipedrive->deals->searchFromField("Search Term", "Text", "title");

Resource is a reserved class name

I'm getting an error on PHP 7 / HHVM, as Resource is now a reserved name.

Fatal error: Uncaught Error: Cannot use '\\Devio\\Pipedrive\\Resources\\Basics\\Resource' as class name as it is reserved in vendor/devio/pipedrive/src/Resources/Pipelines.php

Renaming the Resource class name to something else fixed this issue.

Not compatible with Guzzle HTTP Client 5.x

In the composer.json it seems to be compatible but here is the error

Uncaught Error: Call to undefined method GuzzleHttp\Client::getConfig() in devio/pipedrive/src/Http/PipedriveClient.php:46

I cannot update to 6.x because of other dependencies. Anything to do?

Thanks

Error when composer require version >=2.1.0 (Laravel 5.7)

Hello!
Thanks a lot for this library!

Would like to start using it, but facing an issue while requiring any version >=2.1.0 (while 2.0.3 installs without errors).

I have laravel v5.7.28 and when I run composer require devio/pipedrive - I get the following output from composer:

Using version ^2.4 for devio/pipedrive
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Conclusion: remove laravel/framework v5.7.28
    - Conclusion: don't install laravel/framework v5.7.28
    - devio/pipedrive 2.4.0 requires laravel/helpers ^1.0 -> satisfiable by laravel/helpers[v1.0.0, v1.0.1, v1.1.0, v1.1.1].
    - devio/pipedrive 2.4.1 requires laravel/helpers ^1.0 -> satisfiable by laravel/helpers[v1.0.0, v1.0.1, v1.1.0, v1.1.1].
    - devio/pipedrive 2.4.2 requires laravel/helpers ^1.0 -> satisfiable by laravel/helpers[v1.0.0, v1.0.1, v1.1.0, v1.1.1].
    - laravel/helpers v1.0.0 requires illuminate/support ~5.8.0 -> satisfiable by illuminate/support[v5.8.0, v5.8.11, v5.8.12, v5.8.14, v5.8.15, v5.8.17, v5.8.18, v5.8.19, v5.8.2, v5.8.20, v5.8.22, v5.8.24, v5.8.27, v5.8.28, v5.8.29, v5.8.3, v5.8.30, v5.8.31, v5.8.32, v5.8.33, v5.8.34, v5.8.35, v5.8.36, v5.8.4, v5.8.8, v5.8.9].
    - laravel/helpers v1.0.1 requires illuminate/support ~5.8.0|~5.9.0 -> satisfiable by illuminate/support[v5.8.0, v5.8.11, v5.8.12, v5.8.14, v5.8.15, v5.8.17, v5.8.18, v5.8.19, v5.8.2, v5.8.20, v5.8.22, v5.8.24, v5.8.27, v5.8.28, v5.8.29, v5.8.3, v5.8.30, v5.8.31, v5.8.32, v5.8.33, v5.8.34, v5.8.35, v5.8.36, v5.8.4, v5.8.8, v5.8.9].
    - laravel/helpers v1.1.0 requires illuminate/support ~5.8.0|~5.9.0|^6.0 -> satisfiable by illuminate/support[v5.8.0, v5.8.11, v5.8.12, v5.8.14, v5.8.15, v5.8.17, v5.8.18, v5.8.19, v5.8.2, v5.8.20, v5.8.22, v5.8.24, v5.8.27, v5.8.28, v5.8.29, v5.8.3, v5.8.30, v5.8.31, v5.8.32, v5.8.33, v5.8.34, v5.8.35, v5.8.36, v5.8.4, v5.8.8, v5.8.9, v6.0.0, v6.0.1, v6.0.2, v6.0.3, v6.0.4, v6.1.0, v6.10.0, v6.11.0, v6.12.0, v6.13.0, v6.13.1, v6.2.0, v6.3.0, v6.4.1, v6.5.0, v6.5.1, v6.5.2, v6.6.0, v6.6.1, v6.6.2, v6.7.0, v6.8.0].
    - laravel/helpers v1.1.1 requires illuminate/support ~5.8.0|^6.0 -> satisfiable by illuminate/support[v5.8.0, v5.8.11, v5.8.12, v5.8.14, v5.8.15, v5.8.17, v5.8.18, v5.8.19, v5.8.2, v5.8.20, v5.8.22, v5.8.24, v5.8.27, v5.8.28, v5.8.29, v5.8.3, v5.8.30, v5.8.31, v5.8.32, v5.8.33, v5.8.34, v5.8.35, v5.8.36, v5.8.4, v5.8.8, v5.8.9, v6.0.0, v6.0.1, v6.0.2, v6.0.3, v6.0.4, v6.1.0, v6.10.0, v6.11.0, v6.12.0, v6.13.0, v6.13.1, v6.2.0, v6.3.0, v6.4.1, v6.5.0, v6.5.1, v6.5.2, v6.6.0, v6.6.1, v6.6.2, v6.7.0, v6.8.0].
    - don't install illuminate/support v5.8.0|don't install laravel/framework v5.7.28
    - don't install illuminate/support v5.8.11|don't install laravel/framework v5.7.28
    - don't install illuminate/support v5.8.12|don't install laravel/framework v5.7.28
    - don't install illuminate/support v5.8.14|don't install laravel/framework v5.7.28
    - don't install illuminate/support v5.8.15|don't install laravel/framework v5.7.28
    - don't install illuminate/support v5.8.17|don't install laravel/framework v5.7.28
    - don't install illuminate/support v5.8.18|don't install laravel/framework v5.7.28
    - don't install illuminate/support v5.8.19|don't install laravel/framework v5.7.28
    - don't install illuminate/support v5.8.2|don't install laravel/framework v5.7.28
    - don't install illuminate/support v5.8.20|don't install laravel/framework v5.7.28
    - don't install illuminate/support v5.8.22|don't install laravel/framework v5.7.28
    - don't install illuminate/support v5.8.24|don't install laravel/framework v5.7.28
    - don't install illuminate/support v5.8.27|don't install laravel/framework v5.7.28
    - don't install illuminate/support v5.8.28|don't install laravel/framework v5.7.28
    - don't install illuminate/support v5.8.29|don't install laravel/framework v5.7.28
    - don't install illuminate/support v5.8.3|don't install laravel/framework v5.7.28
    - don't install illuminate/support v5.8.30|don't install laravel/framework v5.7.28
    - don't install illuminate/support v5.8.31|don't install laravel/framework v5.7.28
    - don't install illuminate/support v5.8.32|don't install laravel/framework v5.7.28
    - don't install illuminate/support v5.8.33|don't install laravel/framework v5.7.28
    - don't install illuminate/support v5.8.34|don't install laravel/framework v5.7.28
    - don't install illuminate/support v5.8.35|don't install laravel/framework v5.7.28
    - don't install illuminate/support v5.8.36|don't install laravel/framework v5.7.28
    - don't install illuminate/support v5.8.4|don't install laravel/framework v5.7.28
    - don't install illuminate/support v5.8.8|don't install laravel/framework v5.7.28
    - don't install illuminate/support v5.8.9|don't install laravel/framework v5.7.28
    - don't install illuminate/support v6.0.0|don't install laravel/framework v5.7.28
    - don't install illuminate/support v6.0.1|don't install laravel/framework v5.7.28
    - don't install illuminate/support v6.0.2|don't install laravel/framework v5.7.28
    - don't install illuminate/support v6.0.3|don't install laravel/framework v5.7.28
    - don't install illuminate/support v6.0.4|don't install laravel/framework v5.7.28
    - don't install illuminate/support v6.1.0|don't install laravel/framework v5.7.28
    - don't install illuminate/support v6.10.0|don't install laravel/framework v5.7.28
    - don't install illuminate/support v6.11.0|don't install laravel/framework v5.7.28
    - don't install illuminate/support v6.12.0|don't install laravel/framework v5.7.28
    - don't install illuminate/support v6.13.0|don't install laravel/framework v5.7.28
    - don't install illuminate/support v6.13.1|don't install laravel/framework v5.7.28
    - don't install illuminate/support v6.2.0|don't install laravel/framework v5.7.28
    - don't install illuminate/support v6.3.0|don't install laravel/framework v5.7.28
    - don't install illuminate/support v6.4.1|don't install laravel/framework v5.7.28
    - don't install illuminate/support v6.5.0|don't install laravel/framework v5.7.28
    - don't install illuminate/support v6.5.1|don't install laravel/framework v5.7.28
    - don't install illuminate/support v6.5.2|don't install laravel/framework v5.7.28
    - don't install illuminate/support v6.6.0|don't install laravel/framework v5.7.28
    - don't install illuminate/support v6.6.1|don't install laravel/framework v5.7.28
    - don't install illuminate/support v6.6.2|don't install laravel/framework v5.7.28
    - don't install illuminate/support v6.7.0|don't install laravel/framework v5.7.28
    - don't install illuminate/support v6.8.0|don't install laravel/framework v5.7.28
    - Installation request for laravel/framework (locked at v5.7.28, required as 5.7.*) -> satisfiable by laravel/framework[v5.7.28].
    - Installation request for devio/pipedrive ^2.4 -> satisfiable by devio/pipedrive[2.4.0, 2.4.1, 2.4.2].


Installation failed, reverting ./composer.json to its original content.

Is it the case that version >=2.1.0 doesn't support Laravel version <5.8?

Thanks!

resource Webhooks ist missing

Hello,
there is just one resource missing that is documented on the Pipedrive API Doku.

Please tell me how I can add this resource and poste the code back to here.

Thanks in advance,
Benjamin

guzzle client error

GuzzleHttp\Exception\RequestException

cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)

I get that error when i try to test out your code. Please update your GuzzleClient to allow user to setup their cacert.pem file location to fix this issue.

Error Laravel - Call to undefined method

<?php

namespace App\Http\Controllers;

use App\Services\ClientServices;
use Devio\Pipedrive\Pipedrive;
use Illuminate\Http\Request;

class AllSyncController extends Controller
{

    protected $clients;

    public function __construct(ClientServices $clients)
    {
        $this->clients = $clients;

    }

    public function persons(){

        $organizations = Pipedrive::persons()->all()->getData();
    }
}

Error

Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR)
Call to undefined method Devio\Pipedrive\Pipedrive::persons()

How to fetch all data by calling all() method once without the pagination limitation as 100 per call?

How to fetch all data by calling all() method once without the pagination limitation as 100 per call? Anyone call help? could be just a param to pass in, just not sure about if this repository supports that or not. Cheers.

updated: figured out a function for this, list here in case anyone else who needs it:

// possible $type values: 'Organizations', 'Users', 'Deals', etc.
protected function getAllWithoutPaginationLimit($type, $limit=100, $start=0) {
        $api = '\Pipedrive::' . $type;
        
        $response = $api()->all(['limit'=>$limit, 'start'=>$start]);
        
        if(!$response->isSuccess()) { 
            $msg = 'The pipedrive api call for ' . $type . ' was not successful';
            abort(404, $msg);  // this is a laravel helper, use others if you are not using laravel.
        }

       if(!empty($response->getData())) {
            $resources = $response->getData();
        } else {
            $msg = 'There is no records of ' . $type . ' on Pipedrive website yet';
            abort('404', $msg); 
        }

        if(!empty($response->getContent()->additional_data->pagination->more_items_in_collection) && $response->getContent()->additional_data->pagination->more_items_in_collection === true) {
            $nextStart=$response->getContent()->additional_data->pagination->next_start;
            $nextPaged = $this->getAllWithoutPaginationLimit($type, $limit=$limit, $nextStart);
            $resources = array_merge($resources, $nextPaged);
        }

        return $resources;
    }

Oauth Support

The new Pipedrive App Marketplace has switched over to oAuth authentication. Are there any plans for this package to support it?

findByName() Method Should Not be Globally Deprecated

Devio\Pipedrive\Resources\Traits::findByName() has been marked as deprecated. It's a wrapper for Pipedrive's /find endpoint, which has been deprecated in favor of /search—but not for all resources. In particular, /users/find has not been deprecated, and the /users/search endpoint has not been implemented. See the Pipedrive API Changelog for the six endpoints that are affected: https://pipedrive.readme.io/docs/changelog#removal-of-the-/find-/searchresults-and-/searchresults/field-endpoints-replaced-by-6-new-endpoints

The trait is used mostly by classes where findByName() has been deprecated, so perhaps a simple solution would be to remove the trait from Devio\Pipedrive\Resources\Users and implement findByName() (maybe rename it "find()" to prevent confusion) as a method directly in the class.

List updates about a deal

Hello !
First, thank you for this beautiful work :)
However, I do not really understand regarding methods marked as implemented. I want to list all updates about a deal (flow function in pipedrive api) and it doesn't seems to exist.
Am I right ? or do I don't understand ?

thank you

Proposal: Add event dispatcher

You can add event dispatcher:

$pipedrive->on('update', 'product', function($previous, $current, $meta) {
    //code here...
});
$pipedrive->clients->on('update', function($previous, $current, $meta) {
    //code here...
});
$pipedrive->deals->on('create', function($current, $meta){
    //code here...
});
$pipedrive->dispatch($eventJson);

Product post endpoint expects prices as an array of objects

Setting prices to anything other than a string results in the following error:

'Warning: preg_replace(): Parameter mismatch, pattern is a string while replacement is an array in /vagrant/vendor/devio/pipedrive/src/Builder.php on line 72

While setting it to a string returns an error from the API:

exception 'Devio\Pipedrive\Exceptions\PipedriveException' with message 'Prices must be given as array of objects.' in /vagrant/vendor/devio/pipedrive/src/Http/Request.php:85

builder.php line 76 Object of class stdClass could not be converted to string

Hello,
i find all deal in specific stage and i would like create activity but i receive an error :

Recoverable fatal error: Object of class stdClass could not be converted to string in .../vendor/devio/pipedrive/src/Builder.php on line 76

My code is


foreach ($EtapeRelanceSMS as $etape){
    $rotten_days=$pipedrive->stages->find($etape)->getcontent()->data->rotten_days;
    foreach ($pipedrive->deals->all(["stage_id" => $etape ,"status" => "open"])->getContent()->data as $thedeals){
        
        $dateactivity = new datetime($thedeals->update_time);
        $currentdate = new datetime();
       
        if( $currentdate->diff($dateactivity)->format("%a") > $rotten_days ){
            // create new activity 
            
            $pipedrive->activities->add(['type' => 'monsms', 'deal_id' => $thedeals->id, "person_id" => $thedeals->person_id, "note" => $contentSMSpart1 . $thedeals->value ." €". $contentSMSpart2 ,"user_id" => $thedeals->user_id]);
          
            if ($EtapeRelanceSMS['relance'] == $etape){
                //$pipedrive->deals->update($thedeals->id,["stage_id" => $EtapeRelanceSMS['attente']]);

            }
            if ($EtapeRelanceSMS['attente'] == $etape){
                //$pipedrive->deals->update($thedeals->id,["status" => "lost"]);
            }
            if ($EtapeRelanceSMS['à suivre'] == $etape){
                //$pipedrive->deals->update($thedeals->id,["status" => "lost"]);
                
            }
            echo $dateactivity->format("d/m/y"). " ".$currentdate->format("d/m/y") ." ";
            echo ($currentdate->diff($dateactivity)->format("%a") . " ".$rotten_days ." ". $thedeals->id ." ".  $thedeals->title ."<br>" );
        }
        
     };

}

The error is from
$pipedrive->activities->add(['type' => 'monsms', 'deal_id' => $thedeals->id, "person_id" => $thedeals->person_id, "note" => $contentSMSpart1 . $thedeals->value ." €". $contentSMSpart2 ,"user_id" => $thedeals->user_id]);

Best regards

Creat deal

I was able to observe the following methods.
How do I create a deal on pipedrive using this function using this simple method?

$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';
$pipedrive = new Pipedrive($token);

// Easily access a Pipedrive resource and its values
$organization = $pipedrive->organizations->find(1);
var_dump($organization->getData());

Issue with creation of Filters

There's a issue when creating a new "Filter". I think the problem is with the use of a "json" field in request.

My request is like that:

$newFilter = array(
    'glue' => 'and',
    'conditions' => array(
        array(
            'glue' => 'and',
            'conditions' => array(
                array(
                    'object' => 'person',
                    'field_id' => '9039', // phone
                    'operator' => '=',
                    'value' => 'xxxxxxxxxxx',
                    'extra_value' => null,
                )
            ),
        ),
        array(
            'glue' => 'or',
            'conditions' => array(),
        ),
    ),
);


$pipedrive = new \Devio\Pipedrive\Pipedrive('xxxxxx');
$addFilter = $pipedrive->filters->add(array(
    'name' => 'Filter Name 0123',
    'conditions' => $newFilter,
    'type' => 'people',
));

I receive the follow exception

Fatal error: Uncaught exception 'Devio\Pipedrive\Exceptions\PipedriveException' with message 'This field is missing.' in /var/wxu/test/pipedrive-test/vendor/devio/pipedrive/src/Http/Request.php:85 Stack trace: #0...

I "solved" the issue with a small change in PipedriveClient.php

public function post($url, $parameters = [])
    {
        $request = new GuzzleRequest('POST', $url);
        $form = 'form_params';

        // If any file key is found, we will assume we have to convert the data
        // into the multipart array structure. Otherwise, we will perform the
        // request as usual using the form_params with the given parameters.
        if (isset($parameters['file'])) {
            $form = 'multipart';
            $parameters = $this->multipart($parameters);
        }

        // This was generated with error: return $this->execute($request, [$form => $parameters]);
        // Replace with that:
        return $this->execute($request, ['json' => $parameters]);
    }

But for obvious reasons this will break the file upload.

Maybe someone can work in a fix?
... or i missing something?

Can't get fields

when I trie to get pipedrive person fields I get the following error:
Fatal error: Uncaught Error: Class 'Devio\Pipedrive\Resources\Personfields' not found in /home/jongensv/public_html/wp-content/plugins/pipedrive_klantenportaal/vendor/devio/pipedrive/src/Pipedrive.php:55 Stack trace: #0 /home/jongensv/public_html/wp-content/plugins/pipedrive_klantenportaal/vendor/devio/pipedrive/src/Pipedrive.php(131): Devio\Pipedrive\Pipedrive->make('personfields') #1 /home/jongensv/public_html/wp-content/plugins/pipedrive_klantenportaal/test.php(7): Devio\Pipedrive\Pipedrive->__get('personfields') #2 {main} thrown in /home/jongensv/public_html/wp-content/plugins/pipedrive_klantenportaal/vendor/devio/pipedrive/src/Pipedrive.php on line 55
The weird thing is that it is working on my local wamp machine but not on my production cpanel server.
And loading deals also works great on both my local wamp machine and production cpanel server.

Code:
`<?php
require_once( dirname(FILE) . '/vendor/autoload.php' );
use Devio\Pipedrive\Pipedrive;
$apikey = "";
$pipedrive = new Pipedrive($apikey);

$person_fields = $pipedrive->personfields->all();
$person_fields = $person_fields->getData();
var_dump($person_fields);
`

Running script outside of Laravel gives an error

I'm trying to create an activity and I keep receiving this error:

PHP Fatal error: Class 'Illuminate\Support\Str' not found in /path/to/src/Pipedrive.php on line 66

I've simply included the Pipedrive.php file from within my PHP file (via require). I am not using Laravel or composer.

Is there any way to filter the records

i mean that would be nice if we can get desired records from the pipeline

for example in case if i want to fetch deals in asc or desc order

please let me know if there is a way

Thanks !

Complete?

Hi, thanks for all the work you've done so far but I couldn't find a way to request /stages/:id/deals.

To overcome this need I implemented it myself (code below). Is this the only/right approach?

<?php

namespace Devio\Pipedrive\Resources;

use Devio\Pipedrive\Resources\Basics\Resource;
use Devio\Pipedrive\Resources\Traits\ListsDeals;

class Stages extends Resource
{
    use ListsDeals;

    public function deals($id, $options = [])
    {
        array_set($options, 'id', $id);

        return $this->request->get(':id/deals', $options);
    }
}

Pagination with the all() function

A quick question: Does the all() function return all the items even if there are thousands of them? If not, what's the best way to get the total number of the items for pagination purpose?
thanks.

File upload

I can't get the file upload working. I'm not sure it's an issue with the library, maybe I'm doing something wrong. If so, I'm sorry ;)

public function uploadFile($dealId, \SplFileInfo $file)
{
     $upload = $this->pipedrive->files->add([
        'file' => $file,
        'deal_id' => $dealId
    ]);
}

This throws a PipedriveException: 'No files were provided with the request.'.

What's going wrong?

In readme wrong example

In aliases config example 'Devio\Pipedrive\PipedriveFacade::class' must be as Devio\Pipedrive\PipedriveFacade::class without uotes

Support for find endpoint on Persons

Persons has a find endpoint: api.pipedrive.com/v1/persons/find that allows a text search of name or email. The find endpoint in the generic Resource only allows find by id. Is there a way to call Persons::find?

Lists e-mail messages associated with a deal.

Hi there,
Does this php binding provide email messages associated with a deal
i have tried two ways

Pipedrive::deals()->emailMessages($dealId);

Pipedrive::deals()->find(3)->emailMessages();

but no success ...

Undefined property: stdClass::$success

(1/1) ErrorException Undefined property: stdClass::$success in Response.php line 53

at HandleExceptions->handleError(8, 'Undefined property: stdClass::$success', '\vendor\devio\pipedrive\src\Http\Response.php', 53, array())in Response.php line 53

at Response->isSuccess()in Request.php line 86
at Request->handleResponse(object(Response))in Request.php line 67
at Request->executeRequest('put', 'deals/17790', array())in Request.php line 53
at Request->performRequest('put', ':id', array())in Request.php line 134
at Request->__call('put', array(':id', array()))in Resource.php line 89
at Resource->update(17790, array())
...

it would be nice to add a field mapping

The easiest way to work with fields, which have a normal name.
Something like:

// Deals
$organizations = $pipedrive
    ->deals(['621eeebb0431f9fe252ca369b3dd2f8c'=>'custom'])
    ->update(1,['custom'=>'value']);

How can i create a new Deal ??

Hello sir,
I am trying to create a new deal . but i am unable to find an appropriate method to add a new deal.
That would be nice if you can share a piece of code.
Thanks !

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.