# Get aggregated traffic data for a given time period. GET https://app.unleash-instance.example.com/api/admin/metrics/traffic **Enterprise feature** Gets traffic usage data for the selected period, either aggregated by day or by month. Reference: https://docs.getunleash.io/api/get-traffic-data-usage-for-period ## OpenAPI Specification ```yaml openapi: 3.1.1 info: title: Get aggregated traffic data for a given time period. version: endpoint_metrics.getTrafficDataUsageForPeriod paths: /api/admin/metrics/traffic: get: operationId: get-traffic-data-usage-for-period summary: Get aggregated traffic data for a given time period. description: >- **Enterprise feature** Gets traffic usage data for the selected period, either aggregated by day or by month. tags: - - subpackage_metrics parameters: - name: grouping in: query description: Whether to aggregate the data by month or by day required: true schema: $ref: '#/components/schemas/ApiAdminMetricsTrafficGetParametersGrouping' - name: from in: query description: >- The starting date of the traffic data usage search in IS:yyyy-MM-dd format required: true schema: type: string format: date - name: to in: query description: >- The starting date of the traffic data usage search in IS:yyyy-MM-dd format required: true schema: type: string format: date - name: Authorization in: header description: Header authentication of the form `undefined ` required: true schema: type: string responses: '200': description: trafficUsageDataSegmentedCombinedSchema content: application/json: schema: $ref: '#/components/schemas/trafficUsageDataSegmentedCombinedSchema' components: schemas: ApiAdminMetricsTrafficGetParametersGrouping: type: string enum: - value: daily - value: monthly TrafficUsageDataSegmentedCombinedSchemaGrouping: type: string enum: - value: monthly - value: daily TrafficUsageDataSegmentedCombinedSchemaDateRange: type: object properties: from: type: string format: date description: The start of the dateRange to: type: string format: date description: The end of the dateRange required: - from - to TrafficUsageDataSegmentedCombinedSchemaApiDataItemsDataPointsItemsTrafficTypesItems: type: object properties: group: type: string description: The type of traffic count: type: integer description: The number of requests required: - group - count TrafficUsageDataSegmentedCombinedSchemaApiDataItemsDataPointsItems: type: object properties: period: type: string description: >- The date of the data point. Formatted as a full date (e.g. 2023-04-01) if the data is aggregated by day or as a month (e.g. 2023-04) if the data is aggregated by month. trafficTypes: type: array items: $ref: >- #/components/schemas/TrafficUsageDataSegmentedCombinedSchemaApiDataItemsDataPointsItemsTrafficTypesItems description: The recorded traffic types for the data point required: - period - trafficTypes TrafficUsageDataSegmentedCombinedSchemaApiDataItems: type: object properties: apiPath: type: string description: The API path dataPoints: type: array items: $ref: >- #/components/schemas/TrafficUsageDataSegmentedCombinedSchemaApiDataItemsDataPointsItems description: The recorded data points for the API path required: - apiPath - dataPoints trafficUsageDataSegmentedCombinedSchema: type: object properties: grouping: $ref: '#/components/schemas/TrafficUsageDataSegmentedCombinedSchemaGrouping' description: Whether the data is aggregated by month or by day. dateRange: $ref: >- #/components/schemas/TrafficUsageDataSegmentedCombinedSchemaDateRange description: >- The date range there is data for. The range is inclusive and goes from the start of the `from` date to the end of the `to` date apiData: type: array items: $ref: >- #/components/schemas/TrafficUsageDataSegmentedCombinedSchemaApiDataItems description: Contains the recorded daily/monthly data usage for each API path required: - grouping - dateRange - apiData ``` ## SDK Code Examples ```python import requests url = "https://app.unleash-instance.example.com/api/admin/metrics/traffic" querystring = {"grouping":"daily","from":"2024-01-01","to":"2024-01-31"} headers = {"Authorization": ""} response = requests.get(url, headers=headers, params=querystring) print(response.json()) ``` ```javascript const url = 'https://app.unleash-instance.example.com/api/admin/metrics/traffic?grouping=daily&from=2024-01-01&to=2024-01-31'; const options = {method: 'GET', headers: {Authorization: ''}}; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://app.unleash-instance.example.com/api/admin/metrics/traffic?grouping=daily&from=2024-01-01&to=2024-01-31" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Authorization", "") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby require 'uri' require 'net/http' url = URI("https://app.unleash-instance.example.com/api/admin/metrics/traffic?grouping=daily&from=2024-01-01&to=2024-01-31") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Get.new(url) request["Authorization"] = '' response = http.request(request) puts response.read_body ``` ```java import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.get("https://app.unleash-instance.example.com/api/admin/metrics/traffic?grouping=daily&from=2024-01-01&to=2024-01-31") .header("Authorization", "") .asString(); ``` ```php request('GET', 'https://app.unleash-instance.example.com/api/admin/metrics/traffic?grouping=daily&from=2024-01-01&to=2024-01-31', [ 'headers' => [ 'Authorization' => '', ], ]); echo $response->getBody(); ``` ```csharp using RestSharp; var client = new RestClient("https://app.unleash-instance.example.com/api/admin/metrics/traffic?grouping=daily&from=2024-01-01&to=2024-01-31"); var request = new RestRequest(Method.GET); request.AddHeader("Authorization", ""); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = ["Authorization": ""] let request = NSMutableURLRequest(url: NSURL(string: "https://app.unleash-instance.example.com/api/admin/metrics/traffic?grouping=daily&from=2024-01-01&to=2024-01-31")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "GET" request.allHTTPHeaderFields = headers let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ```