Hey there, fellow code wrangler! Ready to dive into the world of recruitment automation? We're about to embark on a journey to build a slick Recruitee API integration using Python. This nifty tool will help you manage candidates, job postings, and more, all from the comfort of your favorite IDE. Let's get cracking!
Before we start, make sure you've got:
First things first, let's get our environment ready:
pip install requests
Now, let's set up our API credentials:
import os API_KEY = os.environ.get('RECRUITEE_API_KEY') COMPANY_ID = os.environ.get('RECRUITEE_COMPANY_ID') BASE_URL = f'https://api.recruitee.com/c/{COMPANY_ID}'
Pro tip: Always use environment variables for sensitive info. Your future self will thank you!
Let's start with a simple GET request to test the waters:
import requests def get_candidates(): response = requests.get(f'{BASE_URL}/candidates', headers={'Authorization': f'Bearer {API_KEY}'}) response.raise_for_status() return response.json() candidates = get_candidates() print(f"Found {len(candidates['candidates'])} candidates")
Now that we've got the basics down, let's implement some core features:
def create_candidate(data): response = requests.post(f'{BASE_URL}/candidates', json=data, headers={'Authorization': f'Bearer {API_KEY}'}) response.raise_for_status() return response.json() def update_candidate(candidate_id, data): response = requests.patch(f'{BASE_URL}/candidates/{candidate_id}', json=data, headers={'Authorization': f'Bearer {API_KEY}'}) response.raise_for_status() return response.json() def get_job_postings(): response = requests.get(f'{BASE_URL}/offers', headers={'Authorization': f'Bearer {API_KEY}'}) response.raise_for_status() return response.json()
Let's add some resilience to our code:
import time from requests.exceptions import RequestException def api_call_with_retry(func, max_retries=3, delay=1): for attempt in range(max_retries): try: return func() except RequestException as e: if attempt == max_retries - 1: raise time.sleep(delay * (2 ** attempt))
Time to make sense of all that data:
import sqlite3 def store_candidates(candidates): conn = sqlite3.connect('recruitee.db') c = conn.cursor() c.execute('''CREATE TABLE IF NOT EXISTS candidates (id INTEGER PRIMARY KEY, name TEXT, email TEXT)''') for candidate in candidates: c.execute("INSERT OR REPLACE INTO candidates VALUES (?, ?, ?)", (candidate['id'], candidate['name'], candidate['email'])) conn.commit() conn.close() store_candidates(get_candidates()['candidates'])
Let's make our tool user-friendly:
import argparse def main(): parser = argparse.ArgumentParser(description='Recruitee API Integration') parser.add_argument('action', choices=['list', 'create', 'update']) args = parser.parse_args() if args.action == 'list': candidates = get_candidates() for candidate in candidates['candidates']: print(f"{candidate['id']}: {candidate['name']} ({candidate['email']})") # Implement other actions here if __name__ == '__main__': main()
Want to level up? Try implementing webhooks or bulk operations. The sky's the limit!
Don't forget to test your code! Here's a simple example:
import unittest class TestRecruiteeAPI(unittest.TestCase): def test_get_candidates(self): candidates = get_candidates() self.assertIsInstance(candidates, dict) self.assertIn('candidates', candidates) if __name__ == '__main__': unittest.main()
When deploying, remember to:
And there you have it! You've just built a powerful Recruitee API integration in Python. With this foundation, you can automate your recruitment process, save time, and focus on finding the best talent out there.
Remember, the Recruitee API has a lot more to offer. Don't be afraid to explore and expand on this integration. Happy coding, and may your candidate pipeline always be full!