Examples - Cleaner APIs

Code examples and walkthroughs using the Cleaner APIs

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

📘

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 these APIs that you'd like to see here.

Company Cleaner API Example

# 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
QUERY_STRING = {"website":"peopledatalabs.com"}

# Pass the parameters object to the Company Cleaner API
response = CLIENT.company.cleaner(**QUERY_STRING)

# Print the API response
print(response.text)
curl -X GET -G \
  'https://api.peopledatalabs.com/v5/company/clean' \
  -H 'X-Api-Key: xxxx' \
  --data-urlencode 'website=peopledatalabs.com'
// 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" });

// Create a parameters JSON object
const params = {
  website: "peopledatalabs.com"
}

// Pass the parameters object to the Company Cleaner API
PDLJSClient.company.cleaner(params).then((data) => {
  // Print the API response
  console.log(data);
}).catch((error) => {
  console.log(error);
});
# See https://github.com/peopledatalabs/peopledatalabs-ruby
require 'peopledatalabs'

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

# Pass parameters to the Company Cleaner API
response = Peopledatalabs::Cleaner.company(kind: "website", value: "peopledatalabs.com")

# Print the API response
puts response
package main

import (
    "fmt"
    "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.CleanCompanyParams {
        Website: "peopledatalabs.com",
    }
    
    // Pass the parameters object to the Company Cleaner API
    response, err := client.Company.Clean(context.Background(), params)
    // Check for successful response
    if err == nil {
        // Print the API response
        fmt.Println(response)
    }  
}
import requests

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

# Set the Company Cleaner API URL
PDL_URL = "https://api.peopledatalabs.com/v5/company/clean"

# Create a parameters JSON object
QUERY_STRING = {"website":"peopledatalabs.com"}

# Set headers
HEADERS = {
    'accept': "application/json",
    'content-type': "application/json",
    'x-api-key': API_KEY
}

# Pass the parameters object to the Company Cleaner API
response = requests.request("GET", PDL_URL, headers=HEADERS, params=QUERY_STRING)

# Print the API response
print(response.text)

Location Cleaner API Example

# 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
QUERY_STRING = {"location":"239 NW 13th Ave, Portland, Oregon 97209, US"}

# Pass the parameters object to the Location Cleaner API
response = CLIENT.location.cleaner(**QUERY_STRING)

# Print the API response
print(response.text)
curl -X GET -G \
  'https://api.peopledatalabs.com/v5/location/clean' \
  -H 'X-Api-Key: xxxx' \
  --data-urlencode 'location=239 NW 13th Ave, Portland, Oregon 97209, US'
// 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" });

// Create a parameters JSON object
const params = {
  location:"239 NW 13th Ave, Portland, Oregon 97209, US"
}

// Pass the parameters object to the Location Cleaner API
PDLJSClient.location.cleaner(params).then((data) => {
  // Print the API response
  console.log(data);
}).catch((error) => {
  console.log(error);
});
# See https://github.com/peopledatalabs/peopledatalabs-ruby
require 'peopledatalabs'

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

# Pass parameters to the Location Cleaner API
response = Peopledatalabs::Cleaner.location(value: "239 NW 13th Ave, Portland, Oregon 97209, US")

# Print the API response
puts response
package main

import (
    "fmt"
    "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
    querystring := pdlmodel.LocationParams{Location: "239 NW 13th Ave, Portland, Oregon 97209, US"}
    
    // Pass the parameters object to the Location Cleaner API
    params := pdlmodel.CleanLocationParams {
        LocationParams: querystring,
    }
    
    // Check for successful response
    response, err := client.Location.Clean(context.Background(), params)
    if err == nil {
        // Print the API response
        fmt.Println(response)
    }  
}
import requests

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

# Set the Location Cleaner API URL
PDL_URL = "https://api.peopledatalabs.com/v5/location/clean"

# Create a parameters JSON object
QUERY_STRING = {"location":"239 NW 13th Ave, Portland, Oregon 97209, US"}

