# Analytics Query ## Query analytics summary `client.analyticsQuery.summary(stringdataset, AnalyticsQuerySummaryParamsparams, RequestOptionsoptions?): AnalyticsQuerySummaryResponse` **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. ### Parameters - `dataset: string` - `params: AnalyticsQuerySummaryParams` - `account_id: string` Path param: Cloudflare account identifier. - `filters: Array` 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: Array` Values to match against. Type depends on the column. - `string` - `boolean` - `number` - `from: string` Body param: The start of the query time range (inclusive). RFC3339 format with timezone is required (e.g. `2024-11-05T00:00:00Z`). - `groupBy: Array` Body param: Specifies the column names to group results by. Requires valid columns for the target dataset. - `stats: Array` Body param: Specifies the stat names to include in results. Requires valid stats for the target dataset (e.g. `attemptsTotal`, `bytesTotal`). - `to: string` Body param: Specifies the end of the query time range (exclusive). Requires RFC3339 format with timezone. ### Returns - `AnalyticsQuerySummaryResponse` - `currentTotal: Array>` Aggregated stats for the requested time range. - `previousTotal: Array>` Aggregated stats for the equivalent preceding time range, for trend comparison. ### Example ```typescript import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const response = await client.analyticsQuery.summary('access-logins', { account_id: '023e105f4ecef8ad9ca31a8372d0c353', filters: [], from: '2024-11-01T00:00:00Z', groupBy: [], stats: ['attemptsTotal'], to: '2024-11-08T00:00:00Z', }); console.log(response.currentTotal); ``` #### Response ```json { "errors": [], "messages": [ { "code": 1000, "message": "API in beta: expect breaking changes." } ], "result": { "currentTotal": [ { "attemptsTotal": 48291 } ], "previousTotal": [ { "attemptsTotal": 41033 } ] }, "success": true } ``` ## Query analytics timeseries `client.analyticsQuery.timeseries(stringdataset, AnalyticsQueryTimeseriesParamsparams, RequestOptionsoptions?): AnalyticsQueryTimeseriesResponse` **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` - `account_id: string` Path param: Cloudflare account identifier. - `filters: Array` 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: Array` Values to match against. Type depends on the column. - `string` - `boolean` - `number` - `from: string` Body param: The start of the query time range (inclusive). RFC3339 format with timezone is required (e.g. `2024-11-05T00:00:00Z`). - `groupBy: Array` Body param: Specifies the column names to group results by. Requires valid columns for the target dataset. - `resolution: string` Body param: Time bucket size for grouping results. Controls the granularity of the returned time slots. - `stats: Array` Body param: Specifies the stat names to include in results. Requires valid stats for the target dataset (e.g. `attemptsTotal`, `bytesTotal`). - `to: string` Body param: Specifies the end of the query time range (exclusive). Requires RFC3339 format with timezone. ### Returns - `AnalyticsQueryTimeseriesResponse` - `resolution: string` The resolution used for time bucketing. - `slots: Array>` Time-bucketed result rows. Each slot contains a `time_bucket` field plus the requested stats and group-by dimensions. ### Example ```typescript import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const response = await client.analyticsQuery.timeseries('shadow_it', { account_id: '023e105f4ecef8ad9ca31a8372d0c353', filters: [ { name: 'allowed', op: 'eq', values: [true], }, ], from: '2024-11-01T00:00:00Z', groupBy: ['country', 'allowed'], resolution: 'day', stats: ['attemptsTotal'], to: '2024-11-08T00:00:00Z', }); console.log(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 } ``` ## Query analytics top-N `client.analyticsQuery.topN(stringdataset, AnalyticsQueryTopNParamsparams, RequestOptionsoptions?): SinglePage` **post** `/accounts/{account_id}/analytics/query/{dataset}/top-n` Returns the top N results for a dataset by a specified stat. Includes an array of result rows, each containing the requested stats and group-by dimensions. ### Parameters - `dataset: string` - `params: AnalyticsQueryTopNParams` - `account_id: string` Path param: Cloudflare account identifier. - `filters: Array` 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: Array` Values to match against. Type depends on the column. - `string` - `boolean` - `number` - `from: string` Body param: The start of the query time range (inclusive). RFC3339 format with timezone is required (e.g. `2024-11-05T00:00:00Z`). - `groupBy: Array` Body param: Specifies the column names to group results by. Requires valid columns for the target dataset. - `n: number` Body param: Maximum number of results to return. - `orderBy: string` Body param: Specifies the stat name for sorting results in descending order. Requires a valid stat for the target dataset. - `stats: Array` Body param: Specifies the stat names to include in results. Requires valid stats for the target dataset (e.g. `attemptsTotal`, `bytesTotal`). - `to: string` Body param: Specifies the end of the query time range (exclusive). Requires RFC3339 format with timezone. ### Returns - `AnalyticsQueryTopNResponse = Record` Maps field names to values. Keys represent stat names and group-by column names. Values depend on the dataset (strings, numbers, booleans). ### Example ```typescript import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); // Automatically fetches more pages as needed. for await (const analyticsQueryTopNResponse of client.analyticsQuery.topN('gateway-http', { account_id: '023e105f4ecef8ad9ca31a8372d0c353', filters: [], from: '2024-11-05T00:00:00Z', groupBy: ['appName', 'appCategory'], n: 10, orderBy: 'bytesTotal', stats: ['bytesTotal', 'requestsTotal'], to: '2024-11-06T00:00:00Z', })) { console.log(analyticsQueryTopNResponse); } ``` #### Response ```json { "errors": [], "messages": [ { "code": 1000, "message": "API in beta: expect breaking changes." } ], "result": [ { "appCategory": "Collaboration", "appName": "Slack", "bytesTotal": 10485760, "requestsTotal": 1024 }, { "appCategory": "File Storage", "appName": "Dropbox", "bytesTotal": 5242880, "requestsTotal": 512 } ], "success": true } ``` ## Domain Types ### Analytics Query Summary Response - `AnalyticsQuerySummaryResponse` - `currentTotal: Array>` Aggregated stats for the requested time range. - `previousTotal: Array>` Aggregated stats for the equivalent preceding time range, for trend comparison. ### Analytics Query Timeseries Response - `AnalyticsQueryTimeseriesResponse` - `resolution: string` The resolution used for time bucketing. - `slots: Array>` Time-bucketed result rows. Each slot contains a `time_bucket` field plus the requested stats and group-by dimensions. ### Analytics Query Top N Response - `AnalyticsQueryTopNResponse = Record` Maps field names to values. Keys represent stat names and group-by column names. Values depend on the dataset (strings, numbers, booleans). # Data Security # Content Findings ## Top integrations by content findings `client.analyticsQuery.dataSecurity.contentFindings.topN(ContentFindingTopNParamsparams, RequestOptionsoptions?): SinglePage` **post** `/accounts/{account_id}/analytics/query/data-security/content-findings/top-n` Returns the top N integrations ranked by total content findings. ### Parameters - `params: ContentFindingTopNParams` - `account_id: string` Path param: Cloudflare account identifier. - `filters: Array` Body param: Filters to apply. `findingType = content` is applied automatically for CASB data. - `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: Array` Values to match against. Type depends on the column. - `string` - `boolean` - `number` - `from: string` Body param: Start of the query time range (inclusive). RFC3339. - `n: number` Body param: Maximum number of integrations to return. - `to: string` Body param: End of the query time range (exclusive). RFC3339. ### Returns - `ContentFindingTopNResponse = Record` Maps field names to values. Keys represent stat names and group-by column names. Values depend on the dataset (strings, numbers, booleans). ### Example ```typescript import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); // Automatically fetches more pages as needed. for await (const contentFindingTopNResponse of client.analyticsQuery.dataSecurity.contentFindings.topN( { account_id: '023e105f4ecef8ad9ca31a8372d0c353', filters: [], from: '2024-11-01T00:00:00Z', n: 10, to: '2024-11-08T00:00:00Z', }, )) { console.log(contentFindingTopNResponse); } ``` #### Response ```json { "errors": [], "messages": [ { "code": 1000, "message": "API in beta: expect breaking changes." } ], "result": [ { "integrationId": "123e4567-e89b-12d3-a456-426614174000", "integrationName": "Google Workspace", "total": 42 }, { "integrationId": "223e4567-e89b-12d3-a456-426614174001", "integrationName": "Microsoft 365", "total": 17 } ], "success": true } ``` ## Domain Types ### Content Finding Top N Response - `ContentFindingTopNResponse = Record` Maps field names to values. Keys represent stat names and group-by column names. Values depend on the dataset (strings, numbers, booleans). # Findings ## Data security findings summary `client.analyticsQuery.dataSecurity.findings.summary(FindingSummaryParamsparams, RequestOptionsoptions?): FindingSummaryResponse` **post** `/accounts/{account_id}/analytics/query/data-security/findings/summary` Returns aggregate current-period and previous-period totals for CASB findings. ### Parameters - `params: FindingSummaryParams` - `account_id: string` Path param: Cloudflare account identifier. - `filters: Array` Body param: Filters to apply. - `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: Array` Values to match against. Type depends on the column. - `string` - `boolean` - `number` - `from: string` Body param: Start of the query time range (inclusive). RFC3339. - `to: string` Body param: End of the query time range (exclusive). RFC3339. ### Returns - `FindingSummaryResponse` - `currentTotal: Array>` Aggregated stats for the requested time range. - `previousTotal: Array>` Aggregated stats for the equivalent preceding time range, for trend comparison. ### Example ```typescript import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const response = await client.analyticsQuery.dataSecurity.findings.summary({ account_id: '023e105f4ecef8ad9ca31a8372d0c353', filters: [], from: '2024-11-01T00:00:00Z', to: '2024-11-08T00:00:00Z', }); console.log(response.currentTotal); ``` #### Response ```json { "errors": [], "messages": [ { "code": 1000, "message": "API in beta: expect breaking changes." } ], "result": { "currentTotal": [ { "findingProduct": "Cloud", "findingType": "Content", "findingsTotal": 48291 }, { "findingProduct": "SaaS", "findingType": "Posture", "findingsTotal": 1205 } ], "previousTotal": [ { "findingProduct": "Cloud", "findingType": "Content", "findingsTotal": 41033 }, { "findingProduct": "SaaS", "findingType": "Posture", "findingsTotal": 982 } ] }, "success": true } ``` ## Data security findings timeseries `client.analyticsQuery.dataSecurity.findings.timeseries(FindingTimeseriesParamsparams, RequestOptionsoptions?): FindingTimeseriesResponse` **post** `/accounts/{account_id}/analytics/query/data-security/findings/timeseries` Returns merged time-bucketed CASB findings. ### Parameters - `params: FindingTimeseriesParams` - `account_id: string` Path param: Cloudflare account identifier. - `filters: Array` Body param: Filters to apply. - `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: Array` Values to match against. Type depends on the column. - `string` - `boolean` - `number` - `from: string` Body param: Start of the query time range (inclusive). RFC3339. - `to: string` Body param: End of the query time range (exclusive). RFC3339. ### Returns - `FindingTimeseriesResponse` Merged CASB and CDE findings timeseries result. - `slots: Array>` Contains time-bucketed result rows. Each slot includes a `timestamp` plus `content` and `posture` maps with `cloud` and `saas` keys. - `resolution?: string | null` Always null for this endpoint. ### Example ```typescript import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const response = await client.analyticsQuery.dataSecurity.findings.timeseries({ account_id: '023e105f4ecef8ad9ca31a8372d0c353', filters: [], from: '2024-11-01T00:00:00Z', to: '2024-11-08T00:00:00Z', }); console.log(response.slots); ``` #### Response ```json { "errors": [], "messages": [ { "code": 1000, "message": "API in beta: expect breaking changes." } ], "result": { "slots": [ { "content": { "cloud": 150, "saas": 23 }, "posture": { "cloud": 0, "saas": 5 }, "timestamp": "2024-11-05T00:00:00Z" }, { "content": { "cloud": 180, "saas": 30 }, "posture": { "cloud": 0, "saas": 7 }, "timestamp": "2024-11-06T00:00:00Z" } ] }, "success": true } ``` ## Domain Types ### Finding Summary Response - `FindingSummaryResponse` - `currentTotal: Array>` Aggregated stats for the requested time range. - `previousTotal: Array>` Aggregated stats for the equivalent preceding time range, for trend comparison. ### Finding Timeseries Response - `FindingTimeseriesResponse` Merged CASB and CDE findings timeseries result. - `slots: Array>` Contains time-bucketed result rows. Each slot includes a `timestamp` plus `content` and `posture` maps with `cloud` and `saas` keys. - `resolution?: string | null` Always null for this endpoint.