Skip to content
Start here

Save query

client.workers.observability.queries.create(QueryCreateParams { account_id, description, name, parameters } params, RequestOptionsoptions?): QueryCreateResponse { id, adhoc, created, 6 more }
POST/accounts/{account_id}/workers/observability/queries

Persist query for later use.

Security
API Email + API Key

The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.

Example:X-Auth-Email: user@example.com

The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.

Example:X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194
API Token

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

Example:Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY
User Service Key

Used when interacting with the Origin CA certificates API. View/change your key.

Example:X-Auth-User-Service-Key: v1.0-144c9defac04969c7bfad8ef-631a41d003a32d25fe878081ef365c49503f7fada600da935e2851a1c7326084b85cbf6429c4b859de8475731dc92a9c329631e6d59e6c73da7b198497172b4cefe071d90d0f5d2719
Accepted Permissions (at least one required)
Workers Observability Write
ParametersExpand Collapse
params: QueryCreateParams { account_id, description, name, parameters }
account_id: string

Path param: Your Cloudflare account ID.

description: string | null

Body param

maxLength1000
name: string

Body param: Query name

maxLength250
minLength1
parameters: Parameters

Body param

calculations?: Array<Calculation>

Create Calculations to compute as part of the query.

operator: "uniq" | "count" | "max" | 35 more
One of the following:
"uniq"
"count"
"max"
"min"
"sum"
"avg"
"median"
"p001"
"p01"
"p05"
"p10"
"p25"
"p75"
"p90"
"p95"
"p99"
"p999"
"stddev"
"variance"
"COUNT_DISTINCT"
"COUNT"
"MAX"
"MIN"
"SUM"
"AVG"
"MEDIAN"
"P001"
"P01"
"P05"
"P10"
"P25"
"P75"
"P90"
"P95"
"P99"
"P999"
"STDDEV"
"VARIANCE"
alias?: string
key?: string
keyType?: "string" | "number" | "boolean"
One of the following:
"string"
"number"
"boolean"
datasets?: Array<string>

Set the Datasets to query. Leave it empty to query all the datasets.

filterCombination?: "and" | "or" | "AND" | "OR"

Set a Flag to describe how to combine the filters on the query.

One of the following:
"and"
"or"
"AND"
"OR"
filters?: Array<UnionMember0 { filterCombination, filters, kind } | WorkersObservabilityFilterLeaf { key, operation, type, 2 more } >

Configure the Filters to apply to the query. Supports nested groups via kind: ‘group’.

One of the following:
UnionMember0 { filterCombination, filters, kind }
filterCombination: "and" | "or" | "AND" | "OR"
One of the following:
"and"
"or"
"AND"
"OR"
filters: Array<unknown>
kind: "group"
WorkersObservabilityFilterLeaf { key, operation, type, 2 more }

A filter condition applied to query results. Use the keys and values endpoints to discover available fields and their values before constructing filters.

key: string

Filter field name. Use verified keys from previous query results or the keys endpoint. Common keys include $metadata.service, $metadata.origin, $metadata.trigger, $metadata.message, and $metadata.error.

operation: "includes" | "not_includes" | "starts_with" | 27 more

Comparison operator. String operators: includes, not_includes, starts_with, ends_with, regex. Existence: exists, is_null. Set membership: in, not_in (comma-separated values). Numeric: eq, neq, gt, gte, lt, lte.

One of the following:
"includes"
"not_includes"
"starts_with"
"ends_with"
"regex"
"exists"
"is_null"
"in"
"not_in"
"eq"
"neq"
"gt"
"gte"
"lt"
"lte"
"="
"!="
">"
">="
"<"
"<="
"INCLUDES"
"DOES_NOT_INCLUDE"
"MATCH_REGEX"
"EXISTS"
"DOES_NOT_EXIST"
"IN"
"NOT_IN"
"STARTS_WITH"
"ENDS_WITH"
type: "string" | "number" | "boolean"

Data type of the filter field. Must match the actual type of the key being filtered.

One of the following:
"string"
"number"
"boolean"
kind?: "filter"

Discriminator for leaf filter nodes. Always ‘filter’ when present; may be omitted.

value?: string | number | boolean

