Get employee details from Personio API

Introduction

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

Get Employee Details from Personio API

Overview

To retrieve employee details such as first name, last name, and date of joining from the Personio API, you can utilize the listEmployees endpoint. Below is a step-by-step guide with Python code snippets to achieve this.

Step-by-Step Guide

1. Set Up Your Environment

Ensure you have the necessary libraries installed:

pip install requests

2. Define API Credentials

Set your API credentials for authentication:

api_url = "https://api.personio.de/v1/company/employees"
headers = {
    "X-Personio-Partner-ID": "your_partner_id",
    "X-Personio-App-ID": "your_app_id",
    "accept": "application/json"
}

3. Make the API Request

Send a GET request to the listEmployees endpoint to fetch the required details:

import requests

params = {
    "attributes[]": ["first_name", "last_name", "hire_date"]
}

response = requests.get(api_url, headers=headers, params=params)

if response.status_code == 200:
    employees = response.json().get("data", [])
    for employee in employees:
        first_name = employee["attributes"].get("first_name")
        last_name = employee["attributes"].get("last_name")
        hire_date = employee["attributes"].get("hire_date")
        print(f"First Name: {first_name}, Last Name: {last_name}, Date of Joining: {hire_date}")
else:
    print(f"Failed to retrieve data: {response.status_code}")

4. Handle the Response

Process the response to extract and display the employee details:

if response.status_code == 200:
    employees = response.json().get("data", [])
    for employee in employees:
        first_name = employee["attributes"].get("first_name")
        last_name = employee["attributes"].get("last_name")
        hire_date = employee["attributes"].get("hire_date")
        print(f"First Name: {first_name}, Last Name: {last_name}, Date of Joining: {hire_date}")
else:
    print(f"Failed to retrieve data: {response.status_code}")

Knit for Personio API Integration

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

#1 in Ease of Integrations

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