# Set headers
HEADERS = {
    'accept': "application/json",
    'content-type': "application/json",
    'x-api-key': API_KEY
}

# Pass the parameters object to the Location Cleaner API
response = requests.request("GET", PDL_URL, headers=HEADERS, params=QUERY_STRING)

# Print the API response
print(response.text)

School Cleaner API Example

# 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
QUERY_STRING = {"profile":"linkedin.com/school/ucla"}

# Pass the parameters object to the School Cleaner API
response = CLIENT.school.cleaner(**QUERY_STRING)

# Print the API response
print(response.text)
curl -X GET -G \
  'https://api.peopledatalabs.com/v5/school/clean' \
  -H 'X-Api-Key: xxxx' \
  --data-urlencode 'profile=linkedin.com/school/ucla'
// 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" });

// Create a parameters JSON object
const params = {
  profile:"linkedin.com/school/ucla"
}

// Pass the parameters object to the School Cleaner API
PDLJSClient.school.cleaner(params).then((data) => {
  // Print the API response
  console.log(data);
}).catch((error) => {
  console.log(error);
});
# See https://github.com/peopledatalabs/peopledatalabs-ruby
require 'peopledatalabs'

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

# Pass parameters to the School Cleaner API
response = Peopledatalabs::Cleaner.school(kind: "profile", value: "linkedin.com/school/ucla")

# Print the API response
puts response
package main

import (
    "fmt"
    "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
    querystring := pdlmodel.SchoolParams{Profile: "linkedin.com/school/ucla"}
    
    // Pass the parameters object to the School Cleaner API
    params := pdlmodel.CleanSchoolParams {
        SchoolParams: querystring,
    }
    
    // Check for successful response
    response, err := client.School.Clean(context.Background(), params)
    if err == nil {
        // Print the API response
        fmt.Println(response)
    }  
}
import requests

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

# Set the School Cleaner API URL
PDL_URL = "https://api.peopledatalabs.com/v5/school/clean"

# Create a parameters JSON object
QUERY_STRING = {"profile":"linkedin.com/school/ucla"}

# Set headers
HEADERS = {
    'accept': "application/json",
    'content-type': "application/json",
    'x-api-key': API_KEY
}

# Pass the parameters object to the School Cleaner API
response = requests.request("GET", PDL_URL, headers=HEADERS, params=QUERY_STRING)

# Print the API response
print(response.text)

Advanced Example

"I want to find employees at a particular company but don't have the PDL identifier for the company."

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",
)

# Set the website of the company you want to search
COMPANY_WEBSITE = "peopledatalabs.com"

# Create a parameters JSON object for the Company Cleaner API
QUERY_STRING = { "website": COMPANY_WEBSITE }

# Pass the parameters object to the Company Cleaner API
response = CLIENT.company.cleaner(**QUERY_STRING)

# Check for successful response
if response.status_code == 200:
    # Store the cleaned company from the API response
    cleaned_company = response.json()
else:
    cleaned_company = {}
    print(f"Company Cleaner API Error for [{COMPANY_WEBSITE}]: {response.text}")

# Employees at the cleaned company
company_employee_matches = {}

# Check for cleaned company
if cleaned_company:
    # Create an Elasticsearch query
    ES_QUERY = {
        "query": {
            "bool": {
                "must": [
                    {"term": {"job_company_id": cleaned_company['id']}}
                ]
            }
        }
    }

    # Create a parameters JSON object for the Person Search API
    PARAMS = {
        'query': ES_QUERY,
        'size': 100
    }

    # Pass the parameters object to the Person Search API
    response = CLIENT.person.search(**PARAMS)

    # Check for successful response
    if response.status_code == 200:
        # Store the employees of the cleaned company from the API response
        company_employee_matches = response.json()['data']
    else:
        company_employee_matches = {}
        print(f"Person Search Error for [{COMPANY_WEBSITE}]: {response.text}")

