# Subscribe to a calendar

Call this interface to subscribe to the specified calendar with the current identity (application or user).

**Notice**：- The current identity is determined by the Token type of Header Authorization. tenant_access_token stands for the application identity while user_access_token stands for the user identity.
- If you are calling this interface in application identity, ensure that the application has opened [bot capability](https://open.feishu.cn/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-enable-bot-ability).
- You can only subscribe to calendars with the following attributes. You can call the [query calendar information](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/calendar-v4/calendar/get) interface to view the attributes of the specified calendar.
	- Calendar type is shared or primary.
	- Calendar permissions is public or show_only_free_busy.
- Not permitted to subscribe to the robot's primary calendar.
- The maximum number of calendars that the current identity can subscribe to is 1000.

## Request

Facts | &nbsp;
---|---
HTTP URL | https://open.feishu.cn/open-apis/calendar/v4/calendars/:calendar_id/subscribe
HTTP Method | POST
Rate Limit | [1000 per minute & 50 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.**<br>Enable any scope from the list | Update calendar and event information(calendar:calendar)<br>Subscribe to and unsubscribe from calendar(calendar:calendar:subscribe)

### Request header

Parameter | Type | Required | Description
---|---|---|---
Authorization | string | Yes | `tenant_access_token`<br>or<br>`user_access_token`<br>**Value format**: "Bearer `access_token`"<br>**Example value**: "Bearer u-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)

### Path parameters

Parameter | Type | Description
---|---|---
calendar_id | string | Calendar ID.<br>The calendar ID will be returned when creating a shared calendar. You also can call the following interfaces to get the ID of a certain calendar.<br>- [Query Primary Calendar Information](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/calendar-v4/calendar/primary)<br>- [Query Calendar List](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/calendar-v4/calendar/list)<br>- [Search Calendar](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/calendar-v4/calendar/search)<br>**Example value**: "feishu.cn_xxxxxxxxxx@group.calendar.feishu.cn"

## Response

### Response body

Parameter | Type | Description
---|---|---
code | int | Error codes, fail if not zero
msg | string | Error descriptions
data | \- | \-
calendar | calendar | Subscribed calendar entity.
calendar_id | string | Calendar ID. You can subsequently use this ID to query, update or delete calendar information. For details, see [Calendar-related IDs](https://open.feishu.cn/document/ukTMukTMukTM/uETM3YjLxEzN24SMxcjN#f066a96c).
summary | string | Calendar title.
description | string | Calendar description.
permissions | string | Calendar visibility range.<br>**Optional values are**:<br>- private：Private.<br>- show_only_free_busy：Only availability information is displayed.<br>- public：Public. Event details are visible to other people.
color | int | Calendar color, represented by the int32 value of color RGB. When displayed on the client, it will map to the color on the palette that is closest. This field is only effective for the current identity.
type | string | Calendar type.<br>**Optional values are**:<br>- unknown：Unknown type<br>- primary：Primary calendar of the user or app<br>- shared：Shared calendar created by the user or app<br>- google：Google calendar connected to the user<br>- resource：Room calendar<br>- exchange：Exchange calendar connected to the user
summary_alias | string | Calendar alias, which only applies to the current identity.
is_deleted | boolean | Whether the calendar has been marked as deleted for the current identity.
is_third_party | boolean | Whether the calendar is owned by a third party. Third-party calendars and events are read-only.
role | string | Current identity's access to the calendar.<br>**Optional values are**:<br>- unknown：Unknown access.<br>- free_busy_reader：Guest. A guest can only view availability information.<br>- reader：Subscriber. A subscriber can view all event details.<br>- writer：Editor. An editor can create and modify events.<br>- owner：Administrator. An administrator can manage calendars and share settings.

### Response body example
```json
{
    "code": 0,
    "msg": "success",
    "data": {
        "calendar": {
            "calendar_id": "feishu.cn_xxxxxxxxxx@group.calendar.feishu.cn",
            "summary": "Test calendar",
            "description": "Create a calendar by calling an open API",
            "permissions": "private",
            "color": -1,
            "type": "shared",
            "summary_alias": "Calendar alias",
            "is_deleted": false,
            "is_third_party": false,
            "role": "owner"
        }
    }
}
```

### Error code

HTTP status code | Error code | Description | Troubleshooting suggestions
---|---|---|---
400 | 190002 | invalid parameters in request | Invalid request parameters. Troubleshooting suggestions are as follows:<br>- Confirm that the field name and parameter type of the request parameter are correct.<br>- Confirm that the permissions for the corresponding resource have been applied for.<br>- Confirm that the corresponding resource has not been deleted.
500 | 190003 | internal service error | Internal service error, please contact [Technical Support](https://applink.feishu.cn/TLJpeNdW).
429 | 190004 | method rate limited | Method frequency limit. It is recommended to try again later and reduce the request QPS appropriately.
429 | 190005 | app rate limited | Frequency limiting is applied. We recommend that you try again later and reduce the request QPS appropriately.
403 | 190006 | wrong unit for app tenant | Request error, check whether the App ID and App Secret are correct. If the problem still cannot be solved, please consult [Technical Support](https://applink.feishu.cn/TLJpeNdW).
404 | 190007 | app bot_id not found | The bot_id of the application is not found. You need to make sure that the application has enabled [bot capability](https://open.feishu.cn/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-enable-bot-ability). If the problem is still not solved, please contact [technical support](https://applink.feishu.cn/TLJpeNdW).
429 | 190010 | current operation rate limited | The current operation is limited, usually because concurrent preemption of public resources fails. You can appropriately reduce the frequency of the current operation and try again.
400 | 190014 | invalid request parameters. check details for more info. | Invalid request parameters. Please check the details for more information.
404 | 191000 | calendar not found | Calendar not found. You need to check and change to the correct calendar ID.
400 | 191001 | invalid calendar_id | The calendar_id is invalid. You need to check and change it to the correct calendar ID.
403 | 191002 | no calendar access_role | The current identity does not have permission to access the calendar. If you want to query a calendar, you need to ensure that the current identity has permission to access the calendar.
403 | 191003 | calendar is deleted | The calendar has been deleted. You need to check and change to the correct calendar ID.
403 | 191004 | invalid calendar type | The calendar type is incorrect. You can call the [query calendar information](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/calendar-v4/calendar/get) interface to obtain the calendar type information, and then ensure that the calendar type is applicable to the current interface.
400 | 191005 | subscribe calendars count rich limit | The maximum number of subscribed calendars has been reached (the maximum number of calendars that can be subscribed to by the same identity is 1000). It is recommended that you unsubscribe from other calendars that are no longer used and try again.
400 | 191006 | subscribe target calendar is not allowed | - Not permitted to subscribe to the robot's primary calendar.<br>- Subscribing to calendars of other tenants or private calendars is not allowed. You can call the [query calendar information](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/calendar-v4/calendar/get) interface to obtain information such as the calendar's public scope, type, and access rights, and ensure that the calendar passed in is applicable to the current interface.
404 | 195100 | user is dismiss or not exist in the tenant | The current identity or specified user has resigned or is no longer in the tenant. Please check and change to the correct identity to call the interface.

For more error code information, see [General error codes](https://open.feishu.cn/document/ukTMukTMukTM/ugjM14COyUjL4ITN).

