API
Custom SQL endpoint
This endpoint runs your own SQL against the events of the sites you can open. Scope: sql:read. It needs a member or a key.
Last updated . This guide belongs to API access and data export.
POST /organizations/:organizationId/analytics/query
| Field | Required | Content |
|---|---|---|
query | Yes | 1 to 20,000 characters |
siteId | No | Limits the query to one site. Without it, all your sites are included |
curl -X POST "https://app.loogika.com/api/organizations/ORG_ID/analytics/query" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "siteId": 12, "query": "SELECT pathname, count() AS pageviews FROM scoped_events WHERE type = '\''pageview'\'' AND timestamp >= now() - INTERVAL 7 DAY GROUP BY pathname ORDER BY pageviews DESC LIMIT 10" }'
{ "data": [ { "pathname": "/", "pageviews": "9120" } ], "meta": { "queryId": "b7e0d4c2", "rowCount": 1, "maxExecutionTimeSeconds": 10, "maxRows": 1000 } }
Large counts can come back as text, as in the example.
What are the rules for a query?
- It must start with
SELECTorWITH, and it must be one statement. - It can read from
scoped_eventsonly. You can build your own CTEs on top of it. - The time parameters do not apply. Put the period in the query with a condition on
timestamp. - Double quotes, backticks and comments are not allowed outside text values.
Custom dashboards and SQL lists the columns.
What are the limits?
| Limit | Value |
|---|---|
| Rows | 1,000. A longer result is cut without a warning |
| Run time | 10 seconds |
| Requests | 60 per minute |
A query that breaks a rule, or that runs too long, returns status 400 with the reason.