Skip to content
Start here

Execute an Analytics Engine SQL query via request body

POST/accounts/{account_id}/analytics_engine/sql

Executes a SQL query against Workers Analytics Engine data. Pass the SQL query in the request body as plain text. The response uses newline-delimited JSON (NDJSON) by default, or a single JSON object when the query includes a FORMAT JSON clause. Prefer this method for longer queries that may exceed URL length limits.

Security

API Token

The preferred authorization scheme for interacting with the Cloudflare API. Create a token.

Example:Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY
Accepted Permissions (at least one required)
Account Analytics Read
Path ParametersExpand Collapse
account_id: string
Body ParametersExpand Collapse
body: string

Supply a SQL query to run against your Analytics Engine datasets. Use only SELECT statements. The service validates the query against a restricted SQL grammar before execution.

ReturnsExpand Collapse
data: array of map[unknown]

Array of result rows. Each row is an object with keys corresponding to the selected columns.

meta: array of object { name, type }

Column metadata describing the name and type of each column in the result set.

name: string

Column name.

type: string

Column data type.

rows: number

Total number of rows in the result set.

Execute an Analytics Engine SQL query via request body

curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/analytics_engine/sql \
    -H 'Content-Type: text/plain' \
    -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
    -d "\"SELECT blob1, sum(double1) as total\\nFROM my_dataset\\nWHERE timestamp > NOW() - INTERVAL '7' DAY\\nGROUP BY blob1\\nORDER BY total DESC\\nLIMIT 100\\n\""
{
  "data": [
    {
      "blob1": "US",
      "count()": 1523
    },
    {
      "blob1": "DE",
      "count()": 847
    }
  ],
  "meta": [
    {
      "name": "blob1",
      "type": "String"
    },
    {
      "name": "count()",
      "type": "UInt64"
    }
  ],
  "rows": 2
}
Content type error
Query string error: missing field `query`
Authorization error
Input was invalid: syntax error at position 15
Input was invalid: cannot combine the String and UInt64 types with the + operator
Input was invalid: cannot select unknown column: nonexistent
Input was invalid: JOINs are not supported
Resource limit: Your query requires too much memory. Try simplifying the query or narrowing the time range.
Resource limit: Your query timed out. Try simplifying the query or narrowing the time range.
Resource limit: Too many queries queued for this account. Please try again later.
Resource limit: Your query result is too large. Try adding a LIMIT clause or narrowing your query.
Sorry, we were unable to evaluate your query. Please try again later.
Query timed out waiting in queue. The system is under heavy load. Please try again later.
Gateway Timeout
Returns Examples
{
  "data": [
    {
      "blob1": "US",
      "count()": 1523
    },
    {
      "blob1": "DE",
      "count()": 847
    }
  ],
  "meta": [
    {
      "name": "blob1",
      "type": "String"
    },
    {
      "name": "count()",
      "type": "UInt64"
    }
  ],
  "rows": 2
}
Content type error
Query string error: missing field `query`
Authorization error
Input was invalid: syntax error at position 15
Input was invalid: cannot combine the String and UInt64 types with the + operator
Input was invalid: cannot select unknown column: nonexistent
Input was invalid: JOINs are not supported
Resource limit: Your query requires too much memory. Try simplifying the query or narrowing the time range.
Resource limit: Your query timed out. Try simplifying the query or narrowing the time range.
Resource limit: Too many queries queued for this account. Please try again later.
Resource limit: Your query result is too large. Try adding a LIMIT clause or narrowing your query.
Sorry, we were unable to evaluate your query. Please try again later.
Query timed out waiting in queue. The system is under heavy load. Please try again later.
Gateway Timeout