[comment]: # ({312e3a40-312e3a40})
# role.create

[comment]: # ({/312e3a40-312e3a40})

[comment]: # ({58ce01b8-17ca7358})
### 描述

`object role.create(object/array roles)`

此方法用于 create 新角色。

::: noteclassic
此方法仅适用于 *超级管理员* 用户类型。
调用该方法的权限可以在用户角色设置中撤销。更多信息请参见
[User
roles](/manual/web_interface/frontend_sections/users/user_roles)
:::

[comment]: # ({/58ce01b8-17ca7358})

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

`(object/array)` 要创建的角色。

除了[标准角色属性](object#role)之外，该方法还接受以下参数。

|Parameter|[Type](/manual/api/reference_commentary#data-types)|Description|
|--|--|------|
|rules|array|要为该角色创建的[角色规则](object#role-rules)。|

[comment]: # ({/f7c817e8-be3f23e2})

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

`(object)` 返回一个 object，其中包含在 `roleids` 属性下列出的已创建角色的 ID。返回的 ID 顺序与传入的角色顺序一致。

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

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

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

[comment]: # ({060c032d-7e61457f})
#### 创建角色

创建一个类型为“User”的角色，并拒绝访问两个UI元素。

[执行请求](/manual/api#执行请求):


```json
{
    "jsonrpc": "2.0",
    "method": "role.create",
    "params": {
        "name": "Operator",
        "type": "1",
        "rules": {
            "ui": [
                {
                    "name": "monitoring.hosts",
                    "status": "0"
                },
                {
                    "name": "monitoring.maps",
                    "status": "0"
                }
            ]
        }
    },
    "id": 1
}
```
响应：


```json
{
    "jsonrpc": "2.0",
    "result": {
        "roleids": [
            "5"
        ]
    },
    "id": 1
}
```

[comment]: # ({/060c032d-7e61457f})

[comment]: # ({41ff46f7-c3d5b904})
### 另请参见

-   [角色规则](object#role-rules)
-   [UI 元素](object#ui-element)
-   [模块](object#module)
-   [操作](object#action)

[comment]: # ({/41ff46f7-c3d5b904})

[comment]: # ({4b30d86c-4b30d86c})
### 来源

CRole::create() 在 *ui/include/classes/api/services/CRole.php* 中。

[comment]: # ({/4b30d86c-4b30d86c})
