Skip to main content

Query data via API

This guide shows you how to query your metrics and dimensions programmatically. You can either execute queries and get results as JSON, or retrieve the generated SQL to run elsewhere. For background on why this matters, see Open Semantic Layer.

How it works

You specify which dimensions and metrics you want. Holistics executes the query against your data warehouse and returns the aggregated results.

A diagram showing the flow of querying data via API from an external tool. An external app sends an API request with a query to Holistics, which returns the data and generated SQL

The API handles all the complexity: joining tables, applying aggregations, respecting relationships, and enforcing permissions. Your external application just receives clean, governed data.

Quick start

1. Get your API key

Go to User Settings in Holistics and generate an API key. You'll include this key in every API request using the X-Holistics-Key header.

2. Find your dataset ID

Your metrics and dimensions are organized in datasets. To query them, you'll need the dataset ID.

Option A: From the URL

Navigate to your dataset in Holistics. The ID is in the URL:

https://secure.holistics.io/data_sets/12345/explore
^^^^^
Dataset ID

Option B: Via API

List all datasets you have access to:

GET /api/v2/data_sets

3. Build and send your query

Build a query specifying the dimensions and metrics you want, then POST it to one of two endpoints:

EndpointReturns
/data_sets/{id}/submit_queryExecutes the query and returns data as JSON
/data_sets/{id}/generate_sqlReturns the generated SQL

Both endpoints accept the same request body:

{
"query": {
"dimensions": [{"field": "model_name.field_name"}],
"metrics": [{"field": "metric_name"}],
"filters": [
{
"field": "model_name.field_name",
"operator": "operator_name",
"values": [...]
}
]
}
}
  • dimensions: Fields to group by (e.g., countries.name, products.category)
  • metrics: Aggregated measures to calculate (e.g., gmv, order_count)
  • filters: Apply filter to your query (e.g., countries.continent_name is Asia)
Example: curl
curl -X POST \
-H "X-Holistics-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"query": {
"dimensions": [{"field": "ecommerce_countries.name"}],
"metrics": [{"field": "gmv"}]
}
}' \
https://secure.holistics.io/api/v2/data_sets/12345/submit_query
Example: Python
import requests

response = requests.post(
"https://secure.holistics.io/api/v2/data_sets/12345/submit_query",
headers={
"X-Holistics-Key": "YOUR_API_KEY",
"Content-Type": "application/json"
},
json={
"query": {
"dimensions": [{"field": "ecommerce_countries.name"}],
"metrics": [{"field": "gmv"}]
}
}
)
response.raise_for_status() # Raises an HTTPError for bad responses (4xx or 5xx)

data = response.json()

4. Get results

The response format depends on which endpoint you called.

submit_query response

Returns the query results as JSON:

api-return-result.png
{
"fields": ["Country Name", "GMV (Gross Merchandise Value)"],
"values": [
["United States", "1341997"],
["India", "1181929"],
["Australia", "1241734"]
],
"meta": {"page": 1, "page_size": -1, "num_rows": 10}
}

generate_sql response

Returns the generated SQL from the API call. Use this to audit query logic, debug joins, or run the SQL directly in your data warehouse.

api-generated-sql.png
{
"sql": "SELECT \"ecommerce_countries\".\"name\", SUM(\"order_items\".\"quantity\" * \"order_items\".\"price\") AS \"gmv\" FROM ..."
}

API reference

Endpoints

EndpointMethodDescription
/data_setsGETList available datasets
/data_sets/{id}GETGet available dimensions and metrics
/data_sets/{id}/submit_queryPOSTQuery data and return results
/data_sets/{id}/generate_sqlPOSTGet generated SQL without executing

Query object

FieldTypeDescription
dimensionsarrayFields to group by: [{"field": "model.field_name"}]
metricsarrayMeasures to calculate: [{"field": "metric_name"}]
filtersarrayConditions to filter data
limitnumberMaximum rows to return

Query examples

Basic query

Query GMV by country:

{
"query": {
"dimensions": [{"field": "countries.name"}],
"metrics": [{"field": "gmv"}]
}
}

Multiple dimensions

Break down by country and product category:

{
"query": {
"dimensions": [
{"field": "countries.name"},
{"field": "products.category"}
],
"metrics": [
{"field": "gmv"},
{"field": "order_count"}
]
}
}

Filter by value

Only include orders from specific countries:

{
"query": {
"dimensions": [{"field": "countries.name"}],
"metrics": [{"field": "gmv"}],
"filters": [
{
"field": "countries.name",
"operator": "is",
"value": ["United States", "United Kingdom"]
}
]
}
}

Filter by date range

Query data for a specific time period:

{
"query": {
"dimensions": [{"field": "orders.created_date"}],
"metrics": [{"field": "gmv"}],
"filters": [
{
"field": "orders.created_date",
"operator": "between",
"value": ["2025-01-01", "2025-12-31"]
}
]
}
}

Limit results

Get top 10 results:

{
"query": {
"dimensions": [{"field": "products.name"}],
"metrics": [{"field": "gmv"}],
"limit": 10
}
}

Filter operators

OperatorDescriptionExample value
isEquals any of the values["USA", "UK"]
is_notNot equal to any of the values["Unknown"]
is_nullValue is null[]
not_nullValue is not null[]
greater_thanGreater than[100]
less_thanLess than[1000]
betweenBetween two values (inclusive)["2025-01-01", "2025-12-31"]
containsContains substring["phone"]
does_not_containDoes not contain substring["test"]
starts_withStarts with substring["John"]
ends_withEnds with substring[".com"]
is_trueBoolean is true[]
is_falseBoolean is false[]
lastWithin last N periods[7, "day"]
nextWithin next N periods[30, "day"]
beforeBefore a date["2025-01-01"]
afterAfter a date["2025-01-01"]
matchesMatches regex pattern["^test.*"]
matches_user_attributeMatches current user's attribute["department"]

Regional endpoints

RegionBase URL
APAChttps://secure.holistics.io/api/v2
UShttps://us.holistics.io/api/v2
EUhttps://eu.holistics.io/api/v2
Finding your region

Check the URL when you log into Holistics (secure.holistics.io is APAC, us.holistics.io is US, eu.holistics.io is EU).

Authentication

Include your API key in the X-Holistics-Key header with every request. See the Quick start examples above for curl and Python implementations.

Next steps


Let us know what you think about this document :)