Skip to content
Start here

Query analytics summary

client.AnalyticsQuery.Summary(ctx, dataset, params) (*AnalyticsQuerySummaryResponse, error)
POST/accounts/{account_id}/analytics/query/{dataset}/summary

Returns aggregate summary stats for a dataset. Includes current-period and previous-period totals for trend comparison.

Security
API Token

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

Example:Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY
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
Accepted Permissions (at least one required)
Zero Trust Read
ParametersExpand Collapse
dataset string
params AnalyticsQuerySummaryParams
AccountID param.Field[string]

Path param: Cloudflare account identifier.

maxLength32
Filters param.Field[[]AnalyticsQuerySummaryParamsFilter]

Body param: Filters to apply before aggregating results.

Name string

Specifies the column name to filter on. Requires a valid column for the target dataset (e.g. country, allowed, appId).

Op string

Filter operator. Common values: eq, neq, in, not_in, gt, lt, gte, lte.

Values []AnalyticsQuerySummaryParamsFiltersValueUnion

Values to match against. Type depends on the column.

One of the following:
UnionString
UnionBool
UnionFloat
From param.Field[Time]

Body param: The start of the query time range (inclusive). RFC3339 format with timezone is required (e.g. 2024-11-05T00:00:00Z).

formatdate-time
GroupBy param.Field[[]string]

Body param: Specifies the column names to group results by. Requires valid columns for the target dataset.

Stats param.Field[[]string]

Body param: Specifies the stat names to include in results. Requires valid stats for the target dataset (e.g. attemptsTotal, bytesTotal).

To param.Field[Time]

Body param: Specifies the end of the query time range (exclusive). Requires RFC3339 format with timezone.

formatdate-time
ReturnsExpand Collapse
type AnalyticsQuerySummaryResponse struct{…}
CurrentTotal []map[string, unknown]

Aggregated stats for the requested time range.

PreviousTotal []map[string, unknown]

Aggregated stats for the equivalent preceding time range, for trend comparison.

Query analytics summary

package main

import (
  "context"
  "fmt"
  "time"

  "github.com/cloudflare/cloudflare-go"
  "github.com/cloudflare/cloudflare-go/option"
)

func main() {
  client := cloudflare.NewClient(
    option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"),
  )
  response, err := client.AnalyticsQuery.Summary(
    context.TODO(),
    "access-logins",
    cloudflare.AnalyticsQuerySummaryParams{
      AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
      Filters: cloudflare.F([]cloudflare.AnalyticsQuerySummaryParamsFilter{}),
      From: cloudflare.F(time.Now()),
      GroupBy: cloudflare.F([]string{}),
      Stats: cloudflare.F([]string{"attemptsTotal"}),
      To: cloudflare.F(time.Now()),
    },
  )
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", response.CurrentTotal)
}
{
  "errors": [],
  "messages": [
    {
      "code": 1000,
      "message": "API in beta: expect breaking changes."
    }
  ],
  "result": {
    "currentTotal": [
      {
        "attemptsTotal": 48291
      }
    ],
    "previousTotal": [
      {
        "attemptsTotal": 41033
      }
    ]
  },
  "success": true
}
{
  "errors": [
    {
      "code": 11005,
      "message": "art.api.parameter.invalid"
    }
  ],
  "messages": [
    {
      "code": 1002,
      "message": "Parameter 'from' has invalid value '2024-11-05 00:00:00'. Should be of type: 'RFC3339'"
    }
  ],
  "result": null,
  "success": false
}
{
  "errors": [
    {
      "code": 11005,
      "message": "art.api.parameter.invalid"
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "API in beta: expect breaking changes."
    }
  ],
  "result": null,
  "success": false
}
{
  "errors": [
    {
      "code": 11003,
      "message": "art.api.resource.insufficient_permissions"
    }
  ],
  "messages": [],
  "result": null,
  "success": false
}
{
  "errors": [
    {
      "code": 11003,
      "message": "art.api.resource.insufficient_permissions"
    }
  ],
  "messages": [],
  "result": null,
  "success": false
}
{
  "errors": [
    {
      "code": 11003,
      "message": "art.api.resource.insufficient_permissions"
    }
  ],
  "messages": [],
  "result": null,
  "success": false
}
Returns Examples
{
  "errors": [],
  "messages": [
    {
      "code": 1000,
      "message": "API in beta: expect breaking changes."
    }
  ],
  "result": {
    "currentTotal": [
      {
        "attemptsTotal": 48291
      }
    ],
    "previousTotal": [
      {
        "attemptsTotal": 41033
      }
    ]
  },
  "success": true
}
{
  "errors": [
    {
      "code": 11005,
      "message": "art.api.parameter.invalid"
    }
  ],
  "messages": [
    {
      "code": 1002,
      "message": "Parameter 'from' has invalid value '2024-11-05 00:00:00'. Should be of type: 'RFC3339'"
    }
  ],
  "result": null,
  "success": false
}
{
  "errors": [
    {
      "code": 11005,
      "message": "art.api.parameter.invalid"
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "API in beta: expect breaking changes."
    }
  ],
  "result": null,
  "success": false
}
{
  "errors": [
    {
      "code": 11003,
      "message": "art.api.resource.insufficient_permissions"
    }
  ],
  "messages": [],
  "result": null,
  "success": false
}
{
  "errors": [
    {
      "code": 11003,
      "message": "art.api.resource.insufficient_permissions"
    }
  ],
  "messages": [],
  "result": null,
  "success": false
}
{
  "errors": [
    {
      "code": 11003,
      "message": "art.api.resource.insufficient_permissions"
    }
  ],
  "messages": [],
  "result": null,
  "success": false
}