---
title: "Developer guide to get employee leave information from GreytHR"
description: "Step-by-step guide to get employee leave info from GreytHR API using Python. Covers endpoints, headers, authentication, FAQs, and error handling."
source_url: "https://www.getknit.dev/blog/developer-guide-to-get-employee-leave-information-from-greythr"
page_type: "blog"
---

_This is an educational blog post from Knit's blog: “Developer guide to get employee leave information from GreytHR”._

# Developer guide to get employee leave information from GreytHR

## Introduction

This article is a part of a series of articles covering the GreytHR API in depth, and covers the specific use case of using the GreytHR API to get employee leave information.

You can find all the other use cases we have covered for the GreytHR API along with a comprehensive deep dive on its various aspects like authentication, rate limits etc [here](https://www.getknit.dev/blog/greythr-api-directory-9RnbMR).

### Prerequisites

*   Access to GreytHR API with valid credentials.
*   API access token.
*   Company domain registered with GreytHR.

### API Endpoints

*   Get Employee Leave Balance for a Year:  
    `https://api.greythr.com/leave/v2/employee/{employee-id}/years/{{Year}}/balance`
*   Get Leave Balance Details for All Employees:  
    `https://api.greythr.com/leave/v2/employee/years/{{Year}}/balance`
*   Get Leave Transactions Details for All Employees:  
    `https://api.greythr.com/leave/v2/employee/transactions?start={{StartDate}}&end={{EndDate}}`

#### Step 1: Set Up Headers

```
headers = {
    "ACCESS-TOKEN": "YourAccessToken",
}
```

#### Step 2: Get Employee Leave Balance for a Year

```
import requests

employee_id = "11"
year = "2020"

url = f"https://api.greythr.com/leave/v2/employee/{employee_id}/years/{year}/balance"

response = requests.get(url, headers=headers)
leave_balance = response.json()

print(leave_balance)
```

#### Step 3: Get Leave Balance Details for All Employees

```
import requests

year = "2021"

url = f"https://api.greythr.com/leave/v2/employee/years/{year}/balance"

response = requests.get(url, headers=headers)
all_leave_balances = response.json()

print(all_leave_balances)
```

#### Step 4: Get Leave Transactions Details for All Employees

```
import requests

start_date = "2020-06-01"
end_date = "2020-06-30"

url = f"https://api.greythr.com/leave/v2/employee/transactions?start={start_date}&end={end_date}"

response = requests.get(url, headers=headers)
leave_transactions = response.json()

print(leave_transactions)
```

### Common Pitfalls

*   Incorrect API endpoint URLs.
*   Invalid or expired access tokens.
*   Wrong company domain in headers.
*   Missing required request parameters.
*   Handling large datasets without implementing pagination.

### Frequently Asked Questions

**1\. What does the access token look like?**  
The access token is a unique string provided by GreytHR during authentication. Always keep it secure and refresh it as required.

**2\. How should I handle pagination in large responses?**  
GreytHR includes pagination details in responses. Use these parameters to iterate through pages and fetch the complete dataset without missing records.

**3\. Can I filter leave transactions by leave type?**  
The API doesn’t currently allow filtering by leave type at the endpoint level. You’ll need to fetch all transactions and then filter them client-side.

**4\. What should I check if I get a 401 Unauthorized error?**  
This usually indicates an invalid or expired token. Recheck your token, regenerate if needed, and ensure your request headers are correctly set.

**5\. Are there limits on how many requests I can make?**  
Yes. GreytHR enforces rate limits on API usage. Refer to their documentation or contact support to confirm the exact limits for your plan.

## Knit for GreytHR API Integration

For quick and seamless access to [GreytHR API](https://www.getknit.dev/integration/greythr), 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 [GreytHR API.](https://www.getknit.dev/integration/greythr)


## Related pages

- [How Knit works](https://md.getknit.dev/how-knit-works)
- [Unified API product](https://md.getknit.dev/products/unified-api)
