> ## 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.

# Query Shift History

> Call this API to query shift history by shift ID and version, including the shift name, shift settings, clock-in times, and break times.

Call this API to query shift history by shift ID and version. The response includes the shift name, shift settings, clock-in times, and break times.

## Request

| **Basic information** | |
| - | - |
| HTTP URL | [https://api.dingtalk.io/topapi/attendance/shift/history/query](https://api.dingtalk.io/topapi/attendance/shift/history/query) |
| HTTP Method | POST |
| Supported app types | appType-Internal app |
| Permissions | permission-qyapi\_attendance\_group\_read-Attendance group query permission |

### Query Parameters

| Name | Type | Required | Example | Description |
| - | - | - | - | - |
| access\_token | String | Yes | 73e9xxx | The app credential used to call this API. Obtain it by calling the [Get the access\_token of an Internal App](https://help.dingtalk.io/open/development/obtain-orgapp-token) API. |

### Request Body

| Name | Type | Required | Example | Description |
| - | - | - | - | - |
| op\_user\_id | String | Yes | user123 | The userId of the operator. |
| shift\_id | Number | Yes | 628380875 | The shift ID. Obtain the id value by calling the [Get Shift Summaries](https://help.dingtalk.io/open/development/enterprise-shift-query-in-batches.md) API. |
| version | Number | Yes | 624190327 | The shift version. Obtain the shift\_version value by calling the [Batch Query User Scheduling Information](https://help.dingtalk.io/open/development/query-batch-scheduling-information.md) API. |

### Request Example

```curl theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -X POST "https://api.dingtalk.io/topapi/attendance/shift/history/query" \
-H 'Content-Type:application/x-www-form-urlencoded;charset=utf-8' \
-d 'access_token=e56f7xxxxeb7ef1' \
-d 'op_user_id=dd_dd' \
-d 'shift_id=2445' \
-d 'version=222'
```

Java

```java theme={"theme":{"light":"github-light","dark":"github-dark"}}
DingTalkClient client = new DefaultDingTalkClient("https://api.dingtalk.io/topapi/attendance/shift/history/query");
OapiAttendanceShiftHistoryQueryRequest req = new OapiAttendanceShiftHistoryQueryRequest();
req.setOpUserId("user456");
req.setShiftId(715390132L);
req.setVersion(624190327L);
OapiAttendanceShiftHistoryQueryResponse 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.OapiAttendanceShiftHistoryQueryRequest("https://api.dingtalk.io/topapi/attendance/shift/history/query")

req.op_user_id="dd_dd"
req.shift_id=2445
req.version=222
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 OapiAttendanceShiftHistoryQueryRequest;
$req->setOpUserId("dd_dd");
$req->setShiftId("2445");
$req->setVersion("222");
$resp = $c->execute($req, $access_token, "https://api.dingtalk.io/topapi/attendance/shift/history/query");
```

C#

```csharp theme={"theme":{"light":"github-light","dark":"github-dark"}}
IDingTalkClient client = new DefaultDingTalkClient("https://api.dingtalk.io/topapi/attendance/shift/history/query");
OapiAttendanceShiftHistoryQueryRequest req = new OapiAttendanceShiftHistoryQueryRequest();
req.OpUserId = "dd_dd";
req.ShiftId = 2445L;
req.Version = 222L;
OapiAttendanceShiftHistoryQueryResponse rsp = client.Execute(req, access_token);
Console.WriteLine(rsp.Body);
```

## Response

### Response Body

| Name | Type | Example | Description |
| - | - | - | - |
| result | TopShiftVo | | The query result. |
| shift\_group\_name | String | Regular day shift | The shift group name. |
| corp\_id | String | dinge87fxxx | The organization ID (corpId). |
| shift\_setting | TopShiftSettingVo | | The shift settings. |
| shift\_id | Number | 628380875 | The shift ID. |
| gmt\_modified | Date | 2021-01-14 14:21:03 | The time when the shift was last modified. |
| corp\_id | String | dinge87fxxx | The organization ID (corpId). |
| is\_deleted | String | N | The deletion flag. |
| work\_time\_minutes | Number | 480 | The work duration, in minutes. A value of -1 indicates that this feature is disabled. |
| id | Number | 350530359 | The shift settings ID. Currently not used. |
| attend\_days | String | 21 | The number of attendance days for this shift. |
| gmt\_create | Date | 2021-01-14 14:18:08 | The creation time. |
| name | String | Regular day shift | The shift name. |
| id | Number | 241120079 | The shift ID. |
| sections | TopSectionVo\[] | | The clock-in sections. |
| punches | TopPunchVo\[] | | The clock-in points. |
| check\_type | String | OnDuty | The clock-in type:   - **OnDuty**: Clock in - **OffDuty**: Clock out |
| end\_min | Number | 1 | The latest allowed delay for clock-in, in minutes. |
| across | Number | 0 | Whether the shift spans to the next day:   - **0**: Does not span to the next day - **1**: Spans to the next day |
| check\_time | Date | 1970-01-01 09:00:00 | The clock-in time. |
| permit\_minutes | Number | 60 | The allowed duration for late arrival or early leave. |
| free\_check | Boolean | false | Whether clock-in is exempt:   - **true**: Clock-in not required - **false**: Clock-in required |
| id | Number | 376955859 | The clock-in point ID. Currently not used. |
| begin\_min | Number | demo | The earliest allowed advance for clock-in, in minutes. |
| work\_time\_minutes | Number | 480 | The work duration, in minutes. |
| rests | TopRestVo\[] | | The break sections. |
| check\_type | String | OnDuty | The break type:   - **OnDuty**: Break start - **OffDuty**: Break end |
| across | Number | 0 | Whether the break spans to the next day, meaning the break time falls on the following day:   - **0**: Does not span to the next day - **1**: Spans to the next day |
| check\_time | Date | 1970-01-01 12:00:00 | The break time. |
| id | Number | 376955861 | The break point ID. |
| id | Number | 22979360 | The clock-in section ID. Each clock-in and clock-out pair forms one section. A shift can have multiple sections. |
| shift\_group\_id | Number | 22979 | The shift group ID. |
| success | Boolean | true | Whether the call succeeded.   - **true**: Success - **false**: Failed |
| errcode | Number | 0 | The return code. |
| errmsg | String | ok | The description of the return code. |
| request\_id | String | q3ef3y3sogkd | The request ID. |

### Response Body Example

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "errcode": 0,
  "errmsg":"ok",
  "result": {
    "corp_id": "dinge87fxxx",
    "id": 628380875,
    "name": "Regular day shift",
    "sections": [
      {
        "id": 350530359,
        "punches": [
          {
            "across": 0,
            "begin_min": 1,
            "check_time": "1970-01-01 09:00:00",
            "check_type": "OnDuty",
            "end_min": 1,
            "free_check": false,
            "id": 376955859,
            "permit_minutes": 60
          },
          {
            "across": 0,
            "begin_min": 1,
            "check_time": "1970-01-01 18:00:00",
            "check_type": "OffDuty",
            "end_min": 1,
            "free_check": false,
            "id": 376955860,
            "permit_minutes": 15
          }
        ],
        "rests": [
          {
            "across": 0,
            "check_time": "1970-01-01 12:00:00",
            "check_type": "OnDuty",
            "id": 376955861
          },
          {
            "across": 0,
            "check_time": "1970-01-01 13:00:00",
            "check_type": "OffDuty",
            "id": 376955862
          }
        ]
      }
    ],
    "shift_setting": {
      "corp_id": "dinge87fxxx",
      "gmt_create": "2021-01-14 14:18:08",
      "gmt_modified": "2021-01-14 14:21:03",
      "id": 624190327,
      "is_deleted": "N",
      "shift_id": 628380875,
      "work_time_minutes": 480
    }
  },
  "success": true,
  "request_id": "q3ef3y3sogkd"
}
```

### Error Codes

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


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