Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vincent15000's avatar

Interface Pipedrive with Laravel

Hello,

I need to retrieve some sales data from Pipedrive and synchronize them with local data in Laravel. The Laravel application will never update any data on Pipedrive, just retrieve some datas.

The aim is to do store locally the datas needed to do some calculations and then also store the results locally in the database.

But I have a little problem to solve : in Pipedrive, each line has an id and in the local database, each line has a different id. And this is valid for users, for sales, ...

I had the idea to add a custom field source_id in the different tables. This field would be the pipedrive_id for the users, for the sales, ... to identify that exactly the same line in Pipedrive and locally.

Is it a good idea ?

Do you have another idea ?

And some anticipation : what about the datas integrity if the admin deletes a user on Pipedrive and creates the same user which will then have a different id ?

Thanks for your help to choose the better way.

V

0 likes
5 replies
LaryAI's avatar
Level 58

To interface Pipedrive with Laravel and synchronize sales data, your approach of using a source_id field to store the pipedrive_id is a good idea. This allows you to maintain a reference to the original Pipedrive data and helps in synchronizing and identifying records between the two systems. Here’s a step-by-step solution to implement this:

  1. Add source_id Field:

    • Add a source_id column to your relevant tables (e.g., users, sales) in your Laravel application. This will store the Pipedrive ID for each record.
    Schema::table('users', function (Blueprint $table) {
        $table->string('source_id')->nullable()->unique();
    });
    
    Schema::table('sales', function (Blueprint $table) {
        $table->string('source_id')->nullable()->unique();
    });
    
  2. Retrieve Data from Pipedrive:

    • Use Pipedrive's API to fetch the data. You can use a package like guzzlehttp/guzzle to make HTTP requests.
    use GuzzleHttp\Client;
    
    $client = new Client();
    $response = $client->get('https://api.pipedrive.com/v1/deals', [
        'query' => ['api_token' => 'your_api_token']
    ]);
    
    $deals = json_decode($response->getBody()->getContents(), true);
    
  3. Synchronize Data:

    • Loop through the Pipedrive data and update or insert records in your local database using the source_id.
    foreach ($deals['data'] as $deal) {
        \App\Models\Sale::updateOrCreate(
            ['source_id' => $deal['id']],
            [
                'name' => $deal['title'],
                'value' => $deal['value'],
                // Add other fields as necessary
            ]
        );
    }
    
  4. Handle Data Integrity:

    • To handle cases where a user or sale is deleted and recreated in Pipedrive, you can implement a soft delete mechanism in your Laravel models. This way, if a record is deleted in Pipedrive, you can mark it as inactive in your local database instead of permanently deleting it.
    use Illuminate\Database\Eloquent\SoftDeletes;
    
    class Sale extends Model
    {
        use SoftDeletes;
    }
    
  5. Regular Synchronization:

    • Set up a scheduled task using Laravel's task scheduling to regularly synchronize data between Pipedrive and your Laravel application.
    $schedule->command('pipedrive:sync')->hourly();
    
  6. Considerations for Data Integrity:

    • If a user or sale is deleted and recreated in Pipedrive, it will have a new pipedrive_id. You might need to implement additional logic to handle such cases, possibly by checking other unique fields (like email for users) to determine if it's the same entity.

By following these steps, you can effectively synchronize data from Pipedrive to your Laravel application while maintaining data integrity and handling potential issues with ID changes.

1 like
webrobert's avatar
webrobert
Best Answer
Level 51

Hi Vincent! Been a while. If I understand correctly you need to match the local record with the remote one. So yes, you need a common id to reference. A column for the remote Id locally or vise versa if it’s an option. Incidentally, I often start thinking I don’t want a sync but I imagine your remote has a web hook or something so you can follow status updates.

1 like
vincent15000's avatar

@webrobert Hello Robert, thank you for you answer.

Oh yes it's a good idea to use a webhook to store automatically every update without having to run a synchronization.

1 like

Please or to participate in this conversation.