# Query connector data

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

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

Executes a query against the connector. Only whitelisted methods are allowed per connector type. SQL execute is restricted to SELECT/WITH/EXPLAIN. MongoDB write methods (insert_one, update_one, delete_one, delete_many) require admin or superadmin role; update_one, delete_one and delete_many require a non-empty filter.

**Operation ID:** `queryConnector`

## 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
    - Description: Method arguments
    - Additional properties: allowed
  - `limit` (`integer`) — Max rows to return (no upper cap — in-flight queries are cancellable)
    - Description: Max rows to return (no upper cap — in-flight queries are cancellable)
    - Default: `100`
    - Minimum: 1

## Success responses

### 200

Query results

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

- Type: `object`
- Properties:
  - `data` (`array<object>`)
    - Items:
      - Type: `object`
  - `count` (`integer`)
  - `truncated` (`boolean`)
  - `mutation` (`boolean`) — True when the response is from a MongoDB write operation

## Error responses

### 400

Validation error


### 403

Method not allowed for data exploration


### 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

Query execution failed


## Examples

### cURL

```bash
curl --request POST \
  --url 'https://your-envoy.example.com/api/connectors/YOUR_ID/query' \
  --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', {
  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);
```
