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:
Accepted Permissions (at least one required)
Body Parameters
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