> This page is for API.

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.eon.io/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.eon.io/_mcp/server.

# Run Query

POST https://%7Baccount-domain%7D.console.eon.io/api/v1/projects/{projectId}/snapshots/{snapshotId}/databases/query
Content-Type: application/json

Runs a SQL query against a database snapshot.

This method is asynchronous.
It returns a query ID that you can use to check the status of the query.
You can then use the query ID to call [Get Query Status] and [Get Query Result].

When the query is complete, the results are saved as a CSV to the location you specify in your restore account.

If the request fails, see [Troubleshooting Queries] for possible errors and how to resolve them.

[Troubleshooting Queries]: /data-protection/backup-and-protection/exploring-and-querying/query/troubleshooting-queries
[Get Query Status]: ./get-query-status
[Get Query Result]: ./get-query-result


Reference: https://docs.eon.io/api/api-reference/query-databases/run-query

## Authentication

- `Authorization` header (bearer token, required) — Bearer authentication of the form `Bearer <token>`, where token is your auth token.

## Request

### Path parameters

- `projectId` (string, required) — ID of the project that contains the database snapshot you want to retrieve. You can see your project ID in the [API Credentials](https://console.eon.io/global-management/api-credentials) page in your global management console.
- `snapshotId` (string, required) — ID of the database [snapshot](/api/api-reference/backup-management/snapshots/list-resource-snapshots) you want to query. Snapshot must belong to an RDS resource.

### Body (application/json)

This endpoint expects a QueryDBRequest.

- `databaseName` (string, required) — Name of the database to query.
- `query` (string, required) — SQL query to run against the database. Support is limited to Athena [`SELECT` queries](https://docs.aws.amazon.com/athena/latest/ug/select.html).
- `restoreAccountId` (string, required) — Eon-assigned ID of the [restore account](./list-restore-accounts).
- `destination` (QueryDBRestoreDestination, required) — Storage location to store CSV of query results to.

## Response

### 202

Querying database.

- `queryId` (string, required) — Query ID. Can be used to call [Get Query Status](./get-query-status) and [Get Query Result](./get-query-result).

## Types

### QueryDBRestoreDestination

- `s3Bucket` (S3RestoreDestination, optional) — S3 bucket.

### S3RestoreDestination

S3 bucket.

- `bucketName` (string, required) — Name of an existing bucket to restore query results to. Must be in the same region as the snapshot's vault.
- `prefix` (string, optional) — Prefix to prepend to the restore path. If omitted, query results are restored to the bucket root.

## Examples

**Request**

```json
{
  "databaseName": "postgres",
  "query": "SELECT * FROM customers LIMIT 50;",
  "restoreAccountId": "1e0b9aa3-a942-5e86-afe6-57606e952622"
}
```

**Response**

```json
{
  "queryId": "330e9e09-6cb8-52af-b532-a476f598cf94"
}
```

**SDK Code**

```python
import requests

url = "https://{account-domain}.console.eon.io/api/v1/projects/330e9e09-6cb8-52af-b532-a476f598cf94/snapshots/9888b6d9-8d8c-4c25-bcd9-7c71298eba0f/databases/query"

payload = {
    "databaseName": "postgres",
    "query": "SELECT * FROM customers LIMIT 50;",
    "restoreAccountId": "1e0b9aa3-a942-5e86-afe6-57606e952622"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://{account-domain}.console.eon.io/api/v1/projects/330e9e09-6cb8-52af-b532-a476f598cf94/snapshots/9888b6d9-8d8c-4c25-bcd9-7c71298eba0f/databases/query';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"databaseName":"postgres","query":"SELECT * FROM customers LIMIT 50;","restoreAccountId":"1e0b9aa3-a942-5e86-afe6-57606e952622"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://{account-domain}.console.eon.io/api/v1/projects/330e9e09-6cb8-52af-b532-a476f598cf94/snapshots/9888b6d9-8d8c-4c25-bcd9-7c71298eba0f/databases/query")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"databaseName\": \"postgres\",\n  \"query\": \"SELECT * FROM customers LIMIT 50;\",\n  \"restoreAccountId\": \"1e0b9aa3-a942-5e86-afe6-57606e952622\"\n}")
  .asString();
```