# Create card entity

Create a card entity based on the card JSON code or the cardkit tool.

## Use restrictions
- This interface only supports the [card JSON 2.0 structure](https://open.feishu.cn/document/uAjLw4CM/ukzMukzMukzM/feishu-cards/card-json-v2-structure) or the [new version cards](https://open.feishu.cn/document/uAjLw4CM/ukzMukzMukzM/feishu-cards/feishu-card-cardkit/cardkit-upgraded-version-card-release-notes) built with the cardkit tool.
- When calling this interface, it is not supported to set the card to exclusive card mode. That is, it is not supported to set the `update_multi` attribute in the card JSON data to `false`.
- The valid period of the card entity is 14 days. That is, after 14 days of creating the card entity, you will not be able to call the relevant interface to operate the card.
- A card entity can only be sent once.

## Request

Facts | &nbsp;
---|---
HTTP URL | https://open.feishu.cn/open-apis/cardkit/v1/cards
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.** | Create and update card(cardkit:card:write)

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

### Request body

Parameter | Type | Required | Description
---|---|---|---
type | string | Yes | Card types. Optional values:<br>- `card_json`: Cards constructed from card JSON code<br>- `template`: Card templates built with the [card construction tool](https://open.feishu.cn/cardkit?from=open_docs)<br>**Example value**: "card_json"<br>**Data validation rules**:<br>- Length range: `1` ～ `50` characters
data | string | Yes | Card data. It must be consistent with the type specified by `type`:<br>- If `type` is `card_json`, then card JSON code should be passed here, and ensure it is escaped as a string. Only the [card JSON 2.0 structure](https://open.feishu.cn/document/uAjLw4CM/ukzMukzMukzM/feishu-cards/card-json-v2-structure) is supported, meaning you must declare `schema` as `2.0`.<br>- If `type` is `template`, then card template data should be passed here, and ensure it is escaped as a string. Only the new version cards are supported. In the construction tool, there should be a "New Version" label next to the card name.<br>**Example value**: "Please refer to the request body example below"<br>**Data validation rules**:<br>- Length range: `1` ～ `3000000` characters

### Request body example
```json
{  // When type is card_json
  "type": "card_json",
  "data": "{\"schema\":\"2.0\",\"header\":{\"title\":{\"content\":\"Project Progress Update Reminder\",\"tag\":\"plain_text\"}},\"config\":{\"streaming_mode\":true,\"summary\":{\"content\":\"\"},\"streaming_config\":{\"print_frequency_ms\":{\"default\":70,\"android\":70,\"ios\":70,\"pc\":70},\"print_step\":{\"default\":1,\"android\":1,\"ios\":1,\"pc\":1},\"print_strategy\":\"fast\"}},\"body\":{\"elements\":[{\"tag\":\"markdown\",\"content\":\"As of today, the project completion rate has reached 80%\",\"element_id\":\"markdown_1\"}]}}"
}

{  // When type is template
  "type": "template",
  "data": "{\"template_id\":\"AAqIi1B8abcef\",\"template_version_name\":\"1.0.0\",\"template_variable\":{\"open_id\":\"ou_5c6d1637498e704f541095bba3dabcef\"}}}"
}
```

## Response

### Response body

Parameter | Type | Description
---|---|---
code | int | Error codes, fail if not zero
msg | string | Error descriptions
data | \- | \-
card_id | string | Card entity ID

### Response body example
```json
{
    "code": 0,
    "msg": "success",
    "data": {
        "card_id": "7355372766134157313"
    }
}
```

### Error Codes

HTTP Status Code | Error Code | Description | Troubleshooting Suggestions
---|---|---|---
400 | 10002 | Your request contains an invalid request parameter. | Parameter error. Please check the input parameters according to the error information returned by the interface and refer to the documentation.
400 | 200860 | Card content exceeds limit. | The card size exceeds the limit. It is recommended to keep the card size within 30KB.
400 | 300301 | Duplicate element_id in card component. | The ID (element_id) of the card internal component is duplicated. Please check and modify.
400 | 300302 | update_multi property is false | In streaming update mode, the global card property update_multi must be set to true.
400 | 300303 | Only schema 2.0 is supported | This interface only supports Schema v2.0 structure. For details, refer to [Card JSON 2.0 Structure](https://open.feishu.cn/document/uAjLw4CM/ukzMukzMukzM/feishu-cards/card-json-v2-structure).
400 | 200220 | Failed to generate card content | Failed to generate card content. Please check if the card JSON format is incorrect.
400 | 300305 | The number of card components exceeds 200 | Exceeding card component limit. In the card JSON 2.0 structure, a single card supports a maximum of 200 elements (such as text elements with the tag `plain_text`) or components. Please ensure that the total number of components and elements does not exceed 200.
400 | 300307 | The card DSL is empty | The card JSON data is empty. Please check and modify.

