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

# List Sleep Sessions

> Returns sleep sessions (including naps).



## OpenAPI

````yaml /openapi.json get /api/v1/users/{user_id}/events/sleep
openapi: 3.1.0
info:
  title: Open Wearables API
  version: 1.0.0
servers: []
security: []
paths:
  /api/v1/users/{user_id}/events/sleep:
    get:
      tags:
        - 'External: Events'
      summary: List Sleep Sessions
      description: Returns sleep sessions (including naps).
      operationId: list_sleep_sessions_api_v1_users__user_id__events_sleep_get
      parameters:
        - name: user_id
          in: path
          required: true
          schema:
            type: string
            format: uuid
            title: User Id
        - name: start_date
          in: query
          required: true
          schema:
            type: string
            description: >-
              ISO 8601 datetime (e.g. `2023-11-07T05:31:56Z`) or Unix timestamp
              in seconds. Date-only strings (e.g. `2023-11-07`) are also
              accepted and cover the whole day, so a date-only range includes
              both boundary days.
            examples:
              - '2023-11-07T05:31:56Z'
              - '2023-11-07'
            format: date-time
            title: Start Date
          description: >-
            ISO 8601 datetime (e.g. `2023-11-07T05:31:56Z`) or Unix timestamp in
            seconds. Date-only strings (e.g. `2023-11-07`) are also accepted and
            cover the whole day, so a date-only range includes both boundary
            days.
        - name: end_date
          in: query
          required: true
          schema:
            type: string
            description: >-
              ISO 8601 datetime (e.g. `2023-11-07T05:31:56Z`) or Unix timestamp
              in seconds. Date-only strings (e.g. `2023-11-07`) are also
              accepted and cover the whole day, so a date-only range includes
              both boundary days.
            examples:
              - '2023-11-07T05:31:56Z'
              - '2023-11-07'
            format: date-time
            title: End Date
          description: >-
            ISO 8601 datetime (e.g. `2023-11-07T05:31:56Z`) or Unix timestamp in
            seconds. Date-only strings (e.g. `2023-11-07`) are also accepted and
            cover the whole day, so a date-only range includes both boundary
            days.
        - name: include
          in: query
          required: false
          schema:
            type: array
            items:
              $ref: '#/components/schemas/SleepInclude'
            title: Include
        - name: cursor
          in: query
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: Cursor
        - name: limit
          in: query
          required: false
          schema:
            type: integer
            maximum: 1000
            minimum: 1
            default: 50
            title: Limit
        - name: provider
          in: query
          required: false
          schema:
            anyOf:
              - $ref: '#/components/schemas/ProviderName'
              - type: 'null'
            title: Provider
        - name: source
          in: query
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: Source
        - name: device_model
          in: query
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: Device Model
        - name: data_source_id
          in: query
          required: false
          schema:
            anyOf:
              - type: string
                format: uuid
              - type: 'null'
            title: Data Source Id
        - name: is_nap
          in: query
          required: false
          schema:
            anyOf:
              - type: boolean
              - type: 'null'
            description: >-
              When true, return only naps; when false, only main sleep. Omit to
              return both.
            title: Is Nap
          description: >-
            When true, return only naps; when false, only main sleep. Omit to
            return both.
        - name: source_selection
          in: query
          required: false
          schema:
            anyOf:
              - enum:
                  - all
                  - per_session
                type: string
              - type: 'null'
            description: >-
              `all` returns every source's sessions. `per_session` drops a
              session when the sessions of one source ranked higher by provider,
              then device type priority, cover at least
              `SESSION_DUPLICATE_OVERLAP` of it (default 0.5); sessions nothing
              better covers stay, and equally ranked sources never hide each
              other. Source filters narrow which sessions compete. Defaults to
              `all`.
            title: Source Selection
          description: >-
            `all` returns every source's sessions. `per_session` drops a session
            when the sessions of one source ranked higher by provider, then
            device type priority, cover at least `SESSION_DUPLICATE_OVERLAP` of
            it (default 0.5); sessions nothing better covers stay, and equally
            ranked sources never hide each other. Source filters narrow which
            sessions compete. Defaults to `all`.
        - name: filter_by_priority
          in: query
          required: false
          schema:
            type: boolean
            description: Same as source_selection=per_session.
            deprecated: true
            default: false
            title: Filter By Priority
          description: Same as source_selection=per_session.
          deprecated: true
        - name: X-Open-Wearables-API-Key
          in: header
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: X-Open-Wearables-Api-Key
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PaginatedResponse_SleepSession_'
        '422':
          description: Validation Error
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/ValidationProblem'
        4XX:
          description: Client error
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        5XX:
          description: Server error
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      security:
        - OAuth2PasswordBearer: []
