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 open jobs 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 open jobs from Greenhouse API
Overview
To retrieve all open jobs from the Greenhouse API, you need to utilize two endpoints: one to list all jobs and another to get the openings for each job. Below is a step-by-step guide with Python code snippets to achieve this.
Step-by-Step Guide
1. List All Jobs
First, use the GET /v1/jobs
endpoint to list all jobs in the organization.
import requests
import base64
# Replace with your Greenhouse API key
api_key = 'YOUR_API_KEY'
auth = base64.b64encode(f'{api_key}:'.encode()).decode()
url = 'https://harvest.greenhouse.io/v1/jobs'
headers = {
'Authorization': f'Basic {auth}'
}
response = requests.get(url, headers=headers)
jobs = response.json()
2. Filter Open Jobs
Filter the jobs to include only those with the status 'open'.
open_jobs = [job for job in jobs if job['status'] == 'open']
3. Get Openings for Each Job
For each open job, use the GET /v1/jobs/{job_id}/openings
endpoint to retrieve the openings.
openings_url_template = 'https://harvest.greenhouse.io/v1/jobs/{job_id}/openings'
open_jobs_with_openings = []
for job in open_jobs:
job_id = job['id']
openings_url = openings_url_template.format(job_id=job_id)
response = requests.get(openings_url, headers=headers)
openings = response.json()
open_jobs_with_openings.append({
'job': job,
'openings': [opening for opening in openings if opening['status'] == 'open']
})
4. Result
The open_jobs_with_openings
list now contains all open jobs along with their open openings.
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.