print(f"Found {len(company_employee_matches)} employee profiles at {COMPANY_WEBSITE}.")
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",
)

# Set the website of the company you want to search
COMPANY_WEBSITE = "peopledatalabs.com"

# Create a parameters JSON object for the Company Cleaner API
QUERY_STRING = { "website": COMPANY_WEBSITE }

# Pass the parameters object to the Company Cleaner API
response = CLIENT.company.cleaner(**QUERY_STRING)

# Check for successful response
if response.status_code == 200:
    # Store the cleaned company from the API response
    cleaned_company = response.json()
else:
    cleaned_company = {}
    print(f"Company Cleaner API Error for [{COMPANY_WEBSITE}]: {response.text}")

# Employees at the cleaned company
company_employee_matches = {}

# Check for cleaned company
if cleaned_company:
    # Create an SQL query
    SQL_QUERY = f"""
    SELECT * FROM person
    WHERE job_company_id = '{cleaned_company['id']}'
    """

    # Create a parameters JSON object for the Person Search API
    PARAMS = {
        'sql': SQL_QUERY,
        'size': 100
    }

    # Pass the parameters object to the Person Search API
    response = CLIENT.person.search(**PARAMS)

    # Check for successful response
    if response.status_code == 200:
        # Store the employees of the cleaned company from the API response
        company_employee_matches = response.json()['data']
    else:
        company_employee_matches = {}
        print(f"Person Search Error for [{COMPANY_WEBSITE}]: {response.text}")

print(f"Found {len(company_employee_matches)} employee profiles at {COMPANY_WEBSITE}.")
// 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" });

// Set the website of the company you want to search
const companyWebsite = "peopledatalabs.com";

// Create a parameters JSON object for the Company Cleaner API
const queryString = { "website": companyWebsite };

// The cleaned company
var cleanedCompany;

// Pass the parameters object to the Company Cleaner API
PDLJSClient.company.cleaner(queryString).then((data) => {

    // Store the cleaned company from the API response
    cleanedCompany = data;
    
    // Employees at the cleaned company
    var companyEmployeeMatches = {};
    
    // Create an Elasticsearch query
    const esQuery = {
      query: {
         bool: {
            must:[
               {"term": {"job_company_id": cleanedCompany["id"]}}
            ]
         }
      }
    }
    
    // Create a parameters JSON object for the Person Search API
    const params = {
        searchQuery: esQuery, 
        size: 100,
    }
    
    // Pass the parameters object to the Person Search API
    PDLJSClient.person.search.elastic(params).then((data) => {
        // Store the employees of the cleaned company from the API response
        companyEmployeeMatches = data.data;
        console.log(`Found ${companyEmployeeMatches.length} employee profiles at ${companyWebsite}.`);
    }).catch((error) => {
        companyEmployeeMatches = {};
        console.log(`Person Search Error for [${companyWebsite}]: ${error}`);
    });
    
}).catch((error) => {
    console.log(error);
});
// 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" });

// Set the website of the company you want to search
const companyWebsite = "peopledatalabs.com";

// Create a parameters JSON object for the Company Cleaner API
const queryString = { "website": companyWebsite };

// The cleaned company
var cleanedCompany;

// Pass the parameters object to the Company Cleaner API
PDLJSClient.company.cleaner(queryString).then((data) => {

    // Store the cleaned company from the API response
    cleanedCompany = data;
    
    // Employees at the cleaned company
    var companyEmployeeMatches = {};
    
    // Create an SQL query
    const sqlQuery = `SELECT * FROM person
                        WHERE job_company_id = '` + cleanedCompany["id"] + `';`;
    
    // Create a parameters JSON object for the Person Search API
    const params = {
        searchQuery: sqlQuery, 
        size: 100,
    }
    
    // Pass the parameters object to the Person Search API
    PDLJSClient.person.search.sql(params).then((data) => {
        // Store the employees of the cleaned company from the API response
        companyEmployeeMatches = data.data;
        console.log(`Found ${companyEmployeeMatches.length} employee profiles at ${companyWebsite}.`);
    }).catch((error) => {
        companyEmployeeMatches = {};
        console.log(`Person Search Error for [${companyWebsite}]: ${error}`);
    });
    
}).catch((error) => {
    console.log(error);
});
require 'json'

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

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

