Query ClickHouse
Use the Superwall API to query your organization's ClickHouse-backed analytics data and find the event names and attribute keys each app sends.
The ClickHouse query API gives you direct SQL access to the same analytics data Superwall uses for charts and campaign results. Use it when you need flexible reporting, internal dashboards, or ad hoc analysis without maintaining a separate data warehouse.
Querying from the terminal or a coding agent? The Superwall CLI wraps this API: superwall query "SELECT count() FROM sw.events_rep" runs against your logged-in session, with no key handling needed.
Requests are scoped to your organization and require an organization API key with the data:read scope. Superwall provisions a read-only ClickHouse user for your organization on first use, then applies row-level policies so queries only return data for your organization's applications.
Treat data:read keys as sensitive. They can query analytics data for your organization, so create dedicated keys, store them in a secret manager, and revoke them when they are no longer needed.
Endpoint
Use either POST or GET:
| Method | Path | SQL location |
|---|---|---|
POST | https://api.superwall.com/v2/organizations/{organization_id}/query | Request body |
GET | https://api.superwall.com/v2/organizations/{organization_id}/query | query URL parameter |
POST is recommended for most queries because SQL can be long and multiline.
Authentication
- Open Settings > API Keys in the Superwall dashboard.
- Create an organization API key.
- Give the key the
data:readscope and set Project access to all projects. - Copy the token when Superwall shows it.
Pass the token as a bearer token:
Authorization: Bearer YOUR_SECRET_TOKENThe token must belong to the organization in the path. A key from another organization cannot query this endpoint.
A key restricted to some projects gets a 403 from every /query endpoint on this page, because queries read data across your whole organization.
Send a query
Set your organization ID and API key:
export SUPERWALL_ORG_ID="123"
export SUPERWALL_API_KEY="sk_..."Run a query with POST:
curl "https://api.superwall.com/v2/organizations/$SUPERWALL_ORG_ID/query" \
--request POST \
--header "Authorization: Bearer $SUPERWALL_API_KEY" \
--data-binary "SELECT count() FROM sw.events_rep"Run a query with GET:
curl --get "https://api.superwall.com/v2/organizations/$SUPERWALL_ORG_ID/query" \
--header "Authorization: Bearer $SUPERWALL_API_KEY" \
--data-urlencode "query=SELECT count() FROM sw.events_rep"The response is the raw ClickHouse HTTP response. If you do not specify a format, ClickHouse returns its default text format. Add a FORMAT clause when you need JSON:
curl "https://api.superwall.com/v2/organizations/$SUPERWALL_ORG_ID/query" \
--request POST \
--header "Authorization: Bearer $SUPERWALL_API_KEY" \
--data-binary "
SELECT
name,
count() AS events
FROM sw.events_rep
WHERE ts >= now() - INTERVAL 7 DAY
GROUP BY name
ORDER BY events DESC
LIMIT 20
FORMAT JSONEachRow
"Use ClickHouse HTTP options
The endpoint proxies ClickHouse HTTP requests after Superwall authenticates your organization API key. You can pass standard ClickHouse URL parameters, such as query, database, or default_format, through the query string:
curl --get "https://api.superwall.com/v2/organizations/$SUPERWALL_ORG_ID/query" \
--header "Authorization: Bearer $SUPERWALL_API_KEY" \
--data-urlencode "query=SELECT name, count() FROM events_rep GROUP BY name LIMIT 20" \
--data-urlencode "database=sw" \
--data-urlencode "default_format=JSONEachRow"Superwall does not expose the generated ClickHouse username and password. Authenticate to the Superwall endpoint with your bearer token instead of connecting directly to the ClickHouse cluster.
Available tables
Your read-only user can query the analytics tables Superwall exposes for customer reporting:
| Table | Use it for |
|---|---|
sw.events_rep | Raw Superwall events, including event name, metadata, properties, sandbox flag, application ID, and timestamp. |
sw.events_hr_agg | Hourly event aggregates. |
sw.events_daily_count_agg | Daily event counts per app, event name, and sandbox flag, for the last 40 days. Read the events column with uniqHLL12Merge(events). Counts are approximate, within about 1.6%. Use it to count events per day without reading sw.events_rep. See Count each event's arrivals. |
sw.demand_score_events_rep | Demand Score event data. |
open_revenue.attributed_events_by_ts_rep | Revenue and attribution events ordered by event time. |
open_revenue.attributed_events_by_experiment_rep_next | The same revenue and attribution events, keyed by campaign experiment, variant, and paywall. Use it for revenue per variant. |
open_revenue.paywall_open_events_agg | Aggregated paywall open events. |
open_revenue.sdk_events_agg | Hourly unique users per SDK event, such as session_start, paywall_open, transaction_start, and transaction_complete, broken down by campaign, paywall, placement, product, country, store, platform, and more. See Aggregated SDK events. |
open_revenue.retention_message_events_rep | Apple Retention Messaging events. Each retention_message_response row is one request from Apple, with the response Superwall sent, the product, the user's locale, and the retention message. Join it to open_revenue.attributed_events_by_ts_rep on originalTransactionId to see what happened next. |
sw.subscription_status_rep | Subscription status records. |
sw.user_attributes_rep | User attributes set through the SDK or paywall flows. |
sw.device_attributes_rep | Device attributes the SDK reports for each user, such as app version, install date, OS, and locale. One row per user and key. |
sw.user_aliases_rep | IDs that belong to the same user, such as an anonymous ID and the ID it was identified as. Each pair is stored in both directions. |
sw.applications_rep | Application metadata available in ClickHouse. |
Use ClickHouse introspection queries to inspect columns before writing a production query:
SHOW TABLES FROM sw;
SHOW TABLES FROM open_revenue;
DESCRIBE TABLE sw.events_rep;
DESCRIBE TABLE open_revenue.attributed_events_by_ts_rep;To get every table your key can read, with its columns, in one call, use the tables endpoint:
curl "https://api.superwall.com/v2/organizations/$SUPERWALL_ORG_ID/query/tables" \
--header "Authorization: Bearer $SUPERWALL_API_KEY"With the Superwall CLI, run superwall get /v2/organizations/<org-id>/query/tables. With the Superwall MCP connected, an agent finds the endpoint with the api_docs tool and calls it with get.
{
"object": "list",
"data": [
{
"database": "sw",
"name": "events_daily_count_agg",
"columns": [
{ "name": "day", "type": "Date" },
{ "name": "applicationId", "type": "UInt32" },
{ "name": "isSandbox", "type": "UInt8" },
{ "name": "name", "type": "LowCardinality(String)" },
{ "name": "events", "type": "AggregateFunction(uniqHLL12, String)" }
]
}
]
}The list only holds tables your organization's query login can read, and columns are in table order. It can be up to 5 minutes old.
Find event names and property keys
DESCRIBE TABLE shows a table's columns, but not which event names, attribute keys, or event property keys one app actually sends. The schema endpoints list them. They use the same data:read key as queries, with access to all projects, and the app must belong to the organization in the path. To browse the same lists in the dashboard, see Data Warehouse. Start with the app's event names and attribute keys:
export SUPERWALL_APP_ID="456"
curl --get "https://api.superwall.com/v2/organizations/$SUPERWALL_ORG_ID/query/schema" \
--header "Authorization: Bearer $SUPERWALL_API_KEY" \
--data-urlencode "application_id=$SUPERWALL_APP_ID"With the Superwall CLI, run superwall get /v2/organizations/<org-id>/query/schema -d application_id=<app-id>. With the Superwall MCP connected, an agent finds the endpoint with the api_docs tool and calls it with get.
The older /v2/charts/data-schema endpoints, which use the charts:read scope, still answer but are deprecated, so move to the /query/schema paths.
A trimmed response:
{
"object": "data_schema",
"user_attributes": [
{ "key": "plan", "types": ["String"], "last_seen_at": "2026-10-29T18:04:12.000Z" },
{ "key": "streak_days", "types": ["Int64", "String"], "last_seen_at": "2026-10-29T17:58:40.000Z" }
],
"device_attributes": [
{ "key": "appVersion", "types": ["String"], "last_seen_at": "2026-10-29T18:05:01.000Z" }
],
"custom_events": [
{ "name": "onboarding_complete", "last_seen_at": "2026-10-29T18:03:55.000Z", "property_count": 3 }
],
"standard_events": [
{ "name": "paywall_open", "last_seen_at": "2026-10-29T18:05:09.000Z", "property_count": 57 },
{ "name": "renewal", "last_seen_at": "2026-10-29T16:22:31.000Z", "property_count": 32 }
],
"events_truncated": false
}| Field | Contains |
|---|---|
user_attributes | Keys the app set with setUserAttributes, sorted by key. |
device_attributes | Keys the SDK reports about the device, sorted by key. |
custom_events | The app's own event names: placements it registers and events it tracks. Most recent first. |
standard_events | Superwall's events, from the SDK and from store and integration webhooks, such as renewal. Most recent first. |
events_truncated | true when the app has sent more event names than are listed. Each event list holds the 1,000 most recent names. |
Each attribute has types, every JSON type the key has arrived as, most recently seen first: String, Int64, UInt64, Double, Bool, Array, Object, or Null. More than one type means the app has sent the key with different types. Attributes and events each have last_seen_at, the time they last arrived, in ISO 8601. Each event also has property_count, how many property keys it has carried, not counting the keys the SDK adds to every event (see below).
Every schema response also has query, a SQL template for its rows, and docs_url. The template's row_params say which field of a row fills each parameter. To get SQL with every value already filled in, see Get ready-to-run SQL.
The schema endpoints cover production data only, so a name that only ever arrived from sandbox is not listed, even though sw.events_rep has it. They list names and keys and can be up to 5 minutes old. For how often each event arrived, see Count each event's arrivals. The full reference is at api.superwall.com/docs.
List an event's property keys
Pass an event name, exactly as the data schema lists it, to see the keys that event has carried:
curl --get "https://api.superwall.com/v2/organizations/$SUPERWALL_ORG_ID/query/schema/event-properties" \
--header "Authorization: Bearer $SUPERWALL_API_KEY" \
--data-urlencode "application_id=$SUPERWALL_APP_ID" \
--data-urlencode "event=paywall_open"With the CLI: superwall get /v2/organizations/<org-id>/query/schema/event-properties -d application_id=<app-id> -d event=<event-name>.
{
"object": "data_schema_event_properties",
"event": "paywall_open",
"properties": [
{ "key": "$paywall_identifier", "types": ["String"], "last_seen_at": "2026-10-29T18:05:09.000Z" },
{ "key": "$presented_by_event_name", "types": ["String"], "last_seen_at": "2026-10-29T18:05:09.000Z" }
],
"properties_truncated": false
}Each property has the same key, types, and last_seen_at as an attribute, and properties is sorted by key. It holds the 500 most recently seen keys; properties_truncated is true when the event has carried more. Four keys the SDK adds to every event are left out: $app_session_id, $event_name, $is_standard_event, and event_name. A name the app has never sent returns an empty properties list, not an error.
To search property keys across all events at once, GET /v2/organizations/<org-id>/query/schema/property-index?application_id=<app-id> returns every event the data schema lists, each with its property keys and their types but without last_seen_at. Events with no properties are left out, each event holds at most 500 keys, and properties_truncated is true when at least one event was cut.
Count each event's arrivals
To see how often each event arrived, per day over the last 30 days, call the event volume endpoint:
curl --get "https://api.superwall.com/v2/organizations/$SUPERWALL_ORG_ID/query/schema/event-volume" \
--header "Authorization: Bearer $SUPERWALL_API_KEY" \
--data-urlencode "application_id=$SUPERWALL_APP_ID"With the CLI: superwall get /v2/organizations/<org-id>/query/schema/event-volume -d application_id=<app-id>.
{
"object": "data_schema_event_volume",
"days": ["2026-10-01", "2026-10-02", /* … 27 more … */ "2026-10-30"],
"events": [
{ "name": "session_start", "total": 184203, "daily": [6012, 5987, /* … */ 4120] },
{ "name": "paywall_open", "total": 52977, "daily": [1810, 1764, /* … */ 1203] }
]
}days holds the window's 30 dates in UTC, oldest first, ending with today. Each event has its total for the window and daily, one count per date in days, with 0 for a day it didn't arrive. events is sorted by total, most arrivals first, and only holds events that arrived in the window: an event the data schema lists but that isn't here didn't arrive in the last 30 days.
The counts are approximate, within about 1.6%, and an event delivered twice counts once. They come from sw.events_daily_count_agg, so a query on that table returns the same numbers. Like the other schema endpoints, they cover production data only. Today's count is still growing.
List revenue events
Revenue events from your store integrations, such as initial_purchase and renewal, are normalized into open_revenue.attributed_events_by_ts_rep, with the same names for every store. To see which ones an app has received:
curl --get "https://api.superwall.com/v2/organizations/$SUPERWALL_ORG_ID/query/schema/revenue-events" \
--header "Authorization: Bearer $SUPERWALL_API_KEY" \
--data-urlencode "application_id=$SUPERWALL_APP_ID"With the CLI: superwall get /v2/organizations/<org-id>/query/schema/revenue-events -d application_id=<app-id>.
{
"object": "data_schema_revenue_events",
"days": ["2026-10-01", /* … 28 more … */ "2026-10-30"],
"events": [
{
"name": "renewal",
"integration": "app_store_connect",
"stores": ["APP_STORE"],
"total": 4210,
"daily": [140, /* … */ 122],
"refunds": null,
"last_seen_at": "2026-10-30T17:41:08.000Z"
}
],
"fields": [
{ "name": "price", "type": "Nullable(Decimal(65, 2))" },
{ "name": "productId", "type": "Nullable(String)" }
]
}events has one entry per event name and integration, so an app with two integrations has an entry for each. integration is null for the SDK's own transaction_complete. refunds counts the refunds among cancellation events and is null for every other event. fields lists the columns of open_revenue.attributed_events_by_ts_rep. Counts use the same 30-day window and estimate as event volume. There is no older /v2/charts version of this endpoint.
Use the names in SQL
Each name or key maps onto sw.events_rep:
- An event name is a value of the
namecolumn, as inWHERE name = 'renewal'. - An event property key is a key in the
propsof that event's rows, soJSONExtractString(props, '$presented_by_event_name')withWHERE name = 'paywall_open'reads one. - A user attribute key is a key in the
propsofuser_attributesevents, and a device attribute key is a key in thepropsofdevice_attributesevents. typespicks the JSON function:JSONExtractStringforString,JSONExtractIntforInt64,JSONExtractUIntforUInt64,JSONExtractFloatforDouble,JSONExtractBoolforBool, andJSONExtractRawforArrayandObject. A key with several types needs a query that handles each of them.
Users per plan value the app sent in the past 30 days:
SELECT
JSONExtractString(props, 'plan') AS plan,
uniq(appUserId) AS users
FROM sw.events_rep
WHERE applicationId = 456
AND isSandbox = 0
AND name = 'user_attributes'
AND ts >= now() - INTERVAL 30 DAY
GROUP BY plan
ORDER BY users DESCGet ready-to-run SQL
The SQL endpoint writes a query for one event and returns it with everything you need to run it. It never runs the query. Use it to chart an event without writing SQL yourself, or as a starting point for your own query.
Pass the app, the event name, and a kind:
kind | Returns daily counts of | Other parameters |
|---|---|---|
count | One event, from sw.events_daily_count_agg. | |
breakdown | One event, split by the values of one property key, from sw.events_rep. | key |
revenue | One revenue event, from open_revenue.attributed_events_by_ts_rep. | integration (optional) |
revenue_breakdown | One revenue event, split by the values of one revenue column. | field, integration (optional) |
Parameters:
days: 1 to 30 UTC days, today included. Defaults to 30.key(breakdown): the property key. If it has arrived with more than one type, the SQL reads raw JSON unless you passkey_type, such asString.integration(revenue kinds): a value from List revenue events. Leave it out for the SDK's owntransaction_completerows.field(revenue_breakdown): a column from that endpoint'sfields. Date, decimal and float columns can't be used.
curl --get "https://api.superwall.com/v2/organizations/$SUPERWALL_ORG_ID/query/sql" \
--header "Authorization: Bearer $SUPERWALL_API_KEY" \
--data-urlencode "application_id=$SUPERWALL_APP_ID" \
--data-urlencode "kind=count" \
--data-urlencode "event=paywall_open"With the CLI: superwall get /v2/organizations/<org-id>/query/sql -d application_id=<app-id> -d kind=count -d event=paywall_open.
A trimmed response:
{
"object": "data_schema_query",
"kind": "count",
"name": "paywall_open, last 30 days",
"sql": "SELECT day, uniqHLL12Merge(events) AS events\nFROM sw.events_daily_count_agg\nWHERE applicationId = {app:UInt64} AND isSandbox = 0 AND name = {event:String} AND day >= today() - toIntervalDay({days:UInt16} - 1) AND day <= today()\nGROUP BY day\nORDER BY day WITH FILL FROM today() - toIntervalDay({days:UInt16} - 1) TO today() + INTERVAL 1 DAY",
"params": { "app": 456, "event": "paywall_open", "days": 30 },
"table": "sw.events_daily_count_agg",
"columns": [
{ "name": "day", "type": "Date" },
{ "name": "events", "type": "UInt64" }
],
"chart": { "type": "line", "x": "day", "y": ["events"] },
"approximate": true,
"requires_scope": "data:read",
"run": {
"cli": "superwall query --app 456 --param 'event=paywall_open' --param 'days=30' --file query.sql --json",
"curl": "curl --request POST 'https://api.superwall.com/v2/organizations/123/query?default_format=JSON¶m_app=456¶m_event=paywall_open¶m_days=30' --header \"Authorization: Bearer $SUPERWALL_API_KEY\" --data-binary @query.sql"
},
"docs_url": "https://superwall.com/docs/dashboard/guides/query-clickhouse#get-ready-to-run-sql",
"sql_version": "2026-11-04"
}To run it:
- Save the
sqlvalue to a file namedquery.sql. - Run the command in
run.cliwith the Superwall CLI, or the command inrun.curlwith your API key inSUPERWALL_API_KEY.
The SQL uses ClickHouse parameters like {event:String}, and both commands pass their values. params holds the same values for ClickHouse client libraries, and http_params holds them ready to send as param_<name> URL parameters. editor_sql is the same query with the values written in, for editors that can't pass parameters.
The result's columns stay the same over time, but the SQL text can change. sql_version changes when it does. A breakdown keeps the 8 values with the most events and groups the rest as (other values). Counts are approximate, so the parts of a breakdown may not add up exactly to the event's count.
Count revenue like the dashboard
Many apps receive revenue from both their store and RevenueCat, so open_revenue.attributed_events_by_ts_rep can hold the same purchase twice. Each app's revenue provider decides which rows its dashboard figures count:
| Revenue provider | integration values counted |
|---|---|
Store (open_revenue) | app_store_connect, google_play, stripe |
RevenueCat (revenue_cat) | revenue_cat, stripe |
| None chosen | all of them |
Rows with source = 'sdk' always count, and RevenueCat's copies of Stripe purchases never do. With the Superwall CLI, superwall query --app <app> passes the app's id and integrations as ClickHouse parameters, so one query works for any app:
SELECT sum(price) AS revenue
FROM open_revenue.attributed_events_by_ts_rep FINAL
WHERE applicationId = {app:UInt64}
AND isSandbox = 0
AND (integration IN {revenue_integrations:Array(String)} OR source = 'sdk')
AND NOT (coalesce(integration, '') = 'revenue_cat' AND store = 'STRIPE')Read deduplicated tables
sw.device_attributes_rep, sw.user_aliases_rep, sw.user_attributes_rep, and the _rep revenue tables are deduplicated in the background, so a plain query can return an older copy of a row next to its replacement. Add FINAL after the table name to read only the latest version of each row. On sw.device_attributes_rep and sw.user_aliases_rep, FINAL also drops deleted rows, so you don't need to filter on isDeleted.
Look up a user's device attributes:
SELECT key, value
FROM sw.device_attributes_rep FINAL
WHERE applicationId = 123
AND appUserId = 'user_123'Find every ID that belongs to the same user:
SELECT alias
FROM sw.user_aliases_rep FINAL
WHERE applicationId = 123
AND id = 'user_123'Aggregated SDK events
open_revenue.sdk_events_agg stores pre-aggregated unique users per app, SDK event name, hour, and breakdown, the same data behind dashboard conversion charts. Its user columns hold ClickHouse aggregate states, so read them with uniqIfMerge (or uniqIfMergeIf to pick an event) and a GROUP BY, not with SELECT *.
Each row has a tsType:
tsType | ts is |
|---|---|
event_time | The hour the event happened. |
install_time | The hour the user was first seen. Use it for install cohorts. |
vendorIds counts every user. On install_time rows, vendorIdsD1, vendorIdsD3, vendorIdsD7, vendorIdsD14, vendorIdsD30, and vendorIdsD90 count only users who did the event within that many days of install.
Paywall conversion by placement over the last 30 days:
SELECT
breakdown['placement'] AS placement,
uniqIfMergeIf(vendorIds, name = 'paywall_open') AS paywall_users,
uniqIfMergeIf(vendorIds, name = 'transaction_complete') AS converted_users
FROM open_revenue.sdk_events_agg
WHERE applicationId = 123
AND isSandbox = 0
AND tsType = 'event_time'
AND ts >= now() - INTERVAL 30 DAY
GROUP BY placement
ORDER BY paywall_users DESC
LIMIT 20New users per install day, and how many converted within 7 days:
SELECT
toDate(ts) AS install_day,
uniqIfMergeIf(vendorIds, name = 'first_seen') AS new_users,
uniqIfMergeIf(vendorIdsD7, name = 'transaction_complete') AS converted_within_7_days
FROM open_revenue.sdk_events_agg
WHERE applicationId = 123
AND isSandbox = 0
AND tsType = 'install_time'
AND ts >= now() - INTERVAL 30 DAY
GROUP BY install_day
ORDER BY install_dayQuery JSON properties
Some event details are stored in JSON strings such as props and meta. Use ClickHouse JSON functions to extract them. To see which keys an app sends and their types, see Find event names and property keys.
SELECT
JSONExtractString(props, '$presented_by_event_name') AS placement,
count() AS opens
FROM sw.events_rep
WHERE name = 'paywall_open'
AND ts >= now() - INTERVAL 30 DAY
GROUP BY placement
ORDER BY opens DESC
LIMIT 20
FORMAT JSONEachRow;Limits
Queries run as a read-only organization user with ClickHouse settings applied:
| Limit | Value |
|---|---|
| Maximum execution time | 300 seconds |
| Maximum threads | 4 |
| Maximum memory | 8 GB |
| Maximum bytes read | 20 GB |
If a query times out or uses too much memory, narrow the date range, add filters on applicationId, isSandbox, or event name, and avoid selecting large JSON columns unless you need them.
Troubleshooting
| Status | What to check |
|---|---|
401 | The request is missing a bearer token, or the token is invalid or revoked. |
403 | The API key does not include the data:read scope, or it is restricted to some projects instead of all of them. |
404 | The requested organization resource could not be found, or the application_id you passed belongs to another organization. |
429 | Too many requests were sent in a short period. Retry later. |
500 | ClickHouse returned an unexpected error or Superwall could not proxy the request. Check the SQL and try a smaller query. |
Related
How is this guide?
Testing Purchases: Sandbox, TestFlight and Test Mode
Pick the right way to test your paywall and purchases: test mode, StoreKit files, Apple sandbox and TestFlight, Google Play testers, or Stripe sandbox.
Acquisition Cohort Report
Pull installs, trials, ad spend, CPI, and install-cohorted revenue per campaign, ad set, ad, or country through the Superwall MCP or API.