Skip to main content
POST
/
analytics
/
query
Run analytics query
curl --request POST \
  --url https://api.hexclave.com/api/v1/analytics/query \
  --header 'Content-Type: application/json' \
  --data '
{
  "include_all_branches": false,
  "query": "SELECT count() AS event_count FROM events",
  "params": {
    "event_type": "$page-view"
  },
  "timeout_ms": 10000
}
'
import requests

url = "https://api.hexclave.com/api/v1/analytics/query"

payload = {
"include_all_branches": False,
"query": "SELECT count() AS event_count FROM events",
"params": { "event_type": "$page-view" },
"timeout_ms": 10000
}
headers = {"Content-Type": "application/json"}

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

print(response.text)
const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
include_all_branches: false,
query: 'SELECT count() AS event_count FROM events',
params: {event_type: '$page-view'},
timeout_ms: 10000
})
};

fetch('https://api.hexclave.com/api/v1/analytics/query', 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://api.hexclave.com/api/v1/analytics/query",
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([
'include_all_branches' => false,
'query' => 'SELECT count() AS event_count FROM events',
'params' => [
'event_type' => '$page-view'
],
'timeout_ms' => 10000
]),
CURLOPT_HTTPHEADER => [
"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://api.hexclave.com/api/v1/analytics/query"

payload := strings.NewReader("{\n \"include_all_branches\": false,\n \"query\": \"SELECT count() AS event_count FROM events\",\n \"params\": {\n \"event_type\": \"$page-view\"\n },\n \"timeout_ms\": 10000\n}")

req, _ := http.NewRequest("POST", url, payload)

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://api.hexclave.com/api/v1/analytics/query")
.header("Content-Type", "application/json")
.body("{\n \"include_all_branches\": false,\n \"query\": \"SELECT count() AS event_count FROM events\",\n \"params\": {\n \"event_type\": \"$page-view\"\n },\n \"timeout_ms\": 10000\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://api.hexclave.com/api/v1/analytics/query")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"include_all_branches\": false,\n \"query\": \"SELECT count() AS event_count FROM events\",\n \"params\": {\n \"event_type\": \"$page-view\"\n },\n \"timeout_ms\": 10000\n}"

response = http.request(request)
puts response.read_body
{
  "result": [
    {
      "event_count": 42
    }
  ],
  "query_id": "00000000-0000-0000-0000-000000000000:main:00000000-0000-0000-0000-000000000001"
}

Body

application/json
query
string
required

A read-only ClickHouse SQL query.

Example:

"SELECT count() AS event_count FROM events"

include_all_branches
boolean
default:false

Reserved for future branch-wide analytics queries. Must be false.

Example:

false

params
object

ClickHouse query parameters referenced by the query.

Example:
{ "event_type": "$page-view" }
timeout_ms
integer
default:10000

Maximum query execution time in milliseconds. The effective timeout is also capped by the project's plan.

Example:

10000

Response

200 - application/json

Successful response

result
object[]
required

Query result rows as plain JSON objects.

Example:
[{ "event_count": 42 }]
query_id
string
required

The ClickHouse query ID. Use it to fetch query timing stats.

Example:

"00000000-0000-0000-0000-000000000000:main:00000000-0000-0000-0000-000000000001"