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

调用该接口获取当前身份（应用或用户）的主日历信息。

**注意事项**：**说明**

- 当前身份由 Header Authorization 的 Token 类型决定。tenant_access_token 指应用身份，user_access_token 指用户身份。
- 使用应用身份调用该接口前，需要确保该应用开启了[机器人能力](https://open.larksuite.com/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-enable-bot-ability)。
- 使用应用身份调用该接口时，查询参数 user_id_type 不能设置为 user_id。你可以选择 open_id 或者 union_id，在返回结果中，user_id 参数值会包含应用机器人对应的 open_id 或 union_id。

## 请求

基本 | &nbsp;
---|---
HTTP URL | https://open.larksuite.com/open-apis/calendar/v4/calendars/primary
HTTP Method | POST
接口频率限制 | [1000 次/分钟、50 次/秒](https://open.larksuite.com/document/ukTMukTMukTM/uUzN04SN3QjL1cDN)
支持的应用类型 | Custom App、Store App
权限要求<br>**调用该 API 所需的权限。开启其中任意一项权限即可调用**<br>开启任一权限即可 | 读取日历信息(calendar:calendar: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)

### 查询参数

名称 | 类型 | 必填 | 描述
---|---|---|---
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)

## 响应

### 响应体

名称 | 类型 | 描述
---|---|---
code | int | 错误码，非 0 表示失败
msg | string | 错误描述
data | \- | \-
calendars | user_calendar\[\] | 主日历列表。
calendar | calendar | 日历实体信息。
calendar_id | string | 日历 ID。你可以通过该 ID 查询、更新主日历信息。更多信息可参见[日历 ID 字段说明](https://open.larksuite.com/document/uAjLw4CM/ukTMukTMukTM/reference/calendar-v4/calendar/introduction)。
summary | string | 日历标题。
description | string | 日历描述。
permissions | string | 日历公开范围。<br>**可选值有**：<br>- private：私密<br>- show_only_free_busy：仅展示忙闲信息<br>- public：公开，他人可查看日程详情
color | int | 日历颜色，由颜色 RGB 值的 int32 表示。实际在客户端展示时会映射到色板上最接近的一种颜色，且该字段仅对当前身份生效。
type | string | 日历类型。<br>**可选值有**：<br>- unknown：未知类型<br>- primary：用户或应用的主日历<br>- shared：由用户或应用创建的共享日历<br>- google：用户绑定的谷歌日历<br>- resource：会议室日历<br>- exchange：用户绑定的 Exchange 日历
summary_alias | string | 日历备注名，仅对当前身份生效。
is_deleted | boolean | 对于当前身份，日历是否已经被标记为删除。
is_third_party | boolean | 当前日历是否是第三方数据。三方日历及日程只支持读，不支持写入。
role | string | 当前身份对于该日历的访问权限。<br>**可选值有**：<br>- unknown：未知权限<br>- free_busy_reader：游客，只能看到忙碌、空闲信息<br>- reader：订阅者，可查看所有日程详情<br>- writer：编辑者，可创建及修改日程<br>- owner：管理员，可管理日历及共享设置
user_id | string | 日历创建者的 User ID。了解用户不同类型的 ID，可参见[用户身份概述](https://open.larksuite.com/document/home/user-identity-introduction/introduction)。

### 响应体示例
```json
{
    "code": 0,
    "msg": "success",
    "data": {
        "calendars": [
            {
                "calendar": {
                    "calendar_id": "larksuite.com_xxxxxxxxxx@group.calendar.larksuite.com",
                    "summary": "测试日历",
                    "description": "使用开放接口创建日历",
                    "permissions": "private",
                    "color": -1,
                    "type": "shared",
                    "summary_alias": "日历备注名",
                    "is_deleted": false,
                    "is_third_party": false,
                    "role": "owner"
                },
                "user_id": "ou_xxxxxx"
            }
        ]
    }
}
```

### 错误码

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 | 191000 | calendar not found | 日历没有找到。你需要检查并改为正确的日历 ID。
400 | 191001 | invalid calendar_id | calendar_id 无效。你需要检查并改为正确的日历 ID。
403 | 191002 | no calendar access_role | 当前身份没有日历的访问权限。如需查询日历信息，则需要确保当前身份拥有该日历的访问权限。
403 | 191003 | calendar is deleted | 日历已经被删除。你需要检查并改为正确的日历 ID。
403 | 191004 | invalid calendar type | 日历类型错误。你可以调用[查询日历信息](https://open.larksuite.com/document/uAjLw4CM/ukTMukTMukTM/reference/calendar-v4/calendar/get)接口获取日历类型信息，然后确保日历类型适用于当前接口。
404 | 195100 | user is dismiss or not exist in the tenant | 当前身份或指定用户已经离职，或者不在该租户内。请检查并改为正确的身份来调用接口。

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

