[comment]: # ({c28978f7-c28978f7})
# 创建

[comment]: # ({/c28978f7-c28978f7})

[comment]: # ({27465424-3cdde1b6})
### 描述

`object token.create(object/array tokens)`

此方法允许创建新的令牌。

::: noteclassic
用户角色需要 *Manage API tokens* [权限](/manual/web_interface/frontend_sections/users/user_roles#configuration)，才能为其他用户管理令牌。
:::

::: noteimportant
通过此方法创建的令牌还必须先[生成](generate)，然后才能使用。
:::

[comment]: # ({/27465424-3cdde1b6})

[comment]: # ({b3691541-b3691541})
### 参数

`(object/array)` 要创建的令牌。

此方法接受令牌带有规范的令牌属性[standard token properties](object)。

[comment]: # ({/b3691541-b3691541})

[comment]: # ({da7805eb-da7805eb})
### 返回值

`(object)` 返回一个对象其中包含在 `tokenids` 属性下创建的令牌的 ID。返回的 ID 的顺序与传递的令牌的顺序相匹配。

[comment]: # ({/da7805eb-da7805eb})

[comment]: # ({b41637d2-b41637d2})
### 示例

[comment]: # ({/b41637d2-b41637d2})

[comment]: # ({ac487158-119ef871})
#### 创建令牌

创建一个已启用且永不过期的令牌，并对 ID 为 2 的用户进行身份验证。

[请求](/manual/api#performing-requests):

```json
{
    "jsonrpc": "2.0",
    "method": "token.create",
    "params": {
        "name": "Your token",
        "userid": "2"
    },
    "id": 1
}
```

响应：

```json
{
    "jsonrpc": "2.0",
    "result": {
        "tokenids": [
            "188"
        ]
    },
    "id": 1
}
```

创建一个已禁用且于 2021 年 1 月 21 日过期的令牌。此令牌将对当前用户进行身份验证。

[请求](/manual/api#performing-requests):

```json
{
    "jsonrpc": "2.0",
    "method": "token.create",
    "params": {
        "name": "Your token",
        "status": "1",
        "expires_at": "1611238072"
    },
    "id": 1
}
```

响应：

```json
{
    "jsonrpc": "2.0",
    "result": {
        "tokenids": [
            "189"
        ]
    },
    "id": 1
}
```

[comment]: # ({/ac487158-119ef871})

[comment]: # ({5c90c156-5c90c156})
### 来源

*ui/include/classes/api/services/CToken.php* 中的 CToken::create()。

[comment]: # ({/5c90c156-5c90c156})
