# Register client usage metrics POST https://app.unleash-instance.example.com/api/client/metrics Content-Type: application/json Registers usage metrics. Stores information about how many times each flag was evaluated to enabled and disabled within a time frame. If provided, this operation will also store data on how many times each feature flag's variants were displayed to the end user. Reference: https://docs.getunleash.io/api/register-client-metrics ## OpenAPI Specification ```yaml openapi: 3.1.1 info: title: Register client usage metrics version: endpoint_client.registerClientMetrics paths: /api/client/metrics: post: operationId: register-client-metrics summary: Register client usage metrics description: >- Registers usage metrics. Stores information about how many times each flag was evaluated to enabled and disabled within a time frame. If provided, this operation will also store data on how many times each feature flag's variants were displayed to the end user. tags: - - subpackage_client parameters: - name: Authorization in: header description: Header authentication of the form `undefined ` required: true schema: type: string responses: '202': description: This response has no body. content: application/json: schema: $ref: '#/components/schemas/Client_registerClientMetrics_Response_202' '400': description: The request data does not match what we expect. content: {} requestBody: description: clientMetricsSchema content: application/json: schema: $ref: '#/components/schemas/clientMetricsSchema' components: schemas: dateSchema: oneOf: - type: string format: date-time - type: integer ClientMetricsSchemaBucketToggles: type: object properties: 'yes': type: number format: double description: How many times the toggle evaluated to true 'no': type: integer description: How many times the toggle evaluated to false variants: type: - object - 'null' additionalProperties: type: integer description: >- An object describing how many times each variant was returned. Variant names are used as properties, and the number of times they were exposed is the corresponding value (i.e. `{ [variantName]: number }`). ClientMetricsSchemaBucket: type: object properties: start: $ref: '#/components/schemas/dateSchema' description: >- The start of the time window these metrics are valid for. The window is usually 1 hour wide stop: $ref: '#/components/schemas/dateSchema' description: >- The end of the time window these metrics are valid for. The window is 1 hour wide toggles: type: object additionalProperties: $ref: '#/components/schemas/ClientMetricsSchemaBucketToggles' description: an object containing feature names with yes/no plus variant usage required: - start - stop - toggles clientMetricsSchema: type: object properties: appName: type: string description: The name of the application that is evaluating toggles instanceId: type: string description: >- A [(somewhat) unique identifier](https://docs.getunleash.io/sdks/node#advanced-usage) for the application environment: type: string description: >- Which environment the application is running in. This property was deprecated in v5. This can be determined by the API key calling this endpoint. sdkVersion: type: string description: >- An SDK version identifier. Usually formatted as "unleash-client-:" platformName: type: string description: >- The platform the application is running on. For languages that compile to binaries, this can be omitted platformVersion: type: string description: >- The version of the platform the application is running on. Languages that compile to binaries, this is expected to be the compiler version used to assemble the binary. yggdrasilVersion: type: string description: >- The semantic version of the Yggdrasil engine used by the client. If the client is using a native engine this can be omitted. specVersion: type: string description: The version of the Unleash client specification the client supports bucket: $ref: '#/components/schemas/ClientMetricsSchemaBucket' description: >- Holds all metrics gathered over a window of time. Typically 1 hour wide required: - appName - bucket Client_registerClientMetrics_Response_202: type: object properties: {} ``` ## SDK Code Examples ```python import requests url = "https://app.unleash-instance.example.com/api/client/metrics" payload = { "appName": "insurance-selector", "bucket": { "start": "1926-05-08T12:00:00.000Z", "stop": "1926-05-08T13:00:00.000Z", "toggles": { "myCoolToggle": { "yes": 25, "no": 42, "variants": { "blue": 6, "green": 15, "red": 46 } }, "myOtherToggle": { "yes": 0, "no": 100 } } } } headers = { "Authorization": "", "Content-Type": "application/json" } response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` ```javascript const url = 'https://app.unleash-instance.example.com/api/client/metrics'; const options = { method: 'POST', headers: {Authorization: '', 'Content-Type': 'application/json'}, body: '{"appName":"insurance-selector","bucket":{"start":"1926-05-08T12:00:00.000Z","stop":"1926-05-08T13:00:00.000Z","toggles":{"myCoolToggle":{"yes":25,"no":42,"variants":{"blue":6,"green":15,"red":46}},"myOtherToggle":{"yes":0,"no":100}}}}' }; 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" "strings" "net/http" "io" ) func main() { url := "https://app.unleash-instance.example.com/api/client/metrics" payload := strings.NewReader("{\n \"appName\": \"insurance-selector\",\n \"bucket\": {\n \"start\": \"1926-05-08T12:00:00.000Z\",\n \"stop\": \"1926-05-08T13:00:00.000Z\",\n \"toggles\": {\n \"myCoolToggle\": {\n \"yes\": 25,\n \"no\": 42,\n \"variants\": {\n \"blue\": 6,\n \"green\": 15,\n \"red\": 46\n }\n },\n \"myOtherToggle\": {\n \"yes\": 0,\n \"no\": 100\n }\n }\n }\n}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "") req.Header.Add("Content-Type", "application/json") 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/client/metrics") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["Authorization"] = '' request["Content-Type"] = 'application/json' request.body = "{\n \"appName\": \"insurance-selector\",\n \"bucket\": {\n \"start\": \"1926-05-08T12:00:00.000Z\",\n \"stop\": \"1926-05-08T13:00:00.000Z\",\n \"toggles\": {\n \"myCoolToggle\": {\n \"yes\": 25,\n \"no\": 42,\n \"variants\": {\n \"blue\": 6,\n \"green\": 15,\n \"red\": 46\n }\n },\n \"myOtherToggle\": {\n \"yes\": 0,\n \"no\": 100\n }\n }\n }\n}" response = http.request(request) puts response.read_body ``` ```java import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://app.unleash-instance.example.com/api/client/metrics") .header("Authorization", "") .header("Content-Type", "application/json") .body("{\n \"appName\": \"insurance-selector\",\n \"bucket\": {\n \"start\": \"1926-05-08T12:00:00.000Z\",\n \"stop\": \"1926-05-08T13:00:00.000Z\",\n \"toggles\": {\n \"myCoolToggle\": {\n \"yes\": 25,\n \"no\": 42,\n \"variants\": {\n \"blue\": 6,\n \"green\": 15,\n \"red\": 46\n }\n },\n \"myOtherToggle\": {\n \"yes\": 0,\n \"no\": 100\n }\n }\n }\n}") .asString(); ``` ```php request('POST', 'https://app.unleash-instance.example.com/api/client/metrics', [ 'body' => '{ "appName": "insurance-selector", "bucket": { "start": "1926-05-08T12:00:00.000Z", "stop": "1926-05-08T13:00:00.000Z", "toggles": { "myCoolToggle": { "yes": 25, "no": 42, "variants": { "blue": 6, "green": 15, "red": 46 } }, "myOtherToggle": { "yes": 0, "no": 100 } } } }', 'headers' => [ 'Authorization' => '', 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` ```csharp using RestSharp; var client = new RestClient("https://app.unleash-instance.example.com/api/client/metrics"); var request = new RestRequest(Method.POST); request.AddHeader("Authorization", ""); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"appName\": \"insurance-selector\",\n \"bucket\": {\n \"start\": \"1926-05-08T12:00:00.000Z\",\n \"stop\": \"1926-05-08T13:00:00.000Z\",\n \"toggles\": {\n \"myCoolToggle\": {\n \"yes\": 25,\n \"no\": 42,\n \"variants\": {\n \"blue\": 6,\n \"green\": 15,\n \"red\": 46\n }\n },\n \"myOtherToggle\": {\n \"yes\": 0,\n \"no\": 100\n }\n }\n }\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = [ "Authorization": "", "Content-Type": "application/json" ] let parameters = [ "appName": "insurance-selector", "bucket": [ "start": "1926-05-08T12:00:00.000Z", "stop": "1926-05-08T13:00:00.000Z", "toggles": [ "myCoolToggle": [ "yes": 25, "no": 42, "variants": [ "blue": 6, "green": 15, "red": 46 ] ], "myOtherToggle": [ "yes": 0, "no": 100 ] ] ] ] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://app.unleash-instance.example.com/api/client/metrics")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data 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() ``` ```python import requests url = "https://app.unleash-instance.example.com/api/client/metrics" payload = { "appName": "insurance-selector", "bucket": { "start": "1926-05-08T12:00:00.000Z", "stop": "1926-05-08T13:00:00.000Z", "toggles": { "myCoolToggle": { "yes": 25, "no": 42, "variants": { "blue": 6, "green": 15, "red": 46 } }, "myOtherToggle": { "yes": 0, "no": 100 } } } } headers = { "Authorization": "", "Content-Type": "application/json" } response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` ```javascript const url = 'https://app.unleash-instance.example.com/api/client/metrics'; const options = { method: 'POST', headers: {Authorization: '', 'Content-Type': 'application/json'}, body: '{"appName":"insurance-selector","bucket":{"start":"1926-05-08T12:00:00.000Z","stop":"1926-05-08T13:00:00.000Z","toggles":{"myCoolToggle":{"yes":25,"no":42,"variants":{"blue":6,"green":15,"red":46}},"myOtherToggle":{"yes":0,"no":100}}}}' }; 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" "strings" "net/http" "io" ) func main() { url := "https://app.unleash-instance.example.com/api/client/metrics" payload := strings.NewReader("{\n \"appName\": \"insurance-selector\",\n \"bucket\": {\n \"start\": \"1926-05-08T12:00:00.000Z\",\n \"stop\": \"1926-05-08T13:00:00.000Z\",\n \"toggles\": {\n \"myCoolToggle\": {\n \"yes\": 25,\n \"no\": 42,\n \"variants\": {\n \"blue\": 6,\n \"green\": 15,\n \"red\": 46\n }\n },\n \"myOtherToggle\": {\n \"yes\": 0,\n \"no\": 100\n }\n }\n }\n}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "") req.Header.Add("Content-Type", "application/json") 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/client/metrics") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["Authorization"] = '' request["Content-Type"] = 'application/json' request.body = "{\n \"appName\": \"insurance-selector\",\n \"bucket\": {\n \"start\": \"1926-05-08T12:00:00.000Z\",\n \"stop\": \"1926-05-08T13:00:00.000Z\",\n \"toggles\": {\n \"myCoolToggle\": {\n \"yes\": 25,\n \"no\": 42,\n \"variants\": {\n \"blue\": 6,\n \"green\": 15,\n \"red\": 46\n }\n },\n \"myOtherToggle\": {\n \"yes\": 0,\n \"no\": 100\n }\n }\n }\n}" response = http.request(request) puts response.read_body ``` ```java import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://app.unleash-instance.example.com/api/client/metrics") .header("Authorization", "") .header("Content-Type", "application/json") .body("{\n \"appName\": \"insurance-selector\",\n \"bucket\": {\n \"start\": \"1926-05-08T12:00:00.000Z\",\n \"stop\": \"1926-05-08T13:00:00.000Z\",\n \"toggles\": {\n \"myCoolToggle\": {\n \"yes\": 25,\n \"no\": 42,\n \"variants\": {\n \"blue\": 6,\n \"green\": 15,\n \"red\": 46\n }\n },\n \"myOtherToggle\": {\n \"yes\": 0,\n \"no\": 100\n }\n }\n }\n}") .asString(); ``` ```php request('POST', 'https://app.unleash-instance.example.com/api/client/metrics', [ 'body' => '{ "appName": "insurance-selector", "bucket": { "start": "1926-05-08T12:00:00.000Z", "stop": "1926-05-08T13:00:00.000Z", "toggles": { "myCoolToggle": { "yes": 25, "no": 42, "variants": { "blue": 6, "green": 15, "red": 46 } }, "myOtherToggle": { "yes": 0, "no": 100 } } } }', 'headers' => [ 'Authorization' => '', 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` ```csharp using RestSharp; var client = new RestClient("https://app.unleash-instance.example.com/api/client/metrics"); var request = new RestRequest(Method.POST); request.AddHeader("Authorization", ""); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"appName\": \"insurance-selector\",\n \"bucket\": {\n \"start\": \"1926-05-08T12:00:00.000Z\",\n \"stop\": \"1926-05-08T13:00:00.000Z\",\n \"toggles\": {\n \"myCoolToggle\": {\n \"yes\": 25,\n \"no\": 42,\n \"variants\": {\n \"blue\": 6,\n \"green\": 15,\n \"red\": 46\n }\n },\n \"myOtherToggle\": {\n \"yes\": 0,\n \"no\": 100\n }\n }\n }\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = [ "Authorization": "", "Content-Type": "application/json" ] let parameters = [ "appName": "insurance-selector", "bucket": [ "start": "1926-05-08T12:00:00.000Z", "stop": "1926-05-08T13:00:00.000Z", "toggles": [ "myCoolToggle": [ "yes": 25, "no": 42, "variants": [ "blue": 6, "green": 15, "red": 46 ] ], "myOtherToggle": [ "yes": 0, "no": 100 ] ] ] ] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://app.unleash-instance.example.com/api/client/metrics")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data 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() ```