Pipedrive API Documentation

Pipedrive's API Docs

Welcome to Pipedrive's Developer Documentation. Here you'll find comprehensive guides and documentation to help you start working with Pipedrive's API, as well as the Changelog to see any relevant changes regarding the public API.

Creating a Deal

Follow the next steps to create a Deal using PHP with our API.

Only want to see the finished code? No problem! You can find it below. You can also try adding a Deal through our API Reference, using the POST /deals endpoint.

Reminder

A Deal is a visual representation of all actions taken towards the closing of a sale from start to finish. Deals will also automatically pull all contact information from the Person/Organization they're associated with.

Continue reading about Deals

Step 1: Get your API token

Follow our tutorials on how to find the API token and how to get the company domain. Then create a file createDeal.php and first give value to the $api_token and $company_domain variables:

<?php
// Content of createDeal.php
    
// Pipedrive API token
$api_token = '659c9fddb16335e48cc67114694b52074e812e03';
    
// Pipedrive company domain
$company_domain = 'theunicorntail';

Step 2: Prepare the data

When creating a deal, there are at least two required parameters you have to give a value to. You can give your new Deal different parameters, but it is compulsory to give value the following parameters:

  • Deal title
  • Organization ID or Person ID

See here how to add an Organization. You can give values to Organization ID and Person ID both, but in this example, we are going to add an Organization this Deal will be associated with.

Find the Organization ID at the end of the URL:

To send one or multiple parameters with your chosen values, you need to create an array of chosen parameters.

// Deal title and Organization ID
$deal = array(
  'title' => 'Deal title goes here',
  'org_id' => 'Organization ID goes here'
);

Step 3: Define target URL

To make a request, you'll need the correct URL meant for creating Deals. All available endpoints and their URLs are described in our API Reference.

You must provide your company domain name and the API token as part of the query string for all requests at the end of the URL.

An example would look like this https://companydomain.pipedrive.com/api/v1/deals?api_token=659c9fddb16335e48cc67114694b52074e812e03
You need to create a $url variable which holds correct URL for Deal creation and add your $api_token variable to it:

$url = 'https://' . $company_domain . '.pipedrive.com/api/v1/deals?api_token=' . $api_token;

Step 4: Make a POST request

This part of the code is more complex and you don’t need to understand it right away, all you need to know is that it contains everything to make a POST request with your data against our API.
Simply copy and paste this:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $deal);
 
echo 'Sending request...' . PHP_EOL;
 
$output = curl_exec($ch);
curl_close($ch);

Step 5: Check the result

$output variable holds the full response you get back from the server. As all responses from us are in JSON format, the first thing you'll want to do is to convert it into a proper PHP array.

// Create an array from the data that is sent back from the API
// As the original content from server is in JSON format, you need to convert it to PHP array
$result = json_decode($output, true);

After that, you should check if the ID came back as part of returned data. If it did, then this means that a new Deal was added successfully.

// Check if an ID came back, if did print it out
if (!empty($result['data']['id'])) {
  echo 'Deal was added successfully!' . PHP_EOL;
}

Full working example

Copy the full working example into createDeal.php

<?php
// Content of createDeal.php
    
// Pipedrive API token
$api_token = '659c9fddb16335e48cc67114694b52074e812e03';
    
// Pipedrive company domain
$company_domain = 'theunicorntail';
 
// Deal title and Organization ID
$deal = array(
  'title' => 'Deal title goes here',
  'org_id' => 'Organization ID goes here'
);
 
$url = 'https://' . $company_domain . '.pipedrive.com/api/v1/deals?api_token=' . $api_token;
 
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $deal);
 
echo 'Sending request...' . PHP_EOL;
 
$output = curl_exec($ch);
curl_close($ch);
 
// Create an array from the data that is sent back from the API
// As the original content from server is in JSON format, you need to convert it to PHP array
$result = json_decode($output, true);
 
// Check if an ID came back, if did print it out
if (!empty($result['data']['id'])) {
   echo 'Deal was added successfully!' . PHP_EOL;
}

Execute the code

Now run the command php createDeal.php in terminal and you should see the following output:

$ php createDeal.php
Sending request...
Deal was added successfully!

Updated 4 months ago

Creating a Deal


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.