SQL query
curl --request POST \
--url https://{deployment}.{region}.cubecloudapp.dev/cubejs-api/v1/cubesql \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"query": "<string>",
"timezone": "<string>",
"cache": "stale-if-slow"
}
'import requests
url = "https://{deployment}.{region}.cubecloudapp.dev/cubejs-api/v1/cubesql"
payload = {
"query": "<string>",
"timezone": "<string>",
"cache": "stale-if-slow"
}
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({query: '<string>', timezone: '<string>', cache: 'stale-if-slow'})
};
fetch('https://{deployment}.{region}.cubecloudapp.dev/cubejs-api/v1/cubesql', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{deployment}.{region}.cubecloudapp.dev/cubejs-api/v1/cubesql",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'query' => '<string>',
'timezone' => '<string>',
'cache' => 'stale-if-slow'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{deployment}.{region}.cubecloudapp.dev/cubejs-api/v1/cubesql"
payload := strings.NewReader("{\n \"query\": \"<string>\",\n \"timezone\": \"<string>\",\n \"cache\": \"stale-if-slow\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://{deployment}.{region}.cubecloudapp.dev/cubejs-api/v1/cubesql")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"query\": \"<string>\",\n \"timezone\": \"<string>\",\n \"cache\": \"stale-if-slow\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{deployment}.{region}.cubecloudapp.dev/cubejs-api/v1/cubesql")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"query\": \"<string>\",\n \"timezone\": \"<string>\",\n \"cache\": \"stale-if-slow\"\n}"
response = http.request(request)
puts response.read_body{
"schema": [
{
"name": "value",
"column_type": "Int64"
}
],
"lastRefreshTime": "2025-01-13T12:00:00.000Z"
}Core Data Endpoints
SQL query
Run a SQL query against the Cube SQL API and stream the results. The response is newline-delimited JSON: the first line carries the schema (column names and types) and optionally lastRefreshTime; each subsequent line carries a data chunk with one or more result rows.
POST
/
v1
/
cubesql
SQL query
curl --request POST \
--url https://{deployment}.{region}.cubecloudapp.dev/cubejs-api/v1/cubesql \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"query": "<string>",
"timezone": "<string>",
"cache": "stale-if-slow"
}
'import requests
url = "https://{deployment}.{region}.cubecloudapp.dev/cubejs-api/v1/cubesql"
payload = {
"query": "<string>",
"timezone": "<string>",
"cache": "stale-if-slow"
}
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({query: '<string>', timezone: '<string>', cache: 'stale-if-slow'})
};
fetch('https://{deployment}.{region}.cubecloudapp.dev/cubejs-api/v1/cubesql', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{deployment}.{region}.cubecloudapp.dev/cubejs-api/v1/cubesql",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'query' => '<string>',
'timezone' => '<string>',
'cache' => 'stale-if-slow'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{deployment}.{region}.cubecloudapp.dev/cubejs-api/v1/cubesql"
payload := strings.NewReader("{\n \"query\": \"<string>\",\n \"timezone\": \"<string>\",\n \"cache\": \"stale-if-slow\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://{deployment}.{region}.cubecloudapp.dev/cubejs-api/v1/cubesql")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"query\": \"<string>\",\n \"timezone\": \"<string>\",\n \"cache\": \"stale-if-slow\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{deployment}.{region}.cubecloudapp.dev/cubejs-api/v1/cubesql")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"query\": \"<string>\",\n \"timezone\": \"<string>\",\n \"cache\": \"stale-if-slow\"\n}"
response = http.request(request)
puts response.read_body{
"schema": [
{
"name": "value",
"column_type": "Int64"
}
],
"lastRefreshTime": "2025-01-13T12:00:00.000Z"
}Authorizations
Cube API token (a JWT). Sent directly in the Authorization header, e.g. Authorization: <CUBE_API_TOKEN> (no "Bearer" prefix).
Body
application/json
The SQL query to run.
Time zone for the query in TZ database name format, e.g. America/Los_Angeles.
In-memory cache strategy (see Cache control):
stale-if-slow(default): if refresh keys are up to date, return the cached value; if expired, fetch fresh data but fall back to the stale value when the source query is slow.stale-while-revalidate: if expired, return stale data immediately and refresh the cache in the background.must-revalidate: if expired, always wait for fresh data from the source, even if slow.no-cache: skip refresh-key checks and always query the data source.
Available options:
stale-if-slow, stale-while-revalidate, must-revalidate, no-cache