# Download execution result

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

Download a CSV file of SQL query results that were successfully executed by the current identity.

```text
POST https://moi.matrixorigin.cn/newmoi/query/result/download
```

## Preparation before calling

First [query the execution status](get-execution-status.md), confirm that the status is `success` and obtain the result ID (`statement_id`). The response body is a CSV file, not JSON.


## Request body

::::{div} mo-api-split
:::{div} mo-api-split-main

```{raw} html
<dl class="mo-api-fields">
  <div class="mo-api-field"><dt><code>statement_id</code><span class="mo-api-field__type">string</span><span class="mo-api-field__required">Required</span></dt><dd>The result ID of a successful query execution.</dd></div>
</dl>
```

:::
:::{div} mo-api-split-aside

```{raw} html
<p class="mo-api-example-label">Request example</p>
```

```bash
curl -X POST "https://moi.matrixorigin.cn/newmoi/query/result/download" \
  -H "X-API-Key: $AI_STUDIO_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -H 'Content-Type: application/json' \
  -d "{\"statement_id\":\"$STATEMENT_ID\"}" \
  --output result.csv
```

:::
::::

## Successful response

On success, a CSV file is returned, which the example command saves as `result.csv`. For example, after querying the order number, customer name and amount, the download content is as follows:

```text
order_id,customer_name,amount
1001,王小明,128.50
1002,李华,89.00
1003,Chen Wei,256.00
```

The response header contains the actual file name and file size:

::::{div} mo-api-split
:::{div} mo-api-split-main

```{raw} html
<dl class="mo-api-fields">

</dl>
```

:::
:::{div} mo-api-split-aside

```{raw} html
<p class="mo-api-example-label">Successful response example</p>
```

```json
{}
```

:::
::::

## Error response

::::{div} mo-api-split
:::{div} mo-api-split-main

```{raw} html
<dl class="mo-api-fields">
  <div class="mo-api-field"><dt><code>code</code><span class="mo-api-field__type">string</span></dt><dd>Error code.</dd></div>
  <div class="mo-api-field"><dt><code>msg</code><span class="mo-api-field__type">string</span></dt><dd>Readable error message.</dd></div>
  <div class="mo-api-field"><dt><code>data</code><span class="mo-api-field__type">null</span></dt><dd>`null` in an error response.</dd></div>
</dl>
```

:::
:::{div} mo-api-split-aside

```{raw} html
<p class="mo-api-example-label">Error response example</p>
```

```json
{
  "code": 404,
  "message": "SQL 查询结果不存在"
}
```

:::
::::

## Follow-up operations

Use [query execution result](get-execution-result.md) when you need to read by page.