# Set the website of the company you want to search
COMPANY_WEBSITE = "peopledatalabs.com"

# Pass parameters to the Company Cleaner API
response = Peopledatalabs::Cleaner.company(kind: "website", value: COMPANY_WEBSITE)

# Check for successful response
if response['status'] == 200
    # Store the cleaned company from the API response
    cleaned_company = response
else
    cleaned_company = {}
    puts "Company Cleaner API Error for #{COMPANY_WEBSITE}: #{response}"
end

# Employees at the cleaned company
company_employee_matches = {}

# Check for cleaned company
if cleaned_company
    # Create an Elasticsearch query
    ES_QUERY = {
        "query": {
            "bool": {
                "must": [
                    {"term": {"job_company_id": cleaned_company['id']}}
                ]
            }
        }
    }

    # Pass parameters to the Person Search API
    response = Peopledatalabs::Search.people(searchType: 'elastic', query: ES_QUERY, size: 100)

    # Check for successful response
    if response['status'] == 200
        # Store the employees of the cleaned company from the API response
        company_employee_matches = response['data']
    else
        company_employee_matches = []
        puts "Person Search Error for [#{COMPANY_WEBSITE}]: #{response}"
    end
end
puts "Found #{company_employee_matches.length()} employee profiles at #{COMPANY_WEBSITE}."
require 'json'

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

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

# Set the website of the company you want to search
COMPANY_WEBSITE = "peopledatalabs.com"

# Pass parameters to the Company Cleaner API
response = Peopledatalabs::Cleaner.company(kind: "website", value: COMPANY_WEBSITE)

# Check for successful response
if response['status'] == 200
    # Store the cleaned company from the API response
    cleaned_company = response
else
    cleaned_company = {}
    puts "Company Cleaner API Error for #{COMPANY_WEBSITE}: #{response}"
end

# Employees at the cleaned company
company_employee_matches = {}

# Check for cleaned company
if cleaned_company
    # Create an SQL query
    SQL_QUERY = """
    SELECT * FROM person
    WHERE job_company_id = '#{cleaned_company['id']}'
    """

    # Pass parameters to the Person Search API
    response = Peopledatalabs::Search.people(searchType: 'sql', query: SQL_QUERY, size: 10)

    # Check for successful response
    if response['status'] == 200
        # Store the employees of the cleaned company from the API response
        company_employee_matches = response['data']
    else
        company_employee_matches = []
        puts "Person Search Error for [#{COMPANY_WEBSITE}]: #{response}"
    end
end
puts "Found #{company_employee_matches.length()} employee profiles at #{COMPANY_WEBSITE}."
package main

