<span id="下载表-csv-数据"></span>

# Download table data as CSV

```{raw} html
<div class="mo-api-page-show-toc" aria-hidden="true"></div>
```

Download a specified Catalog table's query results directly as a CSV with headers, reading at most 1,000,000 rows.

```text
POST https://api.moi.matrixorigin.cn/v5/catalog/table/download
```

<span id="调用前准备"></span>

## Before you call this API

Set `BASE_URL` to the product API prefix `https://api.moi.matrixorigin.cn/v5`; use the corresponding product API URL for a dedicated deployment.

Obtain a positive integer ID for a queryable table. Prepare a personal access token with table.query, a workspace ID, and a local destination path. `BASE_URL` includes the product prefix in the same environment; `MOI_KEY` and `WORKSPACE_ID` are product credentials and workspace ID. Example IDs and data are placeholders.

OUTPUT_FILE specifies the local destination path.

<span id="请求体"></span>

## Request body

:::::::{div} mo-api-tabs
::::::{tab-set}
:::::{tab-item} Request example

```bash
curl --fail-with-body -sS -X POST "$BASE_URL/catalog/table/download" \
  -H "X-API-Key: $MOI_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -H "Content-Type: application/json" \
  -d '{"id": 31}' \
  -o "$OUTPUT_FILE"
```

:::::
:::::{tab-item} Parameters

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer | Yes | Table ID. |

No pagination, resume, or total-row parameters. Confirm a separate export approach for data exceeding the row limit.

:::::
::::::
:::::::

<span id="成功响应"></span>

## Successful response

:::::::{div} mo-api-tabs mo-api-response-tabs
::::::{tab-set}
:::::{tab-item} Response example

```text
id,amount
1,12.50
```

:::::
:::::{tab-item} Fields

| Response item | Type | Description |
| --- | --- | --- |
| Content-Type | string | text/csv; charset=utf-8 on success. |
| Content-Disposition | string | Attachment name uses the URL-encoded table name and .csv extension. |
| Response body | bytes (byte stream) | CSV header and data rows. Inspect actual file contents after the read completes without client errors. |

Failures before streaming may return JSON business errors. Failures after bytes have been sent interrupt the connection. HTTP 200 or a partial file does not establish a complete download.

:::::
::::::
:::::::

<span id="错误响应"></span>

## Error responses

:::::::{div} mo-api-tabs mo-api-response-tabs
::::::{tab-set}
:::::{tab-item} Response example

```json
{
  "code": "ErrParamInvalid",
  "msg": "示例错误信息"
}
```

:::::
:::::{tab-item} Fields

| HTTP | code | Condition |
| --- | --- | --- |
| 400 | ErrParamInvalid | Invalid request JSON. |
| 409 | ErrReadonlySystemDatabase | Table ID is not positive. |
| 404 | ErrNotFound | Business read confirms the target table does not exist. |

For identity, permission, and dependency failures, use actual code, msg, and diagnostic fields. Error wording may vary by language.

:::::
::::::
:::::::
