Get contact
Tags: #pipedrive #crm #contact #sales #snippet
Author: Alok Chilka

Input

Import libraries

1
try:
2
from pipedrive.client import Client
3
except:
4
!pip install pipedrive-python-lib
5
from pipedrive.client import Client
6
import pandas as pd
Copied!

Enter your api KEY

Domain & API Key
Go to Account - Personal Preferences - API Key Tab - Click on Generate New Token
Add the key to line 2 in below cell
1
DOMAIN = "https://your_domain.pipedrive.com"
2
API_KEY = "your_api_key"
Copied!

Connect to Pipedrive

1
client = Client(domain=DOMAIN)
2
client.set_api_token(API_KEY)
Copied!

Model

Get all contacts

1
response = client.persons.get_all_persons() #returns all the records present in CRM
2
dataKey = response.get("data", None) #the key with all records
3
userInfo = {} #empty dictionary for storing data in user object
4
users = [] #empty list to store multiple user objects
Copied!
1
for dataKeyItem in dataKey: #Iterate through each record
2
phonelist = []
3
emaillist = []
4
for phone in dataKeyItem["phone"]:
5
phonelist.append(phone["value"])
6
7
for email in dataKeyItem["email"]:
8
emaillist.append(email["value"])
9
10
userInfo = {
11
"FirstName": dataKeyItem["first_name"],
12
"LastName": dataKeyItem["last_name"],
13
"Phone": phonelist,
14
"Email": emaillist,
15
"Company": dataKeyItem["org_name"],
16
"Job" : dataKeyItem["your_field_api_key"] #once you create a field you will find the resepect field api key in Accounts - Data Fields section
17
}
18
users.append(userInfo)
Copied!

Output

Display result

1
#use below line to adjust the display of columns and rows
2
pd.set_option("display.max_rows", None, "display.max_columns", 4)
3
4
#the below dataframe has sample data from Pipedrive CRM.
5
personsDF = pd.DataFrame(users)
6
print(personsDF)
Copied!
Last modified 2mo ago
Copy link
Edit on GitHub