despia() call.
HealthKit is iOS only. Always gate calls behind an
isDespiaIOS check so the feature degrades gracefully in a browser or on Android.Installation
- Bundle
- CDN
How it works
Pass areadhealthkit:// URL with an identifier and optional days parameter. Despia requests permission, fetches the data, and returns it via healthkitResponse.
Read
Quantity types
Use any validHKQuantityTypeIdentifier to read numeric health metrics such as steps, heart rate, distance, or body mass.
Sleep data
Sleep analysis usesHKCategoryTypeIdentifierSleepAnalysis. Each record includes a label with the sleep stage (inBed, awake, core, deep, rem, or asleep) alongside startDate and endDate.
Workouts
UseHKWorkoutTypeIdentifier to fetch workout sessions. Each record includes activityType (e.g. running, yoga, hiit), duration in seconds, calories, and distance in meters.
Characteristics
Characteristics such as date of birth, biological sex, and blood type are static values. They are returned as a plain string rather than an array.HKCharacteristicTypeIdentifierDateOfBirth, HKCharacteristicTypeIdentifierBiologicalSex, HKCharacteristicTypeIdentifierBloodType, HKCharacteristicTypeIdentifierFitzpatrickSkinType.
Write
Usewritehealthkit:// to save a numeric value to HealthKit. The format is writehealthkit://IdentifierString//Value. Writing adds to existing data rather than replacing it.
Realtime updates
The observer system fires a webhook POST to your server whenever HealthKit data changes. Pass a comma-separated list of identifiers, a delivery frequency, and your server URL.Parameters
| Parameter | Required | Description |
|---|---|---|
types | Yes | Comma-separated list of HealthKit identifiers to observe |
frequency | No | One of immediate, hourly, daily, weekly. Defaults to immediate |
server | Yes | Full URL of the endpoint to receive webhook POSTs |
Webhook payload
Your server receives aPOST with Content-Type: application/json on every update. The data object contains one key per observed type, each holding an array of the most recent records (last 1 day).
Payload fields
| Field | Type | Description |
|---|---|---|
event | string | Always healthkit:update |
userId | string | Device ID, consistent across all events from the same device |
timestamp | string | ISO 8601 timestamp of when the webhook was sent |
data | object | One key per observed type, each containing an array of records |
data follows the same shape as a standard read response for that type. Quantity types include date, value, and unit. Category types include startDate, endDate, value, and label. Workout records include date, activityType, duration, calories, and distance.
Stopping observers
Passall to stop every active observer or a comma-separated list for specific types. Awaiting with ["observingHealthKit"] returns the updated active types after the call resolves.
Resources
NPM Package
despia-native