# Get consumption metric with retention data points

- Operation ID: `generateDailyRetentionDataPointsStats`
- HTTP method: `POST`
- Path: `/business-profile-service/organizations/usage/stats/retentionDataPoints`
- [Human-readable API reference](https://hub.synerise.com/api-reference/organizations#tag/Consumption/operation/generateDailyRetentionDataPointsStats)

## Self-contained OpenAPI method

The fenced document below contains this method's documentation and all of its local references. It is self-contained; no category or master specification fetch is required.

```yaml
openapi: 3.0.0
info:
  title: Synerise Public API
  version: 1.9.1
paths:
  /business-profile-service/organizations/usage/stats/retentionDataPoints:
    post:
      operationId: generateDailyRetentionDataPointsStats
      summary: Get consumption metric with retention data points
      description: |
        Retrieve the number of events kept in the database, listed by day. This includes events saved in the past, which currently exist in the database according to their retention period. 

        You can limit the metric to particular workspaces and event types (actions).


        ---

        **API consumers:** <a href="/api-reference/authorization?tag=Authorization&amp;operationId=userLogin" target="_blank" rel="noopener">Synerise User</a>, <span title="Contact support">Organization</span>
      security:
        - JWT: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                from:
                  type: string
                  example: 2025-05-29
                  description: First day to retrieve, in `YYYY-MM-DD` format
                to:
                  type: string
                  example: 2025-05-30
                  description: Last day to retrieve, in `YYYY-MM-DD` format
                actions:
                  type: array
                  description: You can limit the events added to the report. Without this parameter, all events are included.
                  items:
                    type: string
                    example: page.visit
                bpGuids:
                  type: array
                  description: You can limit the workspaces added to the report. Without this parameter, all workspaces in the organization are included.
                  items:
                    type: string
                    format: uuid
                    example: 34eea35e-3ac4-44f4-95b5-fd00a3b45eff
              required:
                - from
                - to
      responses:
        "200":
          description: Statistics of retention events for the specified date range
          content:
            application/json:
              schema:
                type: object
                properties:
                  dailyUsageStatistics:
                    type: object
                    description: Statistics for individual days
                    properties:
                      day:
                        type: string
                        format: date
                        description: Date of the data in this object
                      events:
                        type: object
                        description: The top 5 most popular event types. The keys in the object are action names.
                        additionalProperties:
                          type: integer
                          description: The number of events
                      other:
                        type: integer
                        description: The number of events which were not included in the top 5 from `events`
                      total:
                        type: integer
                        description: The total number of events
                      totalWeight:
                        type: number
                        format: double
                        nullable: true
                        description: The total weight generated by weight-eligible actions on this day (fractional). Present only when the request's `actions` include at least one weight-eligible action; otherwise omitted.
                      weights:
                        type: object
                        nullable: true
                        description: The weight generated per weight-eligible action (fractional). The keys in the object are action names. Present only when the request's `actions` include at least one weight-eligible action; otherwise omitted.
                        additionalProperties:
                          type: number
                          format: double
                          description: The weight generated by this action
                  eventsAverage:
                    type: object
                    description: The average number of top 5 most popular events kept in the database, calculated from all the requested days.
                    additionalProperties:
                      type: integer
                      description: The average number of events
                  averageAll:
                    type: integer
                    description: The average number of all events kept in the database on all the requested days.
                  averageOther:
                    type: integer
                    description: The average number of events kept in the databse on all the requested days, other than the top 5 events from `eventsAverage`
        "401":
          description: "Unauthorized: wrong consumer scope; token missing/expired/invalid; invalid API key; etc."
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: integer
                    description: HTTP status of the response
                  error:
                    type: string
                    description: Synerise error code. See [error reference](https://developers.synerise.com/errors.html).
                  message:
                    type: string
                    description: Description of the problem
                  timestamp:
                    type: string
                    format: date-time
                    description: Time when the error occurred
        "403":
          description: "Unauthorized: insufficient permissions."
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: integer
                    description: HTTP status of the response
                  error:
                    type: string
                    description: Synerise error code. See [error reference](https://developers.synerise.com/errors.html).
                  message:
                    type: string
                    description: Description of the problem
                  timestamp:
                    type: string
                    format: date-time
                    description: Time when the error occurred
        4xx:
          description: Request failed. See response for details.
          content:
            application/json:
              schema:
                type: object
                required:
                  - message
                  - timestamp
                properties:
                  httpStatus:
                    type: integer
                    description: HTTP status of the response
                  errorCode:
                    type: string
                    description: Synerise error code. See [error reference](https://developers.synerise.com/errors.html).
                  timestamp:
                    type: string
                    format: date-time
                    description: Time when the error occurred
                  message:
                    type: string
                    description: Description of the problem
                  traceId:
                    type: string
                    description: Trace ID for troubleshooting
                  errors:
                    type: array
                    description: Details of the problems
                    items:
                      type: object
                      properties:
                        errorCode:
                          type: string
                          description: Synerise error code. See [error reference](https://developers.synerise.com/errors.html).
                        message:
                          type: string
                          description: Description of the problem
                        details:
                          type: object
                          description: Details of the problem, if applicable.
                        source:
                          type: object
                          description: Properties that caused a problem, if applicable.
                          properties:
                            parameter:
                              type: string
                              description: The name of the property that caused an error
      tags:
        - Consumption
      x-snr-doc-urls:
        - /api-reference/organizations#tag/Consumption/operation/generateDailyRetentionDataPointsStats
      x-codeSamples:
        - lang: cURL
          label: cURL
          source: |-
            curl --request POST \
              --url https://api.synerise.com/business-profile-service/organizations/usage/stats/retentionDataPoints \
              --header 'Authorization: Bearer REPLACE_BEARER_TOKEN' \
              --header 'content-type: application/json' \
              --data '{"from":"2025-05-29","to":"2025-05-30","actions":["page.visit"],"bpGuids":["34eea35e-3ac4-44f4-95b5-fd00a3b45eff"]}'
        - lang: Python
          label: Python
          source: |-
            import http.client

            conn = http.client.HTTPSConnection("api.synerise.com")

            payload = "{\"from\":\"2025-05-29\",\"to\":\"2025-05-30\",\"actions\":[\"page.visit\"],\"bpGuids\":[\"34eea35e-3ac4-44f4-95b5-fd00a3b45eff\"]}"

            headers = {
                'Authorization': "Bearer REPLACE_BEARER_TOKEN",
                'content-type': "application/json"
                }

            conn.request("POST", "/business-profile-service/organizations/usage/stats/retentionDataPoints", payload, headers)

            res = conn.getresponse()
            data = res.read()

            print(data.decode("utf-8"))
        - lang: JavaScript
          label: JavaScript
          source: |-
            const data = JSON.stringify({
              "from": "2025-05-29",
              "to": "2025-05-30",
              "actions": [
                "page.visit"
              ],
              "bpGuids": [
                "34eea35e-3ac4-44f4-95b5-fd00a3b45eff"
              ]
            });

            const xhr = new XMLHttpRequest();
            xhr.withCredentials = true;

            xhr.addEventListener("readystatechange", function () {
              if (this.readyState === this.DONE) {
                console.log(this.responseText);
              }
            });

            xhr.open("POST", "https://api.synerise.com/business-profile-service/organizations/usage/stats/retentionDataPoints");
            xhr.setRequestHeader("Authorization", "Bearer REPLACE_BEARER_TOKEN");
            xhr.setRequestHeader("content-type", "application/json");

            xhr.send(data);
        - lang: Node.js
          label: Node.js
          source: |-
            const http = require("https");

            const options = {
              "method": "POST",
              "hostname": "api.synerise.com",
              "port": null,
              "path": "/business-profile-service/organizations/usage/stats/retentionDataPoints",
              "headers": {
                "Authorization": "Bearer REPLACE_BEARER_TOKEN",
                "content-type": "application/json"
              }
            };

            const req = http.request(options, function (res) {
              const chunks = [];

              res.on("data", function (chunk) {
                chunks.push(chunk);
              });

              res.on("end", function () {
                const body = Buffer.concat(chunks);
                console.log(body.toString());
              });
            });

            req.write(JSON.stringify({
              from: '2025-05-29',
              to: '2025-05-30',
              actions: ['page.visit'],
              bpGuids: ['34eea35e-3ac4-44f4-95b5-fd00a3b45eff']
            }));
            req.end();
        - lang: PHP
          label: PHP
          source: |-
            <?php

            $request = new HttpRequest();
            $request->setUrl('https://api.synerise.com/business-profile-service/organizations/usage/stats/retentionDataPoints');
            $request->setMethod(HTTP_METH_POST);

            $request->setHeaders([
              'Authorization' => 'Bearer REPLACE_BEARER_TOKEN',
              'content-type' => 'application/json'
            ]);

            $request->setBody('{"from":"2025-05-29","to":"2025-05-30","actions":["page.visit"],"bpGuids":["34eea35e-3ac4-44f4-95b5-fd00a3b45eff"]}');

            try {
              $response = $request->send();

              echo $response->getBody();
            } catch (HttpException $ex) {
              echo $ex;
            }
        - lang: Java
          label: Java
          source: |-
            HttpResponse<String> response = Unirest.post("https://api.synerise.com/business-profile-service/organizations/usage/stats/retentionDataPoints")
              .header("Authorization", "Bearer REPLACE_BEARER_TOKEN")
              .header("content-type", "application/json")
              .body("{\"from\":\"2025-05-29\",\"to\":\"2025-05-30\",\"actions\":[\"page.visit\"],\"bpGuids\":[\"34eea35e-3ac4-44f4-95b5-fd00a3b45eff\"]}")
              .asString();
servers:
  - description: Microsoft Azure EU
    url: https://api.synerise.com
  - description: Microsoft Azure USA
    url: https://api.azu.synerise.com
  - description: Google Cloud Platform
    url: https://api.geb.synerise.com
tags:
  - name: Consumption
components:
  securitySchemes:
    JWT:
      type: http
      scheme: bearer
      description: |-
        JWT Bearer token. The header looks like this: `Bearer {JWT}`

        Remember to include the space between 'Bearer' and the token.

        Generate a token via the **Authorization** endpoints.
```
