> ## Documentation Index
> Fetch the complete documentation index at: https://docs.peopledatalabs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Examples - Person Retrieve API

> *Code examples and walkthroughs using the Person Retrieve API*

We've provided code samples in Python, cURL, Ruby, Go and JavaScript. If you aren't comfortable working in any of these languages, feel free to use this [handy tool](https://curlconverter.com/) to convert code from cURL to the language of your choice.

<Info>
  **See a Bug? Want To See a Specific Example?**

  Feel free to use the `Suggest Edits` button in the top right-hand corner of this page to point out any bugs or to request any specific code examples for this API that you'd like to see here.
</Info>

## Basic Usage

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

<CodeGroup>
  ```python Python3 SDK theme={null}
  import json

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

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

  # Create a parameters JSON object
  PARAMS = {
      "person_id": "qEnOZ5Oh0poWnQ1luFBfVw_0000", # The ID for the record we want
      "pretty": True
  }

  # Pass the parameters object to the Person Retrieve API
  json_response = CLIENT.person.retrieve(**PARAMS).json()

  # Print the API response in JSON format
  print(json_response)
  ```

  ```bash cURL theme={null}
  curl -X GET -G \
    'https://api.peopledatalabs.com/v5/person/retrieve/qEnOZ5Oh0poWnQ1luFBfVw_0000'\
    -H 'X-Api-Key: xxxx' \
    --data-urlencode 'pretty=True'
  ```

  ```javascript JavaScript theme={null}
  // See https://github.com/peopledatalabs/peopledatalabs-js
  import PDLJS from 'peopledatalabs';

  // Create a client, specifying your API key
  const PDLJSClient = new PDLJS({ apiKey: "YOUR API KEY" });

  // Pass a person ID to the Person Retrieve API
  PDLJSClient.person.retrieve({ id: 'qEnOZ5Oh0poWnQ1luFBfVw_0000' }).then((data) => {
    // Print the API response in JSON format
    console.log(data);
  }).catch((error) => {
    console.log(error);
  });
  ```

  ```ruby Ruby theme={null}
  require 'json'

  # See https://github.com/peopledatalabs/peopledatalabs-ruby
  require 'peopledatalabs'

  # Set your API key
  Peopledatalabs.api_key = 'YOUR API KEY'

  # Pass a person ID to the Person Retrieve API
  json_response = Peopledatalabs::Retrieve.person(person_id: "qEnOZ5Oh0poWnQ1luFBfVw_0000")

  # Print the API response in JSON format
  puts JSON.dump(json_response)
  ```

  ```go Go expandable theme={null}
  package main

  import (
      "fmt"
      "encoding/json"
      "context"
  )

  // See https://github.com/peopledatalabs/peopledatalabs-go
  import (
      pdl "github.com/peopledatalabs/peopledatalabs-go"
      pdlmodel "github.com/peopledatalabs/peopledatalabs-go/model"
  )

  func main() {
      // Set your API key
      apiKey := "YOUR API KEY"
      // Set API key as environmental variable
      // apiKey := os.Getenv("API_KEY")

      // Create a client, specifying your API key
      client := pdl.New(apiKey)
      
      // Create a parameters JSON object
      params := pdlmodel.RetrievePersonParams {
          BaseParams: pdlmodel.BaseParams {
              Pretty: true,
          },
          PersonID: "qEnOZ5Oh0poWnQ1luFBfVw_0000",
      }
      
      // Pass the parameters object to the Person Retrieve API
      response, err := client.Person.Retrieve(context.Background(), params)
      // Check for successful response
      if err == nil {
          // Convert the API response to JSON
          jsonResponse, jsonErr := json.Marshal(response)
          // Print the API response
          if (jsonErr == nil) {
              fmt.Println(string(jsonResponse))
          }
      }
  }
  ```

  ```python Python3 theme={null}
  import requests, json

  # Set your API key
  API_KEY = "YOUR API KEY"

  # Set the Person Retrieve API URL
  PDL_BASE_URL = "https://api.peopledatalabs.com/v5/person/retrieve"

  # Set the person ID
  PERSON_ID = "qEnOZ5Oh0poWnQ1luFBfVw_0000" # The ID for the record we want

  # Create a parameters JSON object
  PARAMS = {
      "api_key": API_KEY,
      "pretty": True
  }

  # Append the person ID to the API URL
  URL_PATH = f"{PDL_BASE_URL}/{PERSON_ID}"

  # Pass the URL path and the parameters object to the Person Retrieve API
  json_response = requests.get(URL_PATH, params=PARAMS).json()

  # Print the API response in JSON format
  print(json_response)
  ```
</CodeGroup>

## Record Updating

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

<CodeGroup>
  ```python Python3 SDK theme={null}
  import json

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

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

  # 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",
  } 

  # Create a parameters JSON object
  PARAMS = {
      "person_id": STALE_PERSON_RECORD['id'], # The ID for the record we want to update
      "pretty": True
  }

  # Pass the parameters object to the Person Retrieve API
  json_response = CLIENT.person.retrieve(**PARAMS).json()

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

  # Print records
  print(f"Old Person Record: \n{STALE_PERSON_RECORD}")
  print(f"New Person Record: \n{new_person_record}")
  ```

  ```javascript Javascript theme={null}
  // See https://github.com/peopledatalabs/peopledatalabs-js
  import PDLJS from 'peopledatalabs';

  // Create a client, specifying your API key
  const PDLJSClient = new PDLJS({ apiKey: "YOUR API KEY" });

  // 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",
                              } 

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

  // Pass the person ID to the Person Retrieve API
  PDLJSClient.person.retrieve(personID).then((data) => {
      var newPersonRecord = {};
      var record = data.data;
      
      // Replace fields in the stale record with updated values from the API response
      for (let field in record) {
          if (stalePersonRecord[field]) {
              newPersonRecord[field] = record[field];
          }
      }
      
      // Print records
      console.log("Old Person Record: \n" + stalePersonRecord.job_title);
      console.log("New Person Record: \n" + newPersonRecord.job_title);
  }).catch((error) => {
      console.log(error);
  });
  ```

  ```ruby Ruby theme={null}
  # See https://github.com/peopledatalabs/peopledatalabs-ruby
  require 'peopledatalabs'

  # Set your API key
  Peopledatalabs.api_key = 'YOUR API KEY'

  # 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",
  }

  # Pass the person ID to the Person Retrieve API
  response = Peopledatalabs::Retrieve.person(person_id: STALE_PERSON_RECORD[:id])
  data = response['data']

  # Replace fields in the stale record with updated values from the API response
  new_person_record = {}
  STALE_PERSON_RECORD.each do |key, value|
      new_person_record[key] = data[key.to_s]
  end

  # Print records
  puts "Old Person Record: \n#{STALE_PERSON_RECORD}"
  puts "New Person Record: \n#{new_person_record}"
  ```

  ```go Go expandable theme={null}
  package main

  import (
      "fmt"
      "encoding/json"
      "context"
  )

  // See https://github.com/peopledatalabs/peopledatalabs-go
  import (
      pdl "github.com/peopledatalabs/peopledatalabs-go"
      pdlmodel "github.com/peopledatalabs/peopledatalabs-go/model"
  )

  func main() {
      // Set your API key
      apiKey := "YOUR API KEY"
      // Set API key as environmental variable
      // apiKey := os.Getenv("API_KEY")

      // Create a client, specifying your API key
      client := pdl.New(apiKey)

      // A stale person record that you would like to update
      stalePersonRecord := map[string]string {
          "id": "qEnOZ5Oh0poWnQ1luFBfVw_0000",
          "first_name": "sean",
          "last_name": "thorne",
          "job_title": "an old job title",
      }
     
      // Create a parameters JSON object
      params := pdlmodel.RetrievePersonParams {
          BaseParams: pdlmodel.BaseParams {
              Pretty: true,
          },
          // The ID for the record we want to update
          PersonID: stalePersonRecord["id"],
      }
      
      // Pass the parameters object to the Person Retrieve API
      response, err := client.Person.Retrieve(context.Background(), params)
      // Check for successful response
      if err == nil {
          newPersonRecord := make(map[string]string)
          var data map[string]string
          
          // Convert the API response to JSON
          jsonResponse, jsonErr := json.Marshal(response.Data)
          if jsonErr == nil {
              json.Unmarshal(jsonResponse, &data) 
              // Replace fields in the stale record with updated values from the API response
              for key := range stalePersonRecord {
                  if dataKey, ok := data[key]; ok {
                      newPersonRecord[key] = dataKey
                  }
              }
              // Print records
              fmt.Printf("Old Person Record: %v\n", stalePersonRecord)
              fmt.Printf("New Person Record: %v\n", newPersonRecord)
          }
      }
  }
  ```

  ```python Python3 expandable theme={null}
  import requests, json

  # Set your API key
  API_KEY = "YOUR API KEY"

  # Set the Person Retrieve API URL
  PDL_BASE_URL = "https://api.peopledatalabs.com/v5/person/retrieve"

  # 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",
  } 

  # The ID for the record we want to update
  PERSON_ID = STALE_PERSON_RECORD['id'] 

  # Create a parameters JSON object
  PARAMS = {
      "api_key": API_KEY
  }

  # Append the person ID to the API URL
  URL_PATH = f"{PDL_BASE_URL}/{PERSON_ID}"

  # Pass the URL path and the parameters object to the Person Retrieve API
  json_response = requests.get(URL_PATH, params=PARAMS).json()

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

  # Print records
  print(f"Old Person Record: \n{STALE_PERSON_RECORD}")
  print(f"New Person Record: \n{new_person_record}")
  ```
</CodeGroup>


## Related topics

- [Examples - Person Search API](/docs/examples-person-search-api.md)
- [October 2022 Release Notes](/changelog/october-2022-release-notes-v20.md)
- [July 2023 Release Notes](/changelog/july-2023-release-notes-v23.md)
- [April 2022 Release Notes](/changelog/april-2022-release-notes-v18.md)
- [January 2023 Release Notes](/changelog/january-2023-release-notes-v21.md)
