---
title: "Execute Custom SQL Query"
method: POST
path: "/orcabase/api/sql"
tags: ["Data Out"]
---

# Execute Custom SQL Query

`POST /orcabase/api/sql`

Run custom SQL queries for structured data retrieval. The response returns the query results in a JSON format.

## Request body

- object
  - `shopId` string, required — The shop domain for which you are requesting data (e.g., `example.myshopify.com`).
  - `query` string, required — The SQL query string to execute. Include dynamic `@startDate` AND `@endDate` parameters in your query string, and provide specific start and end values in the request body via `period.startDate` and `period.endDate`.
  - `currency` string — The currency for data aggregation (e.g., USD, EUR). Defaults to the currency provided during user account registration.
  - `period` object, required — The date range for the query period.
    - `startDate` string, date, required — The start date for the query period (ISO 8601 format).
    - `endDate` string, date, required — The end date for the query period (ISO 8601 format).

## Response `200`

The SQL query was executed successfully, and the response contains the query results in a JSON format grouped by `channel` and `event_date`.

- object
  - `success` boolean — Indicates whether the request was successful.
  - `message` string — A success message indicating the query was executed.
  - `data` object[] — The query results as an array of objects, with dynamically generated properties that can include strings, numbers, dates, or other types.

## Other responses

- `400` — Invalid request due to missing or malformed parameters.
- `403` — Access forbidden due to missing or invalid access token.
- `429` — Rate limit exceeded. Too many requests were sent in a short period.
- `500` — Internal server error. An unexpected issue occurred on the server.

---

[API](https://skmtc.net/triplewhale/apis/triple-whale-api.md) · [All operations](https://skmtc.net/triplewhale/apis/triple-whale-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/triplewhale/triple-whale-api/revisions/96b22ac9b5a7/schema)