Comparison value. Must match actual values in your data — verify with the values endpoint. Ensure the value type (string/number/boolean) matches the field type. String comparisons are case-sensitive. Regex uses RE2 syntax (no lookaheads/lookbehinds).

One of the following:
string
number
boolean
groupBys?: Array<GroupBy>

Define how to group the results of the query.

type: "string" | "number" | "boolean"
One of the following:
"string"
"number"
"boolean"
value: string
havings?: Array<Having>

Configure the Having clauses that filter on calculations in the query result.

key: string
operation: "eq" | "neq" | "gt" | 3 more
One of the following:
"eq"
"neq"
"gt"
"gte"
"lt"
"lte"
value: number
limit?: number

Set a limit on the number of results / records returned by the query

maximum100
minimum0
needle?: Needle { value, isRegex, matchCase }

Define an expression to search using full-text search.

value: string | number | boolean
maxLength1000
One of the following:
string
number
boolean
isRegex?: boolean
matchCase?: boolean
orderBy?: OrderBy { value, order }

Configure the order of the results returned by the query.

value: string

Configure which Calculation to order the results by.

order?: "asc" | "desc"

Set the order of the results

One of the following:
"asc"
"desc"
ReturnsExpand Collapse
QueryCreateResponse { id, adhoc, created, 6 more }
id: string
adhoc: boolean

If the query wasn’t explcitly saved

created: string
createdBy: string
description: string | null
maxLength1000
name: string

Query name

maxLength250
minLength1
parameters: Parameters { calculations, datasets, filterCombination, 6 more }
calculations?: Array<Calculation>

Create Calculations to compute as part of the query.

operator: "uniq" | "count" | "max" | 35 more
One of the following:
"uniq"
"count"
"max"
"min"
"sum"
"avg"
"median"
"p001"
"p01"
"p05"
"p10"
"p25"
"p75"
"p90"
"p95"
"p99"
"p999"
"stddev"
"variance"
"COUNT_DISTINCT"
"COUNT"
"MAX"
"MIN"
"SUM"
"AVG"
"MEDIAN"
"P001"
"P01"
"P05"
"P10"
"P25"
"P75"
"P90"
"P95"
"P99"
"P999"
"STDDEV"
"VARIANCE"
alias?: string
key?: string
keyType?: "string" | "number" | "boolean"
One of the following:
"string"
"number"
"boolean"
datasets?: Array<string>

Set the Datasets to query. Leave it empty to query all the datasets.

filterCombination?: "and" | "or" | "AND" | "OR"

Set a Flag to describe how to combine the filters on the query.

One of the following:
"and"
"or"
"AND"
"OR"
filters?: Array<UnionMember0 { filterCombination, filters, kind } | WorkersObservabilityFilterLeaf { key, operation, type, 2 more } >

Configure the Filters to apply to the query. Supports nested groups via kind: ‘group’.

One of the following:
UnionMember0 { filterCombination, filters, kind }
filterCombination: "and" | "or" | "AND" | "OR"
One of the following:
"and"
"or"
"AND"
"OR"
filters: Array<unknown>
kind: "group"
WorkersObservabilityFilterLeaf { key, operation, type, 2 more }

A filter condition applied to query results. Use the keys and values endpoints to discover available fields and their values before constructing filters.

key: string

Filter field name. Use verified keys from previous query results or the keys endpoint. Common keys include $metadata.service, $metadata.origin, $metadata.trigger, $metadata.message, and $metadata.error.

operation: "includes" | "not_includes" | "starts_with" | 27 more

Comparison operator. String operators: includes, not_includes, starts_with, ends_with, regex. Existence: exists, is_null. Set membership: in, not_in (comma-separated values). Numeric: eq, neq, gt, gte, lt, lte.

One of the following:
"includes"
"not_includes"
"starts_with"
"ends_with"
"regex"
"exists"
"is_null"
"in"
"not_in"
"eq"
"neq"
"gt"
"gte"
"lt"
"lte"
"="
"!="
">"
">="
"<"
"<="
"INCLUDES"
"DOES_NOT_INCLUDE"
"MATCH_REGEX"
"EXISTS"
"DOES_NOT_EXIST"
"IN"
"NOT_IN"
"STARTS_WITH"
"ENDS_WITH"
type: "string" | "number" | "boolean"

