# Export all rows matching a read-only query

> Source: https://docs.clonepartner.com/api-reference/connectors/export-connector-query/

`POST /api/connectors/{id}/query/export`

Streams every row the query yields as a CSV/JSON/NDJSON file download — no row cap and no server-side buffering. Write methods are rejected regardless of role. Cancel by aborting the request/download.

**Operation ID:** `exportConnectorQuery`

## Authentication

### Option 1

- **BearerAuth** (`http bearer`)
  API key token. Create via POST /api/api-keys. Format: `envoy_<hex>`

### Option 2

- **CookieAuth** (`apiKey`)
  Session cookie set after login + TOTP verification

## Path parameters

- `id` — `integer`, `required`
  Resource ID

## Request body

The request body is required.

### `application/json`

- Type: `object`
- Properties:
  - `method` (`string`, `required`) — Connector method to call (must be read-only)
  - `args` (`object`, `required`) — Method arguments (send without limit/top to export all rows)
    - Description: Method arguments (send without limit/top to export all rows)
    - Additional properties: allowed
  - `format` (`string`)
    - Allowed values: `csv`, `ndjson`
    - Default: `ndjson`
  - `columns` (`array<string>`) — CSV column order; defaults to the first row's keys
    - Description: CSV column order; defaults to the first row's keys
    - Items:
      - Type: `string`
  - `filename` (`string`) — Download filename (extension appended from format)

## Success responses

### 200

Streamed export file (Content-Disposition attachment). Gzip when Accept-Encoding includes gzip.

**Content type:** `text/csv`

- Type: `string`
**Content type:** `application/x-ndjson`

- Type: `string`

## Error responses

### 400

Validation error or cancelled export


### 403

Method is not read-only


### 404

Resource not found

**Content type:** `application/json`

- Reference: `Error`
  - Type: `object`
  - Properties:
    - `error` (`string`)
      - Example: `NOT_FOUND`
    - `message` (`string`)
      - Example: `Resource not found`

Example:

```json
{
  "error": "NOT_FOUND",
  "message": "Resource not found"
}
```

### 500

Export execution failed


## Examples

### cURL

```bash
curl --request POST \
  --url 'https://your-envoy.example.com/api/connectors/YOUR_ID/query/export' \
  --header 'Authorization: Bearer $API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
  "method": "string",
  "args": {}
}'
```

### JavaScript (fetch)

```javascript
const response = await fetch('https://your-envoy.example.com/api/connectors/YOUR_ID/query/export', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "method": "string",
    "args": {}
  }),
});

if (!response.ok) throw new Error(`Request failed: ${response.status}`);
const data = response.status === 204 ? null : await response.json();
console.log(data);
```
