Obtain API Access: Ensure you have access to the Pipedrive API. You’ll need an API token which you can get from your Pipedrive account settings. Click on Personal Preferences to get or generate token.

Set Up Guzzle: If you haven’t already, install Guzzle HTTP client library in your PHP project. You can use Composer for this.

composer require guzzlehttp/guzzle

Make API Request: Use Guzzle to make a POST request to Pipedrive’s API endpoint for creating deals. Below is a basic example of how you might do this:

Please change YOUR_API_TOKEN .Now if you run the code it will create a deal on pipedrive

<?php 

require 'vendor/autoload.php'; // Include Composer's autoloader

// Set up Guzzle client
use GuzzleHttp\Client;

$client = new Client([
    'base_uri' => 'https://api.pipedrive.com/v1/',
    'headers' => [
        'Authorization' => 'Bearer YOUR_API_TOKEN',
        'Content-Type' => 'application/json',
    ],
]);

// Deal data
$dealData = [
    'title' => 'New Deal',
    'value' => 1000,
    'currency' => 'USD',
    'org_id' => 123, // ID of the organization associated with the deal
];

// Make POST request to create a deal
$response = $client->post('deals', [
    'json' => $dealData,
]);

// Handle response
$statusCode = $response->getStatusCode();
$body = $response->getBody();

echo "Status Code: $statusCode\n";
echo "Response Body: $body\n";

?>

By Navid Anjum

Full-stack web developer and founder of Laravelaura. He makes his tutorials as simple as humanly possible and focuses on getting the students to the point where they can build projects independently. https://github.com/NavidAnjum

Leave a Reply

Your email address will not be published. Required fields are marked *