# Query email tool connection

Query the email tool connection status of the current workspace. This interface does not return passwords.

```text
GET https://moi.matrixorigin.cn/newmoi/workspaces/{workspace_id}/tools/mail/{provider}/connect
```

## Before you call

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`: Target workspace ID, passed through `X-Workspace-ID` Header.

## Request example

```bash
curl "https://moi.matrixorigin.cn/newmoi/workspaces/$WORKSPACE_ID/tools/mail/qq/connect" \
  -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 | The current workspace ID. |
| `provider` | string | Yes | The mail provider to query: `qq` or `wecom`. |

## Successful response

Returns `200` on success. When the connection is not saved, the interface returns to the `disconnected` state.

```json
{
  "code": 0,
  "data": {
    "tool_id": "moi.qq.mail",
    "provider": "qq",
    "status": "disconnected",
    "requires_reconnect": false
  }
}
```

When connection is available:

```json
{
  "code": 0,
  "data": {
    "tool_id": "moi.qq.mail",
    "provider": "qq",
    "email": "user@example.com",
    "credential_ref": "cred_01",
    "status": "connected",
    "connected_at": "2026-01-02T15:04:05Z",
    "requires_reconnect": false
  }
}
```

The response fields are as follows.

| Field | Type | Description |
| --- | --- | --- |
| `code` | integer | `0` on success. |
| `data.tool_id` | string | Email built-in tool ID and provider. |
| `data.provider` | string | Email built-in tool ID and provider. |
| `data.email` | string | Saved email address; may not be returned if not connected or credentials are not available. |
| `data.status` | string | `connected`, `disconnected` or `needs_reconnect`. |
| `data.credential_ref` | string | Credential reference and connection time; not returned if not connected. |
| `data.connected_at` | string | Credential reference and connection time; not returned if not connected. |
| `data.requires_reconnect` | boolean | `true` if credentials are not available. |

## 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`）
  - `provider` or invalid workspace ID.
  - `provider` Use only `qq` or `wecom` and check the path 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 tool connection.
  - Check workspace authorization.
* - `503`
  - `15`（`UNAVAILABLE`）
  - The email connection service or authorization dependency is temporarily unavailable.
  - Try again later.
```

## Follow-up operations

When modifications are needed [Update tool](update-tool.md). When returning the list [Query tool tag](list-tool-tags.md).
