Get all candidates for a job from Greenhouse API

Introduction

This article is a part of a series of articles covering the Greenhouse API in depth, and covers the specific use case of using the Greenhouse API to Get all candidates for a job from Greenhouse API.
You can find all the other use cases we have covered for the Greenhouse API along with a comprehensive deep dive on its various aspects like authentication, rate limits etc here.

Get all candidates for a job from Greenhouse API

Overview

To retrieve all candidates who have applied to a specific job using the Greenhouse API, you will need to utilize multiple API endpoints. This guide provides a step-by-step approach to achieve this using Python code snippets.

Step-by-Step Guide

1. Set Up Authorization

Greenhouse API uses Basic Auth for authorization. Ensure you have your API key ready.

import requests
from requests.auth import HTTPBasicAuth

api_key = 'YOUR_API_KEY'
auth = HTTPBasicAuth(api_key, '')

2. Fetch Candidates for a Specific Job

Use the GET /v1/candidates endpoint to fetch candidates who have applied to a specific job by providing the job_id parameter.

job_id = 'YOUR_JOB_ID'
url = 'https://harvest.greenhouse.io/v1/candidates'
params = {
    'job_id': job_id,
    'per_page': 100,
    'page': 1
}

response = requests.get(url, auth=auth, params=params)
candidates = response.json()

3. Extract Candidate Information

Iterate through the response to extract the first name, last name, and email of each candidate.

candidate_info = []

for candidate in candidates:
    first_name = candidate.get('first_name')
    last_name = candidate.get('last_name')
    email_addresses = candidate.get('email_addresses', [])
    email = email_addresses[0]['value'] if email_addresses else None
    
    candidate_info.append({
        'first_name': first_name,
        'last_name': last_name,
        'email': email
    })

print(candidate_info)

4. Handle Pagination

If there are more candidates than can be returned in a single response, handle pagination by iterating through pages.

all_candidates = []
page = 1

while True:
    params['page'] = page
    response = requests.get(url, auth=auth, params=params)
    candidates = response.json()
    
    if not candidates:
        break
    
    for candidate in candidates:
        first_name = candidate.get('first_name')
        last_name = candidate.get('last_name')
        email_addresses = candidate.get('email_addresses', [])
        email = email_addresses[0]['value'] if email_addresses else None
        
        all_candidates.append({
            'first_name': first_name,
            'last_name': last_name,
            'email': email
        })
    
    page += 1

print(all_candidates)

Knit for Greenhouse API Integration

For quick and seamless access to Greenhouse API, Knit API offers a convenient solution. By integrating with Knit just once, you can streamline the entire process. Knit takes care of all the authentication, authorization, and ongoing integration maintenance, this approach not only saves time but also ensures a smooth and reliable connection to your Greenhouse API.

#1 in Ease of Integrations

Trusted by businesses to streamline and simplify integrations seamlessly with GetKnit.