# Batch query department operation logs

Batch query department operation logs within a specified time range
**Notice**：- Default sorting condition: Default sorting in descending order by operation time
- Only supports the operation log of querying changes in the basic fields of the department, the query function for the operation log of role field changes is yet to be launched.
**Notice**：- Time window supports a wide range of queries, limiting the query range to within 366 days. For example, to query the data from January 1, 2020 to January 1, 2023, it is recommended to divide it into two queries, namely January 1, 2020 to January 1, 2021, January 2, 2022 to January 1, 2023. It is not recommended to query large time range data

- Support to query the operation log of the batch department, limit the maximum number of query departments to 100, and when the number of query departments is greater than 100, it is recommended to query in batches

## Request

Facts | &nbsp;
---|---
HTTP URL | https://open.feishu.cn/open-apis/corehr/v2/departments/query_operation_logs
HTTP Method | POST
Rate Limit | [5 per second](https://open.feishu.cn/document/ukTMukTMukTM/uUzN04SN3QjL1cDN)
Supported app types | Custom App、Store App
Required scopes<br>**To use this API, you must have at least 1 of the listed scopes.** | Get department's activity logs(corehr:department.operation_log:read)

### Request header

Parameter | Type | Required | Description
---|---|---|---
Authorization | string | Yes | `tenant_access_token`<br>**Value format**: "Bearer `access_token`"<br>**Example value**: "Bearer t-7f1bcd13fc57d46bac21793a18e560"<br>[How to choose and get access token](https://open.feishu.cn/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-choose-which-type-of-token-to-use)
Content-Type | string | Yes | **Fixed value**: "application/json; charset=utf-8"

### Query parameters

Parameter | Type | Required | Description
---|---|---|---
page_size | int | Yes | Page size, up to 1000<br>**Example value**: 100<br>**Data validation rules**:<br>- Value range: `1` ～ `1000`
page_token | string | No | Page identifier. It is not filled in the first request, indicating traversal from the beginning; when there will be more groups, the new page_token will be returned at the same time, and the next traversal can use the page_token to get more groups<br>**Example value**: 2
department_id_type | string | No | The department ID type used in this call<br>**Example value**: people_corehr_department_id<br>**Optional values are**:<br>- open_department_id：Identify departments by open_department_id<br>- department_id：Identify departments by department_id<br>- people_corehr_department_id：Identify departments by people_corehr_department_id<br>**Default value**: `people_corehr_department_id`

### Request body

Parameter | Type | Required | Description
---|---|---|---
department_ids | string\[\] | Yes | Department ID list, ID acquisition method:<br>- Call [[Create Department]](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/corehr-v1/department/create) or [[Search Department]](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/corehr-v2/department/search)for the department interface can return the department ID.<br>- You can also get the department ID by [[Event]Create Department](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/corehr-v1/department/events/created) or [[Event]Update departments](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/corehr-v1/department/events/updated) <br>**Example value**: ["7094136522860922222"]<br>**Data validation rules**:<br>- Length range: `1` ～ `100`
start_date | string | Yes | The start date of the query, in the format "YYYY-MM-DD", without time and seconds, including the time start_date passed in, the system will query with the start time of 00:00:00 start_date<br>**Example value**: "2023-01-01"
end_date | string | Yes | The deadline for the query, in the format "YYYY-MM-DD", without time and seconds, including end_date incoming time, the system will query with the end_date 23:59:59 as the deadline. The query deadline should be greater than the start date, and the start and end date span is up to 366 days<br>**Example value**: "2024-01-01"

### Request body example
```json
{
    "department_ids": [
        "7094136522860922222"
    ],
    "start_date": "2023-01-01",
    "end_date": "2024-01-01"
}
```

## Response

### Response body

Parameter | Type | Description
---|---|---
code | int | Error codes, fail if not zero
msg | string | Error descriptions
data | \- | \-
op_logs | organization_op_log\[\] | Operation log list
object_id | string | Department ID
changes | operation_log_entity_field\[\] | Field Change List
field | string | Change field
before | string | Old value
after | string | New Value
operator | string | Employee Number,more detailed information can be obtained through the 、[[Search Employee Information]](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/corehr-v2/employee/search) interface.
operation_type | int | Operation type. The following types are available:<br>- `10`: Create department record<br>- `20`: Create/clone department version<br>- `50`: Edit department version<br>- `60`: Undo department version<br>- `70`: Disable department<br>- `80`: Enable department<br>- `90`: Delete department record<br>- `100`: Custom department sorting<br>- `110`: Update department<br>- `120`: Edit department association rules
operation_time | string | Operating time, with hours and seconds. Example value: 2023-11-15 19:25:45
effective_time | string | Operation effective date, representing the effective date of the department version being operated on. Example value: 2023-10-28
operation_reason | string | Operation reason explanation
change_reasons | string\[\] | List of reasons for adjustment
next_page_token | string | Next page token
has_more | boolean | Whether the response body has more parameters

### Response body example
```json
{
    "code": 0,
    "msg": "success",
    "data": {
        "op_logs": [
            {
                "object_id": "7094136522860922111",
                "changes": [
                    {
                        "field": "description",
                        "before": "old_description",
                        "after": "new_description"
                    }
                ],
                "operator": "001",
                "operation_type": 10,
                "operation_time": "2023-11-15 19:25:45",
                "effective_time": "2023-10-28",
                "operation_reason": "Due to personnel adjustment, the person in charge of the department was changed to so-and-so",
                "change_reasons": [
                    "Create department"
                ]
            }
        ],
        "next_page_token": "2",
        "has_more": true
    }
}
```

### Error code

HTTP status code | Error code | Description | Troubleshooting suggestions
---|---|---|---
400 | 1160101 | date interval exceeds 366 | The start and end date range is within the specified value of 366 days.

