## Query analytics timeseries `client.AnalyticsQuery.Timeseries(ctx, dataset, params) (*AnalyticsQueryTimeseriesResponse, error)` **post** `/accounts/{account_id}/analytics/query/{dataset}/timeseries` Returns time-bucketed analytics data for a dataset. Includes time slots, each containing the requested stats, group-by dimensions, and resolution-controlled bucket size (e.g. `hour`, `day`). ### Parameters - `dataset string` - `params AnalyticsQueryTimeseriesParams` - `AccountID param.Field[string]` Path param: Cloudflare account identifier. - `Filters param.Field[[]AnalyticsQueryTimeseriesParamsFilter]` 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 []AnalyticsQueryTimeseriesParamsFiltersValueUnion` Values to match against. Type depends on the column. - `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`). - `GroupBy param.Field[[]string]` Body param: Specifies the column names to group results by. Requires valid columns for the target dataset. - `Resolution param.Field[string]` Body param: Time bucket size for grouping results. Controls the granularity of the returned time slots. - `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. ### Returns - `type AnalyticsQueryTimeseriesResponse struct{…}` - `Resolution string` The resolution used for time bucketing. - `Slots []map[string, unknown]` Time-bucketed result rows. Each slot contains a `time_bucket` field plus the requested stats and group-by dimensions. ### Example ```go package main import ( "context" "fmt" "time" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" "github.com/cloudflare/cloudflare-go/shared" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) response, err := client.AnalyticsQuery.Timeseries( context.TODO(), "shadow_it", cloudflare.AnalyticsQueryTimeseriesParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), Filters: cloudflare.F([]cloudflare.AnalyticsQueryTimeseriesParamsFilter{cloudflare.AnalyticsQueryTimeseriesParamsFilter{ Name: cloudflare.F("allowed"), Op: cloudflare.F("eq"), Values: cloudflare.F([]cloudflare.AnalyticsQueryTimeseriesParamsFiltersValueUnion{shared.UnionBool(true)}), }}), From: cloudflare.F(time.Now()), GroupBy: cloudflare.F([]string{"country", "allowed"}), Resolution: cloudflare.F("day"), Stats: cloudflare.F([]string{"attemptsTotal"}), To: cloudflare.F(time.Now()), }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", response.Resolution) } ``` #### Response ```json { "errors": [], "messages": [ { "code": 1000, "message": "API in beta: expect breaking changes." } ], "result": { "resolution": "hour", "slots": [ { "appName": "Slack", "bytesTotal": 1048576, "time_bucket": "2024-11-05T00:00:00Z" }, { "appName": "Slack", "bytesTotal": 2097152, "time_bucket": "2024-11-05T01:00:00Z" } ] }, "success": true } ```