import (
    "fmt"
    "encoding/json"
    "reflect"
    "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)
    
    // Set the website of the company you want to search
    companyWebsite := "peopledatalabs.com"

    // Create a parameters JSON object for the Company Cleaner API
    cleanParams := pdlmodel.CleanCompanyParams {
        Website: "peopledatalabs.com",
    }
    
    // The cleaned company
    var cleanedCompany pdlmodel.CleanCompanyResponse
    
    // Pass the parameters object to the Company Cleaner API
    cleanResponse, cleanErr := client.Company.Clean(context.Background(), cleanParams)
    // Check for successful response
    if cleanErr == nil {
        // Store the cleaned company from the API response
        cleanedCompany = cleanResponse
    } else {
        fmt.Printf("Company Cleaner API Error for [%s]: %s", companyWebsite, cleanResponse)
    }
    
    // Check for cleaned company
    if !reflect.ValueOf(cleanedCompany).IsZero() {
        // Create an Elasticsearch query
        elasticSearchQuery := map[string]interface{} {
            "query": map[string]interface{} {
                "bool": map[string]interface{} {
                    "must": []map[string]interface{} {
                        {"term": map[string]interface{}{"job_company_id": cleanedCompany.Id}},
                    },
                },
            },
        }

        // Create a parameters JSON object for the Person Search API
        searchParams := pdlmodel.SearchParams {
            BaseParams: pdlmodel.BaseParams {
                Size: 100,
            },
            SearchBaseParams: pdlmodel.SearchBaseParams {
                Query: elasticSearchQuery,
            },
        }
        
        // Pass the parameters object to the Person Search API
        SearchResponse, SearchErr := client.Person.Search(context.Background(), searchParams)
        // Check for successful response
        if SearchErr == nil {
            data := SearchResponse.Data
            // Store the employees of the cleaned company from the API response in JSON format
            companyEmployeeMatches, jsonErr := json.Marshal(data)
     
            if jsonErr == nil && !reflect.ValueOf(companyEmployeeMatches).IsZero() {
                fmt.Printf("Found %d employee profiles at %s.\n", len(data), companyWebsite)
            }
        } else {
            fmt.Printf("Company Cleaner API Error for [%s]: %s\n", companyWebsite, SearchResponse)
        }
    }
}
package main

import (
    "fmt"
    "encoding/json"
    "reflect"
    "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)
    
    // Set the website of the company you want to search
    companyWebsite := "peopledatalabs.com"

    // Create a parameters JSON object for the Company Cleaner API
    cleanParams := pdlmodel.CleanCompanyParams {
        Website: "peopledatalabs.com",
    }
    
    // The cleaned company
    var cleanedCompany pdlmodel.CleanCompanyResponse
    
    // Pass the parameters object to the Company Cleaner API
    cleanResponse, cleanErr := client.Company.Clean(context.Background(), cleanParams)
    // Check for successful response
    if cleanErr == nil {
        // Store the cleaned company from the API response
        cleanedCompany = cleanResponse
    } else {
        fmt.Printf("Company Cleaner API Error for [%s]: %s", companyWebsite, cleanResponse)
    }
    
    // Check for cleaned company
    if !reflect.ValueOf(cleanedCompany).IsZero() {
        // Create an SQL query
        sqlQuery := "SELECT * FROM person" +
            " WHERE job_company_id='" + cleanedCompany.Id + "';"

        // Create a parameters JSON object for the Person Search API
        searchParams := pdlmodel.SearchParams {
            BaseParams: pdlmodel.BaseParams {
                Size: 100,
            },
            SearchBaseParams: pdlmodel.SearchBaseParams {
                SQL: sqlQuery,
            },
        }
        
        // Pass the parameters object to the Person Search API
        SearchResponse, SearchErr := client.Person.Search(context.Background(), searchParams)
        // Check for successful response
        if SearchErr == nil {
            data := SearchResponse.Data
            // Store the employees of the cleaned company from the API response in JSON format
            companyEmployeeMatches, jsonErr := json.Marshal(data)
     
            if jsonErr == nil && !reflect.ValueOf(companyEmployeeMatches).IsZero() {
                fmt.Printf("Found %d employee profiles at %s.\n", len(data), companyWebsite)
            }
        } else {
            fmt.Printf("Company Cleaner API Error for [%s]: %s\n", companyWebsite, SearchResponse)
        }
    }
}
import json
import requests

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

# Set the Company Cleaner API URL
PDL_COMPANY_CLEANER_URL = "https://api.peopledatalabs.com/v5/company/clean"
# Set the Person Search API URL
PDL_PERSON_SEARCH_URL = "https://api.peopledatalabs.com/v5/person/search"

# Set the website of the company you want to search
COMPANY_WEBSITE = "peopledatalabs.com"

