Hello World Tutorial
Our Pipedrive RESTful API Reference is accessed from https://developers.pipedrive.com/docs/api/v1/ where you can find a list of endpoints and their descriptions. Calls to our API are validated against an API token or an access_token
when using OAuth 2.0. Our API supports UTF-8 for character encoding.
Here's a simple command-line application with samples both in PHP and node.js. It makes a request to our Pipedrive RESTful API showcasing the basic functionality for operating with it.
The quick example below will list all the existing deals from your Pipedrive account. Don't worry, if you haven't created any deals yet, you can still test the code.
Step 1: Things you'll need
- your personal API token
- your company domain name
- (optional) a Developer Sandbox account (you don't need to have one, but you can create it if you're interested in building an app with Pipedrive or need an environment just for testing)
Step 2: Hello, World
Create a file hello_world.php
and then copy-paste this code below into it. Don't forget to give values to the api_token
and the company_domain
variables:
If you don't have any data in your Pipedrive account, you can use template spreadsheets either in English or in Portuguese with sample data, to see how to begin with Pipedrive. You can import the data from the spreadsheets by going to Settings > Tools and apps > (Data) > Import Data in the Pipedrive web app.
<?php
// Content of hello_world.php
// Pipedrive API token
$api_token = 'Your API token goes here';
// Pipedrive company domain
$company_domain = 'Your company domain goes here';
//URL for Deal listing with your $company_domain and $api_token variables
$url = 'https://'.$company_domain.'.pipedrive.com/api/v1/deals?api_token=' . $api_token;
//GET request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
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 a PHP array
$result = json_decode($output, true);
// Check if data returned in the result is not empty
if (empty($result['data'])) {
exit('No deals created yet' . PHP_EOL);
}
// Iterate over all found deals
foreach ($result['data'] as $key => $deal) {
$deal_title = $deal['title'];
// Print out a deal title
echo '#' . ($key + 1) . ': ' . $deal_title . PHP_EOL;
}
//All tutorial Node.Js code examples are for reference only and shouldn’t be used in production code as is. In production, a new new pipedrive.ApiClient() instance should be initialised separately for each request.
const pipedrive = require('pipedrive');
const defaultClient = new pipedrive.ApiClient();
// Configure authorization by settings api key
// PIPEDRIVE_API_KEY is an environment variable that holds real api key
defaultClient.authentications.api_key.apiKey = process.env.PIPEDRIVE_API_KEY;
async function getDeals() {
try {
console.log('Sending request...');
const api = new pipedrive.DealsApi(defaultClient);
const response = await api.getDeals();
console.log('Got the deals successfully!', response);
} catch (err) {
const errorToLog = err.context?.body || err;
console.log('Getting deals failed', errorToLog);
}
}
getDeals();
Step 3: Execute the code
Use php hello_world.php
command to execute the code in the command line.
Here's an example output with 21 deals:
$ php hello_world.php
Sending request...
#1 Batman deal (Deal ID:134)
#2 Big apple sale (Deal ID:135)
#3 Robin sale (Deal ID:136)
#4 Silly goose (Deal ID:137)
#5 Mademoiselle sale (Deal ID:138)
#6 Cats and dogs (Deal ID:139)
#7 Panna on vaja (Deal ID:140)
#8 Lucky (Deal ID:141)
#9 Call him now (Deal ID:142)
#10 Sending (Deal ID:143)
#11 Wolt (Deal ID:144)
#12 PD (Deal ID:145)
#13 The Explorer (Deal ID:146)
#14 The Carryall (Deal ID:147)
#15 The Pineapple (Deal ID:148)
#16 The Base (Deal ID:149)
#17 Kisser (Deal ID:150)
#18 Hugger (Deal ID:151)
#19 The Scholar (Deal ID:152)
#20 The Artist (Deal ID:153)
#21 The Ace (Deal ID:154)
If you don't have any deals, you should see this output:
$ php hello_world.php
Sending request...
No deals created yet
Updated 4 months ago