# Query the automation task list

Query the automated tasks that can be read in the current workspace. The results support filtering by agent, status, triggering method and keywords.

```text
GET https://moi.matrixorigin.cn/newmoi/workspaces/{workspace_id}/agent-automation-tasks
```

## Preparation before calling

Prepare a personal access token and target workspace ID that has access to the target workspace.

The example below uses:

- `$AI_STUDIO_API_KEY`: The actual personal access token, passed through the `X-API-Key` Header.
- `$WORKSPACE_ID`: The workspace ID to be queried, passed through the `X-Workspace-ID` Header, and as `workspace_id` in the path.

## Request example

```bash
curl "https://moi.matrixorigin.cn/newmoi/workspaces/$WORKSPACE_ID/agent-automation-tasks?status=active&limit=20&offset=0" \
  -H "X-API-Key: $AI_STUDIO_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID"
```

## Path parameters

| Parameters | Type | Is it required | Description |
| --- | --- | --- | --- |
| `workspace_id` | string | Yes | Workspace ID. |

## Query parameters

When `limit` or `offset` is not provided, the service returns 50 records by default and starts from record 0; the maximum value for `limit` is 200.

| Parameters | Type | Is it required | Description |
| --- | --- | --- | --- |
| `agent_id` | string | No | Filter by one or more agent IDs. |
| `agent_workspace_id` | string | No | The workspace to which the agent belongs. |
| `status` | string | No | Filter by task status. |
| `trigger_mode` | string | No | Filter by trigger, such as `cron`, `api`, or `callback`. |
| `query` | string | No | Search by task information. |
| `limit` | integer | No | Return the quantity. |
| `offset` | integer | No | Returns the starting position of the list. |

## Successful response

Returns `200` on success. `data.items` is the task list, `data.total` is the total number of matches; when the agent associated with the task is still readable, `agent_summary` is also returned.

```json
{
  "code": 0,
  "data": {
    "items": [
      {
        "id": "task_01",
        "workspace_id": "ws_01",
        "name": "每日摘要",
        "agent_id": "agent_01",
        "trigger": {
          "mode": "cron"
        },
        "status": "active",
        "version": 1,
        "agent_summary": {
          "id": "agent_01",
          "workspace_id": "ws_01",
          "name": "摘要助手",
          "status": "active"
        }
      }
    ],
    "total": 1,
    "limit": 50,
    "offset": 0
  }
}
```

The response fields are as follows.

| Field | Type | Description |
| --- | --- | --- |
| `code` | integer | `0` on success. |
| `data.items` | array | Readable automation tasks. |
| `data.items[].id` | string | Task, workspace, and target agent identifiers. |
| `data.items[].workspace_id` | string | Task, workspace, and target agent identifiers. |
| `data.items[].agent_id` | string | Task, workspace, and target agent identifiers. |
| `data.items[].name` | string | Task name, trigger configuration, status and version. |
| `data.items[].trigger` | object | Task name, trigger configuration, status and version. |
| `data.items[].status` | string | Task name, trigger configuration, status and version. |
| `data.items[].version` | integer | Task name, trigger configuration, status and version. |
| `data.items[].agent_summary` | object | Summary of the target agent returned when it can be read. |
| `data.total` | integer | Total number of matches, current page size, and offset. |
| `data.limit` | integer | Total number of matches, current page size, and offset. |
| `data.offset` | integer | Total number of matches, current page size, and offset. |

`[]` after a type denotes an array. `[]` in a field path denotes each item in an array.

## Error response

```json
{
  "code": 2,
  "message": "<错误信息>"
}
```

### Common HTTP errors

```{list-table}
:header-rows: 1
:widths: 12 22 32 34

* - HTTP status code
  - error code
  - Common causes
  - Recommended actions
* - `400`
  - `2`（`INVALID_ARGUMENT`）
  - `agent_id`, `agent_workspace_id` or other filter parameters are invalid.
  - Check query parameters.
* - `401`
  - `6`（`UNAUTHENTICATED`）
  - Lack of valid identity credentials.
  - Check API Key.
* - `403`
  - `5`（`PERMISSION_DENIED`）
  - The current identity does not have permission to read the associated agent.
  - Check workspace and agent authorizations.
* - `503`
  - `15`（`UNAVAILABLE`）
  - Automation task service, permission filtering or agent summary projection dependencies are not available.
  - Try again later.
```

## Follow-up operations

Save the `id` of the target task, and then [Query automation task details](get-task.md).