Data type of the filter field. Must match the actual type of the key being filtered.

One of the following:
"string"
"number"
"boolean"
kind?: "filter"

Discriminator for leaf filter nodes. Always ‘filter’ when present; may be omitted.

value?: string | number | boolean

Comparison value. Must match actual values in your data — verify with the values endpoint. Ensure the value type (string/number/boolean) matches the field type. String comparisons are case-sensitive. Regex uses RE2 syntax (no lookaheads/lookbehinds).

One of the following:
string
number
boolean
groupBys?: Array<GroupBy>

Define how to group the results of the query.

type: "string" | "number" | "boolean"
One of the following:
"string"
"number"
"boolean"
value: string
havings?: Array<Having>

Configure the Having clauses that filter on calculations in the query result.

key: string
operation: "eq" | "neq" | "gt" | 3 more
One of the following:
"eq"
"neq"
"gt"
"gte"
"lt"
"lte"
value: number
limit?: number

Set a limit on the number of results / records returned by the query

maximum100
minimum0
needle?: Needle { value, isRegex, matchCase }

Define an expression to search using full-text search.

value: string | number | boolean
maxLength1000
One of the following:
string
number
boolean
isRegex?: boolean
matchCase?: boolean
orderBy?: OrderBy { value, order }

Configure the order of the results returned by the query.

value: string

Configure which Calculation to order the results by.

order?: "asc" | "desc"

Set the order of the results

One of the following:
"asc"
"desc"
updated: string
updatedBy: string

Save query

import Cloudflare from 'cloudflare';

const client = new Cloudflare({
  apiEmail: process.env['CLOUDFLARE_EMAIL'], // This is the default and can be omitted
  apiKey: process.env['CLOUDFLARE_API_KEY'], // This is the default and can be omitted
});

const query = await client.workers.observability.queries.create({
  account_id: 'account_id',
  description: 'Query description',
  name: 'x',
  parameters: {},
});

console.log(query.id);
{
  "errors": [
    {
      "message": "message"
    }
  ],
  "messages": [
    {
      "message": "Successful request"
    }
  ],
  "result": {
    "id": "id",
    "adhoc": true,
    "created": "created",
    "createdBy": "createdBy",
    "description": "Query description",
    "name": "x",
    "parameters": {
      "calculations": [
        {
          "operator": "uniq",
          "alias": "alias",
          "key": "key",
          "keyType": "string"
        }
      ],
      "datasets": [
        "string"
      ],
      "filterCombination": "and",
      "filters": [
        {
          "filterCombination": "and",
          "filters": [
            {}
          ],
          "kind": "group"
        }
      ],
      "groupBys": [
        {
          "type": "string",
          "value": "value"
        }
      ],
      "havings": [
        {
          "key": "key",
          "operation": "eq",
          "value": 0
        }
      ],
      "limit": 0,
      "needle": {
        "value": "string",
        "isRegex": true,
        "matchCase": true
      },
      "orderBy": {
        "value": "value",
        "order": "asc"
      }
    },
    "updated": "updated",
    "updatedBy": "updatedBy"
  },
  "success": true
}
Returns Examples
{
  "errors": [
    {
      "message": "message"
    }
  ],
  "messages": [
    {
      "message": "Successful request"
    }
  ],
  "result": {
    "id": "id",
    "adhoc": true,
    "created": "created",
    "createdBy": "createdBy",
    "description": "Query description",
    "name": "x",
    "parameters": {
      "calculations": [
        {
          "operator": "uniq",
          "alias": "alias",
          "key": "key",
          "keyType": "string"
        }
      ],
      "datasets": [
        "string"
      ],
      "filterCombination": "and",
      "filters": [
        {
          "filterCombination": "and",
          "filters": [
            {}
          ],
          "kind": "group"
        }
      ],
      "groupBys": [
        {
          "type": "string",
          "value": "value"
        }
      ],
      "havings": [
        {
          "key": "key",
          "operation": "eq",
          "value": 0
        }
      ],
      "limit": 0,
      "needle": {
        "value": "string",
        "isRegex": true,
        "matchCase": true
      },
      "orderBy": {
        "value": "value",
        "order": "asc"
      }
    },
    "updated": "updated",
    "updatedBy": "updatedBy"
  },
  "success": true
}