Personal Email Address
Location
Current Job Title
Work Email Address
Work History
Other B2B Data Fields
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""
I want to get contact information for data scientists working San Francisco
"""
import requests, json
API_KEY = "####" # Enter your api key here
PDL_URL = "https://api.peopledatalabs.com/v5/person/search"
REQUEST_HEADER = {
'Content-Type': "application/json",
'X-api-key': API_KEY
}
# Define our query for the Person Search API
# We're looking for data scientists located in San Francisco
ES_QUERY = {
"query": {
"bool": {
"must": [
{"match_phrase" : {"job_title": "data scientist"}},
{"term" : {"location_metro": "san francisco, california"}},
]
}
}
}
# Build the request and define how many matches we want returned
# We'll ask for 100 matches
REQUEST_PARAMS = {
"query": json.dumps(ES_QUERY),
"size": 100,
"pretty": True
}
# Send the API request
response = requests.get(PDL_URL, params=REQUEST_PARAMS, headers=REQUEST_HEADER).json()
# Parse the response
if response['status'] == 200:
# Audience is an array of people matches
# Each match contains names, contact info, social profiles and more
# See the full schema for all available fields at: https://docs.peopledatalabs.com/docs/fields
audience = response['data']
# Write matches out to json
with open("my_audience.json", 'w') as file_handle:
json.dump(audience, file_handle, indent=2)
print(f"Generated audience with {len(audience)} members")
else:
error = response['error']
print(f"Request was unsuccessful with status {response['status']}")
print(f"Error: \n Type: {error['type']}\n Message: {error['message']}")