components:
  schemas:
    SleepInclude:
      type: string
      enum:
        - stages
      title: SleepInclude
      description: >-
        Optional expansions for sleep read models, requested via the `include`
        query parameter.
    ProviderName:
      type: string
      enum:
        - apple
        - samsung
        - garmin
        - health_connect
        - google_health
        - polar
        - suunto
        - whoop
        - strava
        - oura
        - fitbit
        - ultrahuman
        - sensorbio
        - withings
        - unknown
        - internal
      title: ProviderName
      description: Supported data providers.
    PaginatedResponse_SleepSession_:
      properties:
        data:
          items:
            $ref: '#/components/schemas/SleepSession'
          type: array
          title: Data
        pagination:
          $ref: '#/components/schemas/Pagination'
        metadata:
          $ref: '#/components/schemas/TimeseriesMetadata'
      type: object
      required:
        - data
        - pagination
        - metadata
      title: PaginatedResponse[SleepSession]
    ValidationProblem:
      description: A 422 for a request that failed validation, listing every failure.
      examples:
        - code: VALIDATION_ERROR
          detail: >-
            body.email: value is not a valid email address: An email address
            must have an @-sign. (and 1 more)
          errors:
            - loc:
                - body
                - email
              msg: >-
                value is not a valid email address: An email address must have
                an @-sign.
              type: value_error
            - loc:
                - body
                - first_name
              msg: String should have at most 100 characters
              type: string_too_long
          status: 422
          title: Unprocessable Content
      properties:
        title:
          description: HTTP status phrase
          title: Title
          type: string
        status:
          description: HTTP status code, the same as the response's
          title: Status
          type: integer
        detail:
          description: Human-readable explanation of this occurrence
          title: Detail
          type: string
        code:
          description: Machine-readable error code, stable across releases
          title: Code
          type: string
        errors:
          description: Every validation failure in the request
          items:
            $ref: '#/components/schemas/ValidationErrorItem'
          title: Errors
          type: array
      required:
        - title
        - status
        - detail
        - code
        - errors
      title: ValidationProblem
      type: object
    Problem:
      description: >-
        An error response: RFC 9457 Problem Details, served as
        ``application/problem+json``.


        ``type`` is omitted, which per the RFC means ``about:blank``: ``title``
        is the status

        phrase, and ``code`` tells errors with the same status apart.
      examples:
        - code: NOT_FOUND
          detail: 'User with ID: 123e4567-e89b-12d3-a456-426614174000 not found.'
          status: 404
          title: Not Found
      properties:
        title:
          description: HTTP status phrase
          title: Title
          type: string
        status:
          description: HTTP status code, the same as the response's
          title: Status
          type: integer
        detail:
          description: Human-readable explanation of this occurrence
          title: Detail
          type: string
        code:
          description: Machine-readable error code, stable across releases
          title: Code
          type: string
      required:
        - title
        - status
        - detail
        - code
      title: Problem
      type: object
    SleepSession:
      properties:
        id:
          type: string
          format: uuid
          title: Id
        start_time:
          type: string
          format: date-time
          title: Start Time
        end_time:
          type: string
          format: date-time
          title: End Time
        zone_offset:
          anyOf:
            - type: string
            - type: 'null'
          title: Zone Offset
        source:
          $ref: '#/components/schemas/SourceMetadata'
        duration_seconds:
          type: integer
          title: Duration Seconds
          description: >-
            Time from start_time to end_time, awake time included; for a night
            merged from several sessions, the gaps between them too
          example: 28800
        sleep_duration_seconds:
          anyOf:
            - type: integer
            - type: 'null'
          title: Sleep Duration Seconds
          description: Time asleep, awake time excluded; whole minutes, so a multiple of 60
          example: 25800
        time_in_bed_seconds:
          anyOf:
            - type: integer
            - type: 'null'
          title: Time In Bed Seconds
          description: Time in bed, awake time included; whole minutes, so a multiple of 60
          example: 28200
        efficiency_percent:
          anyOf:
            - type: number
            - type: 'null'
          title: Efficiency Percent
        stages:
          anyOf:
            - $ref: '#/components/schemas/SleepStagesSummary'
            - type: 'null'
        sleep_stage_intervals:
          anyOf:
            - items:
                $ref: '#/components/schemas/SleepStage'
              type: array
            - type: 'null'
          title: Sleep Stage Intervals
        is_nap:
          type: boolean
          title: Is Nap
          description: >-
            Whether the session is a nap: from the provider when it flags naps,
            else derived by Open Wearables (see Data types)
          default: false
        is_final:
          type: boolean
          title: Is Final
          description: >-
            Whether no more data is expected for this session; until then the
            provider may still extend it
          example: true
      type: object
      required:
        - id
        - start_time
        - end_time
        - source
        - duration_seconds
        - is_final
      title: SleepSession
    Pagination:
      properties:
        next_cursor:
          anyOf:
            - type: string
            - type: 'null'
          title: Next Cursor
          description: Cursor to fetch next page, null if no more data
          example: eyJpZCI6IjEyMzQ1Njc4OTAiLCJ0cyI6MTcwNDA2NzIwMH0
        previous_cursor:
          anyOf:
            - type: string
            - type: 'null'
          title: Previous Cursor
          description: Cursor to fetch previous page
        has_more:
          type: boolean
          title: Has More
          description: Whether more data is available
        total_count:
          anyOf:
            - type: integer
            - type: 'null'
          title: Total Count
          description: Total number of records matching the query
          example: 150
      type: object
      required:
        - has_more
      title: Pagination
    TimeseriesMetadata:
      properties:
        resolution:
          anyOf:
            - $ref: '#/components/schemas/Resolution'
            - type: 'null'
        sample_count:
          anyOf:
            - type: integer
            - type: 'null'
          title: Sample Count
        start_time:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Start Time
        end_time:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: End Time
      type: object
      title: TimeseriesMetadata
    ValidationErrorItem:
      properties:
        loc:
          description: Where the invalid value is, e.g. ['body', 'email']
          items:
            anyOf:
              - type: string
              - type: integer
          title: Loc
          type: array
        msg:
          description: What is wrong with it
          title: Msg
          type: string
        type:
          description: Pydantic error type, e.g. 'missing'
          title: Type
          type: string
      required:
        - loc
        - msg
        - type
      title: ValidationErrorItem
      type: object
    SourceMetadata:
      properties:
        provider:
          type: string
          title: Provider
          example: apple
        source:
          anyOf:
            - type: string
            - type: 'null'
          title: Source
          example: Connect
        device:
          anyOf:
            - type: string
            - type: 'null'
          title: Device
          example: iPhone15,2
        device_type:
          anyOf:
            - $ref: '#/components/schemas/DeviceType'
            - type: 'null'
          example: phone
        device_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Device Id
          example: R9ZW30ABC12
        device_name:
          anyOf:
            - type: string
            - type: 'null'
          title: Device Name
          description: >-
            Marketing name for ``device``, derived so it cannot drift from the
            raw model.
          readOnly: true
      type: object
      required:
        - provider
        - device_name
      title: SourceMetadata
    SleepStagesSummary:
      properties:
        awake_minutes:
          anyOf:
            - type: integer
            - type: 'null'
          title: Awake Minutes
        light_minutes:
          anyOf:
            - type: integer
            - type: 'null'
          title: Light Minutes
        deep_minutes:
          anyOf:
            - type: integer
            - type: 'null'
          title: Deep Minutes
        rem_minutes:
          anyOf:
            - type: integer
            - type: 'null'
          title: Rem Minutes
      type: object
      title: SleepStagesSummary
    SleepStage:
      properties:
        stage:
          $ref: '#/components/schemas/SleepStageType'
        start_time:
          type: string
          format: date-time
          title: Start Time
        end_time:
          type: string
          format: date-time
          title: End Time
      type: object
      required:
        - stage
        - start_time
        - end_time
      title: SleepStage
      description: A single continuous sleep stage interval stored inside the JSONB column.
    Resolution:
      type: string
      enum:
        - raw
        - 1min
        - 5min
        - 15min
        - 1hour
        - 1day
        - 1week
        - 1month
      title: Resolution
      description: >-
        Bucket width requested when reading time series. RAW returns stored
        samples untouched; day, week

        and month read the day aggregates instead of the samples.
    DeviceType:
      type: string
      enum:
        - watch
        - band
        - phone
        - scale
        - ring
        - tablet
        - chest_strap
        - hr_sensor
        - headphones
        - head_mounted
        - glasses
        - smart_display
        - bp_monitor
        - glucose_meter
        - thermometer
        - sleep_monitor
        - bike_computer
        - fitness_machine
        - other
        - unknown
      title: DeviceType
      description: Type of device that collected health data.
    SleepStageType:
      type: string
      enum:
        - in_bed
        - awake
        - sleeping
        - light
        - deep
        - rem
        - unknown
      title: SleepStageType
  securitySchemes:
    OAuth2PasswordBearer:
      type: oauth2
      flows:
        password:
          scopes: {}
          tokenUrl: /api/v1/auth/login

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.