# Webhook
Function that delivers the analyzed results by calling the desired HTTP callback URL, if the parameter is entered in the upload and session end API at [Session API](session-api), the analysis results will be delivered in the following format
# Request
## Method
`POST`
## Header
| Field | Type | Description |
| :-------- | :----- | :----------------------------------------- |
| x-api-key | String | API key used to upload data or end session |
| x-user-id | String | The user id that created the sleep session |
## Body
|
Field
|
Type
|
Description
|
|
callback\_event
|
String (`INFERENCE_COMPLETE`,`SESSION_COMPLETE`)
|
Callback event type\
`INFERENCE_COMPLETE`: If the analysis is completed within 5 or 40 minute increments\
`SESSION_COMPLETE`: The entire session analysis is complete
|
|
callback\_version
|
String\
(`V1`,`V2`,`V3`)
|
Callback version\
`V1`: Follows the callback format of [v1.0](https://docs-en.asleep.ai/v1.0/docs/callback) documentation\
`V2`: Follows the callback format of v2.0\
`V3`: Follows the callback format of the current version
|
|
callback\_data
|
Webhook Data Object
|
Webhook data
|
### Callback Data Object in case of INFERENCE\_COMPLETE
|
Field
|
Type
|
Description
|
|
user\_id
|
String
|
user id
|
|
session\_id
|
String
|
session id
|
|
seq\_num
|
Int
|
Order number of the audio data uploaded
|
|
inference\_seq\_num
|
Int
|
Number that converted seq\_num into 5 minutes increments\
e.g.) when uploading MELSPECTROGRAM, if seq\_num 39, inference\_seq\_num is 3
|
|
stage\_list
|
\[Int]
|
Sleep stage results in previous 5 minutes frame\
e.g.) if inference\_seq\_num is 6, you get back 40 values from 3 to 6
|
|
snoring\_stages
|
\[Int]
|
Snoring stage results in previous 5 minutes frame
|
```json
{
"event": "INFERENCE_COMPLETE",
"version": "V3",
"data": {
"user_id": "G-20250115025029-vLErWBfQNtnfvgDccFOQ",
"session_id": "20250115025029_fvivn",
"seq_num": 39,
"inference_seq_num": 3,
"sleep_stages": [0], // omitted
"breath_stages": null,
"snoring_stages": [0] // omitted
}
}
```
### Webhook Data Object in case of SESSION\_COMPLETE
| Field | Type | Description |
| :---- | :---------------- | :----------------------------------------------------------------------------------------------------------------------- |
| data | Sleep Data Object | The response format is the same as Get Session in the Data API, with the only difference being the addition of user\_id. |
```json
{
"event": "SESSION_COMPLETE",
"version": "V3",
"data": {
"timezone": "UTC",
"peculiarities": ["NO_BREATHING_STABILITY"],
"missing_data_ratio": 0.0,
"user_id": "G-20250115025029-vLErWBfQNtnfvgDccFOQ",
"session": {
"id": "20250115025029_fvivn",
"state": "COMPLETE",
"start_time": "2025-01-15T02:50:29+00:00",
"end_time": "2025-01-15T03:50:29+00:00",
"unexpected_end_time": null,
"created_timezone": "UTC",
"sleep_stages": [0], // omitted
"breath_stages": null,
"snoring_stages": [0] // omitted
},
"stat": {
"sleep_time": "2025-01-15T03:05:29+00:00",
"wake_time": "2025-01-15T03:26:29+00:00",
"sleep_index": 50,
"sleep_latency": 900,
"wakeup_latency": 1440,
"light_latency": 0,
"deep_latency": null,
"rem_latency": null,
"time_in_bed": 3600,
"time_in_sleep_period": 1260,
"time_in_sleep": 1080,
"time_in_wake": 180,
"time_in_light": 1080,
"time_in_deep": 0,
"time_in_rem": 0,
"time_in_stable_breath": null,
"time_in_unstable_breath": null,
"time_in_snoring": 0,
"time_in_no_snoring": 1260,
"sleep_efficiency": 0.3,
"sleep_ratio": 0.86,
"wake_ratio": 0.14,
"light_ratio": 0.86,
"deep_ratio": 0.0,
"rem_ratio": 0.0,
"stable_breath_ratio": null,
"unstable_breath_ratio": null,
"snoring_ratio": 0.0,
"no_snoring_ratio": 1.0,
"breathing_index": null,
"breathing_pattern": null,
"waso_count": 1,
"longest_waso": 180,
"sleep_cycle_count": 0,
"sleep_cycle": null,
"sleep_cycle_time": [],
"unstable_breath_count": null,
"snoring_count": 0
}
}
}
```