# Create a parameters JSON object for the Company Cleaner API
QUERY_STRING = { "website": COMPANY_WEBSITE }

# Set headers
HEADERS = {
    'accept': "application/json",
    'content-type': "application/json",
    'x-api-key': API_KEY
}

# Pass the parameters object to the Company Cleaner API
response = requests.request("GET", PDL_COMPANY_CLEANER_URL, headers=HEADERS, params=QUERY_STRING)

# Check for successful response
if response.status_code == 200:
    # Store the cleaned company from the API response
    cleaned_company = response.json()
else:
    cleaned_company = {}
    print(f"Company Cleaner API Error for [{COMPANY_WEBSITE}]: {response.text}")

# Employees at the cleaned company
company_employee_matches = {}

# Check for cleaned company
if cleaned_company:
    # Set headers
    HEADERS = {
        'Content-Type': "application/json",
        'X-api-key': API_KEY
    }

    # Create an Elasticsearch query
    ES_QUERY = {
        "query": {
            "bool": {
                "must": [
                    {"term": {"job_company_id": cleaned_company['id']}}
                ]
            }
        }
    }

    # Create a parameters JSON object for the Person Search API
    PARAMS = {
        'query': json.dumps(ES_QUERY),
        'size': 100
    }

    # Pass the parameters object to the Person Search API
    response = requests.get(PDL_PERSON_SEARCH_URL, headers=HEADERS, params=PARAMS)

    # Check for successful response
    if response.status_code == 200:
        # Store the employees of the cleaned company from the API response
        company_employee_matches = response.json()['data']
    else:
        company_employee_matches = {}
        print(f"Person Search Error for [{COMPANY_WEBSITE}]: {response.text}")

print(f"Found {len(company_employee_matches)} employee profiles at {COMPANY_WEBSITE}.")
import json
import requests

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

# Set the Company Cleaner API URL
PDL_COMPANY_CLEANER_URL = "https://api.peopledatalabs.com/v5/company/clean"
# Set the Person Search API URL
PDL_PERSON_SEARCH_URL = "https://api.peopledatalabs.com/v5/person/search"

# Set the website of the company you want to search
COMPANY_WEBSITE = "peopledatalabs.com"

# Create a parameters JSON object for the Company Cleaner API
QUERY_STRING = { "website": COMPANY_WEBSITE }

# Set headers
HEADERS = {
    'accept': "application/json",
    'content-type': "application/json",
    'x-api-key': API_KEY
}

# Pass the parameters object to the Company Cleaner API
response = requests.request("GET", PDL_COMPANY_CLEANER_URL, headers=HEADERS, params=QUERY_STRING)

# Check for successful response
if response.status_code == 200:
    # Store the cleaned company from the API response
    cleaned_company = response.json()
else:
    cleaned_company = {}
    print(f"Company Cleaner API Error for [{COMPANY_WEBSITE}]: {response.text}")

# Employees at the cleaned company
company_employee_matches = {}

# Check for cleaned company
if cleaned_company:
    # Set HEADERS
    headers = {
        'Content-Type': "application/json",
        'X-api-key': API_KEY
    }

    # Create an SQL query
    SQL_QUERY = f"""
    SELECT * FROM person
    WHERE job_company_id = '{cleaned_company['id']}'
    """

    # Create a parameters JSON object for the Person Search API
    PARAMS = {
        'sql': SQL_QUERY,
        'size': 100
    }

    # Pass the parameters object to the Person Search API
    response = requests.get(PDL_PERSON_SEARCH_URL, headers=HEADERS, params=PARAMS)

    # Check for successful response
    if response.status_code == 200:
        # Store the employees of the cleaned company from the API response
        company_employee_matches = response.json()['data']
    else:
        company_employee_matches = {}
        print(f"Person Search Error for [{COMPANY_WEBSITE}]: {response.text}")

print(f"Found {len(company_employee_matches)} employee profiles at {COMPANY_WEBSITE}.")