Examples - Person Retrieve API

Code examples and walkthroughs using the Person Retrieve API

On this page, you'll find a collection of running code examples that illustrate various aspects of the Person Retrieve API functionality.

Code examples here are shown in Python, JavaScript, Ruby and cURL.

Basic Usage

"I want to look up information for a PDL Person ID that I have."

import json

# See https://github.com/peopledatalabs/peopledatalabs-python
from peopledatalabs import PDLPY

# Create a client, specifying an API key
client = PDLPY(
    api_key="YOUR API KEY",
)

params = {
    "person_id": "qEnOZ5Oh0poWnQ1luFBfVw_0000", # The ID for the record we want
    "pretty": True
}

json_response = client.person.retrieve(**params).json()
print(json_response)
curl -X GET -G \
  'https://api.peopledatalabs.com/v5/person/retrieve/qEnOZ5Oh0poWnQ1luFBfVw_0000'\
  -H 'X-Api-Key: xxxx' \
  --data-urlencode 'pretty=True'
// See https://github.com/peopledatalabs/peopledatalabs-js
import PDLJS from 'peopledatalabs';

const PDLJSClient = new PDLJS({ apiKey: "YOUR API KEY" });

PDLJSClient.person.retrieve('qEnOZ5Oh0poWnQ1luFBfVw_0000').then((data) => {
  console.log(data);
}).catch((error) => {
  console.log(error);
});
# See https://github.com/peopledatalabs/peopledatalabs-ruby
require 'peopledatalabs'

Peopledatalabs.api_key = 'YOUR API KEY'

response = Peopledatalabs::Retrieve.person(person_id: "qEnOZ5Oh0poWnQ1luFBfVw_0000")

puts response
import requests, json

API_KEY = # YOUR API KEY

pdl_base_url = "https://api.peopledatalabs.com/v5/person/retrieve"

person_id = "qEnOZ5Oh0poWnQ1luFBfVw_0000" # The ID for the record we want

params = {
    "api_key": API_KEY,
    "pretty": True
}

url_path = f"{pdl_base_url}/{person_id}"

json_response = requests.get(url_path,  params=params).json()
print(json_response)

Record Updating

"I have a PDL record, and I want to update it."

import json

# See https://github.com/peopledatalabs/peopledatalabs-python
from peopledatalabs import PDLPY

# Create a client, specifying an API key
client = PDLPY(
    api_key="YOUR API KEY",
)

# An example of a stale person record that you would like to update
stale_person_record = {
  "id": "qEnOZ5Oh0poWnQ1luFBfVw_0000",
  "first_name": "sean",
  "last_name": "thorne",
  "job_title": "an old job title",
} 

params = {
    "person_id": stale_person_record['id'], # The ID for the record we want to update
    "pretty": True
}

json_response = client.person.retrieve(**params).json()

# Replace the fields with updated values from the retrieve API response object
new_person_record = {
    key:json_response['data'][key] for key in json_response['data'].keys() if key in stale_person_record
}

print(f"Old Person Record: \n{stale_person_record}")
print(f"New Person Record: \n{new_person_record}")
// See https://github.com/peopledatalabs/peopledatalabs-js
import PDLJS from 'peopledatalabs';

const PDLJSClient = new PDLJS({ apiKey: "YOUR API KEY" });

// An example of a stale person record that you would like to update
const stalePersonRecord =   {
                                "id": "qEnOZ5Oh0poWnQ1luFBfVw_0000",
                                "first_name": "sean",
                                "last_name": "thorne",
                                "job_title": "an old job title",
                            } 

const personID = stalePersonRecord['id']; // The ID for the record we want to update

PDLJSClient.person.retrieve(personID).then((data) => {
    var newPersonRecord = {};
    var record = data.data;
    
    for (let field in record) {
        if (stalePersonRecord[field]) {
            newPersonRecord[field] = record[field];
        }
    }
    
    console.log("Old Person Record: \n" + stalePersonRecord.job_title);
    console.log("New Person Record: \n" + newPersonRecord.job_title);
}).catch((error) => {
    console.log(error);
});
# See https://github.com/peopledatalabs/peopledatalabs-ruby
require 'peopledatalabs'

Peopledatalabs.api_key = 'YOUR API KEY'

# An example of a stale person record that you would like to update
stale_person_record = {
  id: "qEnOZ5Oh0poWnQ1luFBfVw_0000",
  first_name: "sean",
  last_name: "thorne",
  job_title: "an old job title",
}

response = Peopledatalabs::Retrieve.person(person_id: stale_person_record[:id])
data = response['data']

# Replace the fields with updated values from the retrieve API response object
new_person_record = {}
stale_person_record.each do |key, value|
    new_person_record[key] = data[key.to_s]
end

puts "Old Person Record: \n#{stale_person_record}"
puts "New Person Record: \n#{new_person_record}"
import requests, json

API_KEY = # YOUR API KEY

pdl_base_url = "https://api.peopledatalabs.com/v5/person/retrieve"

# An example of a stale person record that you would like to update
stale_person_record = {
  "id": "qEnOZ5Oh0poWnQ1luFBfVw_0000",
  "first_name": "sean",
  "last_name": "thorne",
  "job_title": "an old job title",
} 

person_id = stale_person_record['id'] # The ID for the record we want to update

params = {
    "api_key": API_KEY
}

url_path = f"{pdl_base_url}/{person_id}"

json_response = requests.get(url_path,  params=params).json()

# Replace the fields with updated values from the retrieve API response object
new_person_record = {
    key:json_response['data'][key] for key in json_response['data'].keys() if key in stale_person_record
}

print(f"Old Person Record: \n{stale_person_record}")
print(f"New Person Record: \n{new_person_record}")

Did this page help you?