> ## Documentation Index
> Fetch the complete documentation index at: https://help.dingtalk.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Calculate Leave Duration

> Call this API with an employee's userId and a start and end time to calculate the employee's leave duration for that period based on scheduling rules.

Call this API to get each employee's leave duration, calculated automatically based on scheduling rules.

## Request

| **Basic Information** | |
| - | - |
| HTTP URL | [https://api.dingtalk.io/topapi/attendance/getleaveapproveduration](https://api.dingtalk.io/topapi/attendance/getleaveapproveduration) |
| HTTP Method | POST |
| Supported app types | appType-Internal app　appType-Third-party enterprise app |
| Required permissions | permission-qyapi\_base-Basic permission required to call organization APIs |

### Query Parameters

| Name | Type | Required | Example | Description |
| - | - | - | - | - |
| access\_token | String | Yes | bE74xxxx | The app credential used to call this API.   - Internal app: Get it by calling [Get the access\_token of an internal app](https://help.dingtalk.io/open/development/obtain-orgapp-token). - Third-party enterprise app: Get it by calling the API that gets the access\_token of a third-party enterprise. |

### Request Body

| Name | Type | Required | Example | Description |
| - | - | - | - | - |
| userid | String | Yes | user123 | The employee's user ID in your organization. The organization uses this field to uniquely identify the user. |
| from\_date | Date | Yes | 2016-03-09 11:11:11 | The start time of the leave. |
| to\_date | Date | Yes | 2016-03-10 11:11:11 | The end time of the leave. |

### Request Example

```curl theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -X POST "https://api.dingtalk.io/topapi/attendance/getleaveapproveduration" \
-H 'Content-Type:application/x-www-form-urlencoded;charset=utf-8' \
-d 'access_token=6777xxxx6f4eff' \
-d 'from_date=2016-03-09+11%3A11%3A11' \
-d 'to_date=2016-03-10+11%3A11%3A11' \
-d 'userid=zhangsan'
```

Java

```java theme={"theme":{"light":"github-light","dark":"github-dark"}}
DingTalkClient client = new DefaultDingTalkClient("https://api.dingtalk.io/topapi/attendance/getleaveapproveduration");
OapiAttendanceGetleaveapprovedurationRequest req = new OapiAttendanceGetleaveapprovedurationRequest();
req.setUserid("user123");
req.setFromDate(StringUtils.parseDateTime("2016-03-09 11:11:11"));
req.setToDate(StringUtils.parseDateTime("2016-03-10 11:11:11"));
OapiAttendanceGetleaveapprovedurationResponse rsp = client.execute(req, access_token);
System.out.println(rsp.getBody());
```

Python

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
import dingtalk.api

req=dingtalk.api.OapiAttendanceGetleaveapprovedurationRequest("https://api.dingtalk.io/topapi/attendance/getleaveapproveduration")

req.userid="zhangsan"
req.from_date="2016-03-09 11:11:11"
req.to_date="2016-03-10 11:11:11"
try:
  resp= req.getResponse(access_token)
  print(resp)
except Exception,e:
  print(e)
```

PHP

```php theme={"theme":{"light":"github-light","dark":"github-dark"}}
include "TopSdk.php";
date_default_timezone_set('Asia/Shanghai');

$c = new DingTalkClient(DingTalkConstant::$CALL_TYPE_OAPI, DingTalkConstant::$METHOD_POST , DingTalkConstant::$FORMAT_JSON);
$req = new OapiAttendanceGetleaveapprovedurationRequest;
$req->setUserid("zhangsan");
$req->setFromDate("2016-03-09 11:11:11");
$req->setToDate("2016-03-10 11:11:11");
$resp = $c->execute($req, $access_token, "https://api.dingtalk.io/topapi/attendance/getleaveapproveduration");
```

C#

```csharp theme={"theme":{"light":"github-light","dark":"github-dark"}}
IDingTalkClient client = new DefaultDingTalkClient("https://api.dingtalk.io/topapi/attendance/getleaveapproveduration");
OapiAttendanceGetleaveapprovedurationRequest req = new OapiAttendanceGetleaveapprovedurationRequest();
req.Userid = "zhangsan";
req.FromDate = DateTime.Parse("2016-03-09 11:11:11");
req.ToDate = DateTime.Parse("2016-03-10 11:11:11");
OapiAttendanceGetleaveapprovedurationResponse rsp = client.Execute(req, access_token);
Console.WriteLine(rsp.Body);
```

## Response

### Response Body

| Name | Type | Example | Description |
| - | - | - | - |
| result | ApproveDurationForTopVo | | The returned result. |
| duration\_in\_minutes | Number | 0 | The leave duration, in minutes. |
| errcode | Number | 0 | The return code. |
| errmsg | String | ok | The description of the return code. |
| request\_id | String | 3ynh2gp5ndke | The request ID. |

### Response Body Example

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "errcode": 0,
  "errmsg":"ok",
  "result": {
    "duration_in_minutes": 480
  },
  "request_id": "6porp1hqkb9k"
}
```

### Error Codes

If a call to this API returns an error, find a solution based on the error message in the [Global Error Codes](https://help.dingtalk.io/open/development/server-api-error-codes-1.md) document.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.