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

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

[comment]: # ({46de83ad-0e3179d3})
### 描述

`object task.create(object/array tasks)`

此方法允许创建任务。

::: noteclassic
此方法对任何类型的用户都可用。
调用该方法的权限可在用户角色设置中撤销。
更多信息请参见 [用户角色](/manual/web_interface/frontend_sections/users/user_roles)。
:::

[comment]: # ({/46de83ad-0e3179d3})

[comment]: # ({8628e056-2574c234})
### 参数

`(object/array)` 要创建的任务。

该方法接受具有[标准任务属性](object#task-object)的任务。

请注意，“立即执行”任务只能为以下类型的监控项/发现规则创建：

-   Zabbix agent（被动）
-   简单检查
-   SNMP agent（v1/v2/v3）
-   Zabbix 内部
-   外部检查
-   数据库监控
-   HTTP agent
-   IPMI agent
-   SSH agent
-   TELNET agent
-   JMX agent
-   计算
-   依赖监控项
-   脚本
-   浏览器

如果监控项/发现规则的类型为“依赖监控项”，则其主监控项也必须是上述类型之一。

[comment]: # ({/8628e056-2574c234})

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

`(object)` 在 `taskids` 属性下返回一个包含创建的任务ID的对象。每个监控项和低级别发现规则都会创建一个任务。返回的ID顺序与传递的 `itemids` 的顺序相匹配。

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

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

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

[comment]: # ({69ebf78a-5c5fa6f1})
#### 创建任务

为一个监控项和一个低级别发现规则创建“立即执行”任务。

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

```json
{
    "jsonrpc": "2.0",
    "method": "task.create",
    "params": [
        {
            "type": 6,
            "request": {
                "itemid": "10092"
            }
        },
        {
            "type": 6,
            "request": {
                "itemid": "10093"
            }
        }
    ],
    "id": 1
}
```

响应：

```json
{
    "jsonrpc": "2.0",
    "result": {
        "taskids": [
            "1",
            "2"
        ]
    },
    "id": 1
}
```

为两个 proxy 创建“刷新 proxy 配置”任务。

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

```json
{
    "jsonrpc": "2.0",
    "method": "task.create",
    "params": [
        {
            "type": 2,
            "request": {
                "proxyids": ["10459", "10460"]
            }
        }
    ],
    "id": 1
}
```

响应：

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

创建“诊断信息”任务。

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

```json
{
    "jsonrpc": "2.0",
    "method": "task.create",
    "params": [
        {
            "type": 1,
            "request": {
                "alerting": {
                    "stats": [
                        "alerts"
                    ],
                    "top": {
                        "media.alerts": 10
                    }
                },
                "lld": {
                    "stats": "extend",
                    "top": {
                        "values": 5
                    }
                }
            },
            "proxyid": 0
        }
    ],
    "id": 1
}
```

响应：

```json
{
    "jsonrpc": "2.0",
    "result": {
        "taskids": [
            "3"
        ]
    },
    "id": 1
}
```

[comment]: # ({/69ebf78a-5c5fa6f1})

[comment]: # ({58f08e8d-d87c906b})
### 另请参阅

-   [任务](/manual/api/reference/task/object)
-   ['立即执行' 请求对象](/manual/api/reference/task/object#execute-now-request-object)
-   ['刷新 proxy 配置' 请求对象](/manual/api/reference/task/object#refresh-proxy-configuration-request-object)
-   ['诊断信息' 请求对象](/manual/api/reference/task/object#diagnostic-information-request-object)

[comment]: # ({/58f08e8d-d87c906b})

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

CTask::create() 在 *ui/include/classes/api/services/CTask.php*.

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