List Multiple Sessions

You can request a list of sleep sessions for a specific user.

1. Request

1.1 URL

GET https://api.asleep.ai/data/v1/sessions

1.2 Header

FieldTypeRequiredDefaultDescription
x-api-keyStringO-API Key
x-user-idStringO-Issued user id
timezoneStringXUTCReturn the analysis results in the timezone specified by the header. For example, UTC, Asia/Seoul

1.3 Query parameter

  • "date_gte, date_lte, order_by" are based on the session_start_time.
FieldTypeRequiredDefaultDescription
date_gteString (YYYY-MM-DD)X-Return sessions that are greater than or equal to date_gte based on the timezone in the header
date_lteString (YYYY-MM-DD)X-Return sessions that are less than or equal to date_lte based on the timezone in the header
order_byString (ASCor DESC)XDESCDESC: Sort in descending order
ASC: Sort in ascending order
offsetIntX0Number of sessions to skip
limitInt (Integer of 0~100)X20Number of sessions to receive
Max value is 100

Example

curl "https://api.asleep.ai/data/v1/sessions?date_gte=2022-01-01&offset=10&limit=10&order_by=ASC" -XGET \
  -H "x-api-key: <YOUR_API_KEY>" \
  -H "x-user-id: <USER_ID>"

2. Response

2.1 200 OK

  • Successful session list retrieval

2.1.1 Body (result field)

FieldTypeDescription
timezoneStringTimezone
sleep_session_listList of Sleep Session ObjectsList of session data

2.1.2 Sleep Session Object

if state == OPEN: session_end_time is null

FieldTypeDescription
session_idStringSession ID
stateString (OPEN,CLOSED,COMPLETE)Session state
OPEN: In-progress session, audio upload is possible
CLOSED: Session has been closed, audio file upload is not possible. Analysis of the uploaded sleep audio is ongoing
COMPLETE: Session has been closed and all sleep analysis is completed
session_start_timeString (YYYY-MM-DDThh:mm:ss+-hh:mm)Session start time
Example) 2022-08-01T01:31:17+09:00 (for Asia/Seoul timezone in the request)
session_end_timeString (YYYY-MM-DDThh:mm:ss+-hh:mm)?Session end time
Example) 2022-08-01T01:31:17+09:00 (for Asia/Seoul timezone in the request)
created_timezoneStringTimezone of session creation (Timezone List)
unexpected_end_timeString(YYYY-MM-DDThh:mm:ss+-hh:mm)?If a session fails to proceed and terminate properly due to app crashes or similar issues, and the client later ends the session with an unexpected parameter set to 1, the time at which this happens is recorded. In this case, the "end_time" is calculated based on the sequence number of the last uploaded audio file. Therefore, if "end_time" is not null, it indicates an abnormal session.
last_received_seq_numInt?Sequence number of the last uploaded audio file
time_in_bedInt (seconds)?Time spent in bed

2.2 400 Bad Request

  • Invalid timezone is provided
{
	"detail": "The invalid timezone is provided"
}