Get Employee Details from Workline API

Thanks for joining our newsletter.
Oops! Something went wrong while submitting the form.
Get Employee Details from Workline APIGet Employee Details from Workline API

Introduction

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

Get Employee Details from Workline API

Overview

The Workline API provides various endpoints to retrieve detailed information about employees. To get the first name, last name, and email for all employees, you can utilize multiple APIs provided by Workline. Below is a step-by-step guide using Python to achieve this.

Step-by-Step Guide

1. Set Up Basic Authentication

All API requests require basic authentication. Ensure you have your AppID, Username, and Password ready.

2. Define API Endpoints

We will use the following API endpoints:

  • https://{domain}.workline.hr/api/GetEmployeesData
  • https://{domain}.workline.hr/api/GetEmpDetails

3. Fetch Employee Data

First, we will fetch the basic employee data using the GetEmployeesData endpoint.

import requests
from requests.auth import HTTPBasicAuth

domain = 'your_domain'
app_id = 'your_app_id'
username = 'your_username'
password = 'your_password'
start_date = '10-Apr-2019'
end_date = '25-May-2019'

url = f'https://{domain}.workline.hr/api/GetEmployeesData'
headers = {
    'AppID': app_id,
    'StartDate': start_date,
    'EndDate': end_date
}

response = requests.post(url, headers=headers, auth=HTTPBasicAuth(username, password))
employees = response.json()

for employee in employees:
    print(employee['FirstName'], employee['LastName'], employee['Emailid'])

4. Fetch Additional Employee Details

For more detailed information, you can use the GetEmpDetails endpoint.

for employee in employees:
    email_id = employee['Emailid']
    url = f'https://{domain}.workline.hr/api/GetEmpDetails'
    headers = {
        'AppID': app_id,
        'EmailID': email_id
    }
    
    response = requests.post(url, headers=headers, auth=HTTPBasicAuth(username, password))
    emp_details = response.json()
    
    for detail in emp_details:
        print(detail['FirstName'], detail['LastName'], detail['Emailid'])

5. Combine Data

To combine data from both endpoints, you can store the results in a list or a dictionary.

combined_data = []

for employee in employees:
    email_id = employee['Emailid']
    url = f'https://{domain}.workline.hr/api/GetEmpDetails'
    headers = {
        'AppID': app_id,
        'EmailID': email_id
    }
    
    response = requests.post(url, headers=headers, auth=HTTPBasicAuth(username, password))
    emp_details = response.json()
    
    for detail in emp_details:
        combined_data.append({
            'FirstName': detail['FirstName'],
            'LastName': detail['LastName'],
            'Emailid': detail['Emailid']
        })

print(combined_data)

Conclusion

By following the above steps, you can efficiently retrieve the first name, last name, and email of all employees using the Workline API.

Knit for Workline API Integration

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