> ## Documentation Index
> Fetch the complete documentation index at: https://docs.spikeapi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Interval Statistics

> This endpoint returns statistics calculated based on the data available for a specific time period. The data is aggregated according to the time interval specified in your request, allowing you to see trends and patterns over time. 

<Note>
Refer to the different statistics types in the [Statistics Types](/technical-references/statistics_matrix) section for more information on how the data is aggregated for each type.
</Note>

#### Coordinated Universal Time

The `/statistics/interval` endpoint uses Coordinated Universal Time (UTC) for all its calculations. This standardization ensures that data is consistent and comparable across different time zones. By using UTC, the API provides a global view of the data, which is crucial for applications that require a uniform time reference. This approach contrasts with the `/statistics/daily` endpoint, which uses the user's local timezone for calculations, offering a more personalized view.

#### Selection of Provider Source
Within a single statistics interval there can be data aggregated from one provider source only.




## OpenAPI

````yaml get /queries/statistics/interval
openapi: 3.1.0
info:
  title: Application user API
  version: 3.0.2
servers:
  - url: https://app-api.spikeapi.com/v3
security: []
paths:
  /queries/statistics/interval:
    get:
      tags:
        - Queries / Statistics
      summary: Interval Statistics
      description: >
        This endpoint returns statistics calculated based on the data available
        for a specific time period. The data is aggregated according to the time
        interval specified in your request, allowing you to see trends and
        patterns over time. 


        <Note>

        Refer to the different statistics types in the [Statistics
        Types](/technical-references/statistics_matrix) section for more
        information on how the data is aggregated for each type.

        </Note>


        #### Coordinated Universal Time


        The `/statistics/interval` endpoint uses Coordinated Universal Time
        (UTC) for all its calculations. This standardization ensures that data
        is consistent and comparable across different time zones. By using UTC,
        the API provides a global view of the data, which is crucial for
        applications that require a uniform time reference. This approach
        contrasts with the `/statistics/daily` endpoint, which uses the user's
        local timezone for calculations, offering a more personalized view.


        #### Selection of Provider Source

        Within a single statistics interval there can be data aggregated from
        one provider source only.
      operationId: getQueriesStatisticsInterval
      parameters:
        - description: Start time of the query range in UTC, inclusive
          example: '2006-01-02T15:04:05'
          explode: false
          in: query
          name: from_timestamp
          required: true
          schema:
            description: Start time of the query range in UTC, inclusive
            examples:
              - '2006-01-02T15:04:05'
              - '2006-01-02T15:04:05Z'
            format: date-time
        - description: End time of the query range in UTC, non-inclusive
          example: '2006-01-02T15:04:05'
          explode: false
          in: query
          name: to_timestamp
          required: true
          schema:
            description: End time of the query range in UTC, non-inclusive
            examples:
              - '2006-01-02T15:04:05'
              - '2006-01-02T15:04:05Z'
            format: date-time
        - description: Interval of the query
          explode: false
          in: query
          name: interval
          required: true
          schema:
            description: Interval of the query
            enum:
              - 1h
            type: string
        - description: Exclude manual metrics from the statistics
          explode: false
          in: query
          name: exclude_manual
          schema:
            default: false
            description: Exclude manual metrics from the statistics
            type: boolean
        - explode: false
          in: query
          name: types
          required: true
          schema:
            items:
              enum:
                - steps
                - distance_total
                - distance_walking
                - distance_cycling
                - distance_running
                - calories_burned_basal
                - calories_burned_active
                - calories_burned_total
                - heartrate
                - heartrate_max
                - heartrate_min
                - heartrate_resting
                - sleep_skin_temperature_deviation
                - hrv_rmssd
                - hrv_sdnn
                - duration_low_intensity
                - duration_moderate_intensity
                - duration_high_intensity
              type: string
            minItems: 1
            type: array
        - explode: false
          in: query
          name: providers
          schema:
            items:
              enum:
                - strava
                - health_connect
                - fitbit
                - garmin
                - huawei
                - dexcom
                - whoop
                - withings
                - suunto
                - apple
                - freestyle_libre
                - oura
                - polar
                - coros
                - ultrahuman
                - samsung_health_data
                - luna
                - map_my_fitness
                - application
              type: string
            type: array
        - description: Whether to include the record IDs in the response
          explode: false
          in: query
          name: include_record_ids
          schema:
            default: false
            description: Whether to include the record IDs in the response
            type: boolean
        - description: Device types to include in the statistics
          explode: false
          in: query
          name: device_types
          schema:
            description: Device types to include in the statistics
            items:
              enum:
                - unknown
                - phone
                - watch
                - scale
                - ring
                - head_mounted
                - fitness_band
                - chest_strap
                - smart_display
                - accessory
              type: string
            type: array
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StatisticsIntervalQueryOutput'
          description: OK
        '400':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/ErrorModel'
          description: Bad Request
        '401':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/ErrorModel'
          description: Unauthorized
        '404':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/ErrorModel'
          description: Not Found
        '422':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/ErrorModel'
          description: Unprocessable Entity
        '500':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/ErrorModel'
          description: Internal Server Error
      security:
        - bearer: []
