Get employee details from BreatheHR API

Introduction

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

Get Employee Details from BreatheHR API

Overview

The BreatheHR API allows you to retrieve detailed information about employees. This section will guide you through the process of obtaining the first name, last name, and date of joining for all employees using the BreatheHR API.

API Endpoints

  • Get All Employees: GET /v1/employees
  • Get Employee by ID: GET /v1/employees/{id}

Step-by-Step Guide

1. Fetch All Employees

First, you need to fetch the list of all employees using the GET /v1/employees endpoint.

import requests

url = "https://api.breathehr.com/v1/employees"
headers = {
    "Authorization": "Bearer YOUR_ACCESS_TOKEN",
    "Content-Type": "application/json"
}
params = {
    "page": 1,
    "per_page": 100
}

response = requests.get(url, headers=headers, params=params)
employees = response.json()

2. Extract Required Details

Next, extract the first name, last name, and date of joining from the response.

employee_details = []
for employee in employees:
    details = {
        "first_name": employee.get("first_name"),
        "last_name": employee.get("last_name"),
        "join_date": employee.get("join_date")
    }
    employee_details.append(details)

print(employee_details)

3. Handle Pagination (if necessary)

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

employee_details = []
page = 1
while True:
    params["page"] = page
    response = requests.get(url, headers=headers, params=params)
    employees = response.json()
    if not employees:
        break
    for employee in employees:
        details = {
            "first_name": employee.get("first_name"),
            "last_name": employee.get("last_name"),
            "join_date": employee.get("join_date")
        }
        employee_details.append(details)
    page += 1

print(employee_details)

Knit for BreatheHR API Integration

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

#1 in Ease of Integrations

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