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.

Adding a Product

This tutorial will focus on the Products feature in Pipedrive, which is available for all Advanced and Professional users. Before you're able to properly start following along with this tutorial, you will need to have the products feature enabled in Pipedrive under Settings > Tools and integrations > Products.

If you want to see the finished code, you can find it below.

You can also try out adding a Product by using the POST /products endpoint from our API Reference.

Step 1: Get your API token and company domain

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

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

Step 2: Prepare the data

When adding a product, there’s only one required parameter you have to give a value to - the product name. You can give the new product additional parameters as well. To send one or multiple parameters with your chosen values, you need to create an array of these chosen parameters. Note that for sending the prices of a product, you need to give value to prices in the form of an array of objects, for that see how the body of the request looks like using JSON.

// Name of the product
$data = array(
    'name' => 'Unicorn tear'
);

Step 3: Define target URL

To make a request, you'll need the correct URL meant for adding products. All available endpoints and their URLs are described in our API Reference. You must provide 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/products?api_token=659c9fddb16335e48cc67114694b52074e812e03.

You need to create a $url variable which holds the correct URL for adding a product:

$url = 'https://' . $company_domain . '.pipedrive.com/api/v1/products?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, $data);
 
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);

Then you can check if data returned in the result is not empty:

// Check if the data returned in the result is not empty
if (empty($result['data'])) {
    exit('Adding failed' . PHP_EOL);
}

And now you should check if product ID came back as returned data. If it did, then this means that the product was added successfully.

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

You can also check the changes in Pipedrive from the products section.

Full working example

Copy the full working example into addProduct.php. Don't forget to replace variables with your actual data:

<?php
// Content of addProduct.php
 
// Pipedrive API token
$api_token = '659c9fddb16335e48cc67114694b52074e812e03';
// Pipedrive company domain
$company_domain = 'theunicorntail';
 
// Name of the product
$data = array(
    'name' => 'Unicorn tear'
);
 
// URL for adding a product
$url = 'https://' . $company_domain . '.pipedrive.com/api/v1/products?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, $data);
 
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 the data returned in the result is not empty
if (empty($result['data'])) {
    exit('Adding failed' . PHP_EOL);
}
// Check if an ID came back, if it did, print out success message
if (!empty($result['data']['id'])) {
    echo 'Product was added successfully!' . PHP_EOL;
}

Full example using JSON

You can also use this JSON body example to add a product. For this request, the content_type needs to be application/json. Don't forget to authenticate your request.

{
    "name": "",
    "code": "",
    "unit": "",
    "tax": "",
    "active_flag": "",
    "visible_to": "",
    "owner_id": "",
    "prices":[
    	{
    	"price": "", 
    	"currency": "",
    	"cost": "",
    	"overhead_cost": ""
    	}
    ]
}

Execute the code

Use php addProduct.php command to execute the code in the command line. Here's an example output if the product was added:

Sending request...
Product added successfully!

If adding the product failed, this is the output you'll get:

Sending request...
Adding failed

Updated about a month ago

Adding a Product


Suggested Edits are limited on API Reference Pages

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