服务端 API/日历/日历管理/查询主日历日程忙闲信息
# 查询主日历日程忙闲信息

调用该接口查询指定用户的主日历忙闲信息，或者查询指定会议室的忙闲信息。

**注意事项**：如果使用应用身份调用该接口，则需要确保应用开启了[机器人能力](https://open.larksuite.com/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-enable-bot-ability)。

## 请求

基本 | &nbsp;
---|---
HTTP URL | https://open.larksuite.com/open-apis/calendar/v4/freebusy/list
HTTP Method | POST
接口频率限制 | [1000 次/分钟、50 次/秒](https://open.larksuite.com/document/ukTMukTMukTM/uUzN04SN3QjL1cDN)
支持的应用类型 | Custom App、Store App
权限要求<br>**调用该 API 所需的权限。开启其中任意一项权限即可调用**<br>开启任一权限即可 | 更新日历及日程信息(calendar:calendar)<br>读取日历忙闲信息(calendar:calendar.free_busy:read)<br>获取日历、日程及忙闲信息(calendar:calendar:readonly)
字段权限要求 | **注意事项**：该接口返回体中存在下列敏感字段，仅当开启对应的权限后才会返回；如果无需获取这些字段，则不建议申请<br>获取用户 user ID(contact:user.employee_id:readonly)

### 请求头

名称 | 类型 | 必填 | 描述
---|---|---|---
Authorization | string | 是 | `tenant_access_token`<br>或<br>`user_access_token`<br>**值格式**："Bearer `access_token`"<br>**示例值**："Bearer u-7f1bcd13fc57d46bac21793a18e560"<br>[了解更多：如何选择与获取 access token](https://open.larksuite.com/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-choose-which-type-of-token-to-use)
Content-Type | string | 是 | **固定值**："application/json; charset=utf-8"

### 查询参数

名称 | 类型 | 必填 | 描述
---|---|---|---
user_id_type | string | 否 | 用户 ID 类型<br>**示例值**：open_id<br>**可选值有**：<br>- open_id：标识一个用户在某个应用中的身份。同一个用户在不同应用中的 Open ID 不同。[了解更多：如何获取 Open ID](https://open.larksuite.com/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-obtain-openid)<br>- union_id：标识一个用户在某个应用开发商下的身份。同一用户在同一开发商下的应用中的 Union ID 是相同的，在不同开发商下的应用中的 Union ID 是不同的。通过 Union ID，应用开发商可以把同个用户在多个应用中的身份关联起来。[了解更多：如何获取 Union ID？](https://open.larksuite.com/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-obtain-union-id)<br>- user_id：标识一个用户在某个租户内的身份。同一个用户在租户 A 和租户 B 内的 User ID 是不同的。在同一个租户内，一个用户的 User ID 在所有应用（包括商店应用）中都保持一致。User ID 主要用于在不同的应用间打通用户数据。[了解更多：如何获取 User ID？](https://open.larksuite.com/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-obtain-user-id)<br>**默认值**：`open_id`<br>**当值为 `user_id`，字段权限要求**：<br>获取用户 user ID(contact:user.employee_id:readonly)

### 请求体

名称 | 类型 | 必填 | 描述
---|---|---|---
time_min | string | 是 | 查询时段开始时间，[RFC 3339](https://datatracker.ietf.org/doc/html/rfc3339) date_time 格式。<br>**注意**：time_min 与 time_max 之间的时间间隔不能大于 90 天。<br>**示例值**："2020-10-28T12:00:00+08:00"
time_max | string | 是 | 查询时段结束时间，[RFC 3339](https://datatracker.ietf.org/doc/html/rfc3339) date_time 格式。<br>**注意**：time_min 与 time_max 之间的时间间隔不能大于 90 天。<br>**示例值**："2020-12-28T12:00:00+08:00"
user_id | string | 否 | 用户 ID，需要传入与查询参数 user_id_type 相匹配的 id。例如，`user_id_type=open_id` 时，需要传入用户的 open_id。了解用户 ID 参见[用户相关的 ID 概念](https://open.larksuite.com/document/home/user-identity-introduction/introduction)。<br>**注意**：user_id 与 room_id 需要二选一传入，如果同时传入则只生效 user_id。<br>**示例值**："ou_xxxxxxxxxx"
room_id | string | 否 | 会议室 room_id。你可以调用[查询会议室列表](https://open.larksuite.com/document/uAjLw4CM/ukTMukTMukTM/reference/vc-v1/room/list)接口或者[搜索会议室](https://open.larksuite.com/document/uAjLw4CM/ukTMukTMukTM/reference/vc-v1/room/search)接口，获取相应会议室的 room_id。<br>**注意**：user_id 与 room_id 需要二选一传入，如果同时传入则只生效 user_id。<br>**示例值**："omm_xxxxxxxxxx"
include_external_calendar | boolean | 否 | 是否包含绑定的三方日历中的日程。<br>**取值**：<br>- true（默认值）：包含<br>- false：不包含<br>**示例值**：true
only_busy | boolean | 否 | 是否只查询忙碌日程信息。<br>**取值**：<br>- true（默认值）：是，查询结果不包含空闲日程。<br>- false：否，查询结果包含空闲日程。<br>**示例值**：true

### 请求体示例
```json
{
    "time_min": "2020-10-28T12:00:00+08:00",
    "time_max": "2020-12-28T12:00:00+08:00",
    "user_id": "ou_xxxxxxxxxx",
    "room_id": "omm_xxxxxxxxxx",
    "include_external_calendar": true,
    "only_busy": true
}
```

## 响应

### 响应体

名称 | 类型 | 描述
---|---|---
code | int | 错误码，非 0 表示失败
msg | string | 错误描述
data | \- | \-
freebusy_list | freebusy\[\] | 在请求的时间区间内的忙碌时间段列表。
start_time | string | 忙闲信息开始时间，[RFC 3339](https://datatracker.ietf.org/doc/html/rfc3339) date_time 格式。
end_time | string | 忙闲信息结束时间，[RFC 3339](https://datatracker.ietf.org/doc/html/rfc3339) date_time 格式。

### 响应体示例
```json
{
    "code": 0,
    "msg": "success",
    "data": {
        "freebusy_list": [
            {
                "start_time": "2020-10-28T22:30:00+08:00",
                "end_time": "2020-10-28T22:45:00+08:00"
            }
        ]
    }
}
```

### 错误码

HTTP状态码 | 错误码 | 描述 | 排查建议
---|---|---|---
400 | 190002 | invalid parameters in request | 无效的请求参数。排查建议如下：<br>- 确认请求参数的字段名称、传参类型正确。<br>- 确认已经申请了相应资源的权限。<br>- 确认相应资源未被删除。
500 | 190003 | internal service error | 内部服务错误，请咨询[技术支持](https://applink.larksuite.com/TLJpeNdW)。
429 | 190004 | method rate limited | 方法频率限制。建议稍后再试，并适当减小请求 QPS。
429 | 190005 | app rate limited | 应用频率限制。建议稍后再试，并适当减小请求 QPS。
403 | 190006 | wrong unit for app tenant | 请求错误，检查应用 App ID 和 App Secret 是否正确。如仍无法解决请咨询[技术支持](https://applink.larksuite.com/TLJpeNdW)。
404 | 190007 | app bot_id not found | 应用的 bot_id 没有找到。你需要确保应用开启了[机器人能力](https://open.larksuite.com/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-enable-bot-ability)。如仍未解决请咨询[技术支持](https://applink.larksuite.com/TLJpeNdW)。
429 | 190010 | current operation rate limited | 当前操作被限流，原因一般为公用资源并发抢占失败。你可以适当降低当前操作频率，然后重试。
404 | 195100 | user is dismiss or not exist in the tenant | 当前身份或指定用户已经离职，或者不在该租户内。请检查并改为正确的身份来调用接口。

更多错误码信息，参见[通用错误码](https://open.larksuite.com/document/ukTMukTMukTM/ugjM14COyUjL4ITN)。

