Get employee details from Namely API

Introduction

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

Get Employee Details from Namely API

Overview

To retrieve employee details such as first name, last name, and date of birth from the Namely API, you can use the GET /profiles endpoint. This endpoint returns all active and inactive employee profiles. Below is a step-by-step guide to achieve this using Python.

Step-by-Step Guide

1. Set Up Your Environment

Ensure you have the necessary Python packages installed. You can install the requests library using pip:

pip install requests

2. Define the API Endpoint and Headers

Set up the API endpoint and headers, including your API key for authorization.

import requests

sub_domain = 'your_sub_domain'
api_key = 'your_api_key'
url = f'https://{sub_domain}.namely.com/api/v1/profiles'
headers = {
    'Accept': 'application/json',
    'Authorization': f'Bearer {api_key}'
}

3. Make the API Request

Make a GET request to the Namely API to retrieve the profiles.

response = requests.get(url, headers=headers)
profiles = response.json().get('profiles', [])

4. Extract Required Information

Extract the first name, last name, and date of birth from the profiles.

employee_details = []
for profile in profiles:
    first_name = profile.get('first_name')
    last_name = profile.get('last_name')
    dob = profile.get('dob')
    employee_details.append({
        'first_name': first_name,
        'last_name': last_name,
        'dob': dob
    })

5. Print or Use the Extracted Data

You can now print or use the extracted employee details as needed.

for employee in employee_details:
    print(f"First Name: {employee['first_name']}, Last Name: {employee['last_name']}, Date of Birth: {employee['dob']}")

Knit for Namely API Integration

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

#1 in Ease of Integrations

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