components:
  schemas:
    StatisticsIntervalQueryOutput:
      additionalProperties: false
      properties:
        from_timestamp:
          examples:
            - '2006-01-02T00:00:00Z'
          format: date-time
          type: string
        statistics:
          items:
            $ref: '#/components/schemas/StatisticsIntervalQueryOutputValue'
          type:
            - array
            - 'null'
        to_timestamp:
          examples:
            - '2006-01-02T00:00:00Z'
          format: date-time
          type: string
      required:
        - from_timestamp
        - to_timestamp
        - statistics
      type: object
    ErrorModel:
      additionalProperties: false
      properties:
        detail:
          description: >-
            A human-readable explanation specific to this occurrence of the
            problem.
          examples:
            - Property foo is required but is missing.
          type: string
        errors:
          description: Optional list of individual error details
          items:
            $ref: '#/components/schemas/ErrorDetail'
          type:
            - array
            - 'null'
        instance:
          description: >-
            A URI reference that identifies the specific occurrence of the
            problem.
          examples:
            - https://example.com/error-log/abc123
          format: uri
          type: string
        status:
          description: HTTP status code
          examples:
            - 400
          format: int64
          type: integer
        title:
          description: >-
            A short, human-readable summary of the problem type. This value
            should not change between occurrences of the error.
          examples:
            - Bad Request
          type: string
        type:
          default: about:blank
          description: A URI reference to human-readable documentation for the error.
          examples:
            - https://example.com/errors/example
          format: uri
          type: string
      type: object
    StatisticsIntervalQueryOutputValue:
      additionalProperties: false
      properties:
        from_timestamp:
          examples:
            - '2006-01-02T00:00:00Z'
          format: date-time
          type: string
        record_ids:
          items:
            description: Unique identifier for a record.
            examples:
              - 12345678-1234-abcd-4321-abcdef123456
            format: uuid
            type: string
          type:
            - array
            - 'null'
        to_timestamp:
          examples:
            - '2006-01-02T00:00:00Z'
          format: date-time
          type: string
        values:
          description: Statistics values
          properties:
            activity_score:
              description: activity_score in count
              examples:
                - 83
              type: number
            calories_burned_active:
              description: calories_burned_active in kcal
              examples:
                - 1020.0991
              type: number
            calories_burned_basal:
              description: calories_burned_basal in kcal
              examples:
                - 2000.1242
              type: number
            calories_burned_total:
              description: calories_burned_total in kcal
              examples:
                - 3020.2233
              type: number
            distance_cycling:
              description: distance_cycling in meters
              examples:
                - 20091.0022
              type: number
            distance_running:
              description: distance_running in meters
              examples:
                - 12000.1014
              type: number
            distance_total:
              description: distance_total in meters
              examples:
                - 5880.7021
              type: number
            distance_walking:
              description: distance_walking in meters
              examples:
                - 1200.7022
              type: number
            duration_high_intensity:
              description: duration_high_intensity in ms
              examples:
                - 1200000
              type: number
            duration_low_intensity:
              description: duration_low_intensity in ms
              examples:
                - 9000000
              type: number
            duration_moderate_intensity:
              description: duration_moderate_intensity in ms
              examples:
                - 2400000
              type: number
            heartrate:
              description: heartrate in bpm
              examples:
                - 100
              type: number
            heartrate_max:
              description: heartrate_max in bpm
              examples:
                - 120
              type: number
            heartrate_min:
              description: heartrate_min in bpm
              examples:
                - 60
              type: number
            heartrate_resting:
              description: heartrate_resting in bpm
              examples:
                - 60
              type: number
            hrv_rmssd:
              description: hrv_rmssd in ms
              examples:
                - 45
              type: number
            hrv_sdnn:
              description: hrv_sdnn in ms
              examples:
                - 52
              type: number
            recovery_score:
              description: recovery_score in count
              examples:
                - 83
              type: number
            sleep_duration_total:
              description: sleep_duration_total in ms
              examples:
                - 3600000
              type: number
            sleep_score:
              description: sleep_score in count
              examples:
                - 70
              type: number
            sleep_skin_temperature_deviation:
              description: sleep_skin_temperature_deviation in celsius
              examples:
                - -0.13
              type: number
            steps:
              description: steps in count
              examples:
                - 10000
              type: number
            stress_score:
              description: stress_score in count
              examples:
                - 70
              type: number
          type: object
      required:
        - values
      type: object
    ErrorDetail:
      additionalProperties: false
      properties:
        location:
          description: >-
            Where the error occurred, e.g. 'body.items[3].tags' or
            'path.thing-id'
          type: string
        message:
          description: Error message text
          type: string
        value:
          description: The value at the given location
      type: object
  securitySchemes:
    bearer:
      bearerFormat: JWT
      scheme: bearer
      type: http

````