How to get employee dependent data from BambooHR API (Python Example)

Introduction

This article is a part of a series of articles covering the BambooHR API in depth, and covers the specific use case of using the BambooHR API to Get employee details.

If you are looking for a comprehensive directory of BambooHR API endpoints to discover what endpoints will fit best for your use case, check our BambooHR API Directory.

BambooHR API: Get Employee Details

Overview

To retrieve detailed information about employees in BambooHR, you can utilize multiple APIs. This guide provides a step-by-step approach to get the first name and last name of all employees using the BambooHR API.

Step-by-Step Guide

Step 1: Get Employee Directory

First, you need to fetch the employee directory, which contains basic information about all employees.

Endpoint
GET https://api.bamboohr.com/api/gateway.php/{companyDomain}/v1/employees/directory
Sample Python Code
import requests

company_domain = 'your_company_domain'
url = f'https://api.bamboohr.com/api/gateway.php/{company_domain}/v1/employees/directory'
headers = {
   'Accept': 'application/json',
   'Authorization': 'Basic YOUR_API_KEY'
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
   employees = response.json().get('employees', [])
   for employee in employees:
       print(f"First Name: {employee.get('firstName')}, Last Name: {employee.get('lastName')}")
else:
   print(f"Failed to retrieve employee directory: {response.status_code}")

Step 2: Get Employee Dependents (Optional)

If you need additional details such as employee dependents, you can use the following endpoint.

Endpoint
GET https://api.bamboohr.com/api/gateway.php/{companyDomain}/v1/employeedependents
Sample Python Code
employee_id = 'specific_employee_id'
url = f'https://api.bamboohr.com/api/gateway.php/{company_domain}/v1/employeedependents?employeeid={employee_id}'
response = requests.get(url, headers=headers)
if response.status_code == 200:
   dependents = response.json().get('Employee Dependents', [])
   for dependent in dependents:
       print(f"Dependent Name: {dependent.get('firstName')} {dependent.get('lastName')}")
else:
   print(f"Failed to retrieve employee dependents: {response.status_code}")

Knit for BambooHR API Integration

For quick and seamless access to BambooHR 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 BambooHR API.

#1 in Ease of Integrations

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