## 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 } ```