Sleep
This endpoint is dedicated to retrieving user sleep data, allowing for a comprehensive view of sleep patterns and quality. It offers filters for time range and includes options for sleep stages and metrics, ensuring that you can tailor the data retrieval to your specific needs.
Properties
- Name
 user_id- Type
 - string
 - Description
 UUID of the user. This must be a valid UUID that represents the user whose sleep data is being requested.
Get Sleep Data
This endpoint allows you to retrieve sleep data for a specified user. By default, it returns sleep sessions sorted in descending order.
Optional attributes
- Name
 startDate- Type
 - string
 - Description
 The start date to filter the sleep data. Must be in ISO 8601 format. Defaults to the earliest sleep record if not provided.
- Name
 endDate- Type
 - string
 - Description
 The end date to filter the sleep data. Must be in ISO 8601 format. Defaults to the most recent sleep record if not provided.
- Name
 include_stages- Type
 - boolean
 - Description
 A boolean to determine whether to include sleep stages in the response. Defaults to
falseif not specified.
- Name
 include_metrics- Type
 - boolean
 - Description
 A boolean to determine whether to include sleep metrics in the response. Defaults to
falseif not specified.
- Name
 sort- Type
 - string
 - Description
 Specifies the sort order of the sleep data, either
ascfor ascending ordescfor descending. Defaults to descending if not provided.
- Name
 page- Type
 - integer
 - Description
 The page number of results to return. Must be an integer greater than 0. Defaults to 1.
- Name
 pageSize- Type
 - integer
 - Description
 The number of results per page. Must be an integer between 1 and 10,000. Defaults to a server-defined default page size.
Request
curl -G https://api.onetwentyone.ai/api/v1/sleep/123e4567-e89b-12d3-a456-426614174000 \
  -H "Authorization: Bearer {token}" \
  -d startDate="2022-01-01" \
  -d endDate="2022-01-31" \
  -d include_stages=true \
  -d include_metrics=true \
  -d sort="asc" \
  -d page=1 \
  -d pageSize=50
Response
{
  "pagination": {
    "current_page": 1,
    "has_more": true,
    "next_page": "/api/sleep/123e4567-e89b-12d3-a456-426614174000?startDate=2022-01-01&endDate=2022-01-31&include_stages=true&include_metrics=true&page=2&pageSize=50",
    "prev_page": null
  },
  "limit": {
    "X-RateLimit-Limit": 10000,
    "X-RateLimit-Remaining": 9991,
    "X-RateLimit-Reset": 1715126400
},
  "data": [
    {
      "id": "SLEEPSESSION-UUID",
      "time_in_bed_start": "2022-01-01T22:00:00Z",
      "time_in_bed_end": "2022-01-02T06:00:00Z",
      "sleep_metric": [
        {
          "sleep_metric": "timeNightInBed",
          "value": 404.2
        },
        // More items
      ],
      "raw_sleep": [
        {
          "stage": "LIGHT",
          "start": "2022-01-01T22:12:01Z",
          "end": "2022-01-01T22:23:30Z"
        },
        {
          "stage": "DEEP",
          "start": "2022-01-01T22:23:31Z",
          "end": "2022-01-01T22:29:00Z"
        },
        // More items...
      ]
    },
    {
      "id": "SLEEPSESSION-UUID",
      "time_in_bed_start": "2022-01-02T21:12:00Z",
      "time_in_bed_end": "2022-01-03T06:22:00Z"
    }
    // More items...
  ]
}