Overview

Sahha provides your app with realtime data samples directly from Apple Health and Google Health Connect.

Samples are an array of events and values that occur within a time period that you specify.

For example:

  • a steps sample which includes step count
  • a heartRate sample which includes beats per minute
  • a sleep sample which includes minutes spent in various sleep stages

Samples are fetched in realtime

Using the getSamples method will fetch the most up-to-date samples for a SahhaSensor.

This is very useful for monitoring the most recent changes in user activity.

For example, you can monitor changes in a user's heart rate.

If you'd like to check for new data continuously, you can call getSamples for the heart_rate sensor with a timer (for example every 5 minutes).

Limiting the Date Range of Samples

Although the getSamples method is free to use, it still requires time for the device to fetch samples.

The longer the date range you specify for this method, the longer it will take for samples to ready - potentially blocking your UI.

If you are going to call getSamples using a timer, we recommend limiting the date range for new samples to match the interval you are polling (for example every 5 minutes).


Get samples for the last hour

Using getSamples will return an array of samples for the SahhaSensor and time period you specify.

To get samples for the last hour, specify a startDateTime and endDateTime with a one hour difference.

Older samples will be at the start of the array.

Newer samples will be at the end of the array.

MyApp.swift
Swift
// Get samples for the last hour
// Add a date range
// getSamples is deprecated in iOS SDK 1.4.0. Use getBiomarkers for new code.

let today = Date()
let lastHour = Calendar.current.date(byAdding: .hour, value: -1, to: today) ?? Date()

Sahha.getSamples(
    sensor: .steps,
    startDateTime: lastHour,
    endDateTime: today)
{ error, samples in
    if let error = error {
        print(error)
    } else if samples.isEmpty == false {
        print(samples)
    }
}

Get samples for the last day

Using getSamples will return an array of samples for the SahhaSensor and time period you specify.

To get samples for the last 24 hours, specify a startDateTime and endDateTime with a one day difference.

Older samples will be at the start of the array.

Newer samples will be at the end of the array.

MyApp.swift
Swift
// Get samples for the last 24 hours
// Add a date range
// getSamples is deprecated in iOS SDK 1.4.0. Use getBiomarkers for new code.

let today = Date()
let yesterday = Calendar.current.date(byAdding: .day, value: -1, to: today) ?? Date()

Sahha.getSamples(
    sensor: .steps,
    startDateTime: yesterday,
    endDateTime: today)
{ error, samples in
    if let error = error {
        print(error)
    } else if samples.isEmpty == false {
        print(samples)
    }
}

Sample response

Samples are returned as an array of objects in JSON format.

  • Parameters:
    • id: UUID for the sample
    • type: The type of the sample (steps, sleep, etc.)
    • startDateTime: Start date-time in "yyyy-MM-dd'T'HH:mm:ss.SSZZZZZ" format ("2021-10-27T16:34:06-06:00")
    • endDateTime: End date-time in "yyyy-MM-dd'T'HH:mm:ss.SSZZZZZ" format ("2021-10-27T16:44:06-06:00")
    • value: Numerical value of the sample (100, 200, etc.)
    • unit: The unit for measuring the value (count, minute, kg, bpm, etc.)
    • source: The source which recorded the sample in com.company.app format ("com.apple.health")

For iOS and Android, samples are returned as an array of objects in SahhaSample format.

SahhaSample.swift
Swift
public struct SahhaSample: Comparable, Codable, Sendable {
    public var id: String
    public var category: String
    public var type: String
    public var value: Double
    public var unit: String
    public var startDateTime: Date
    public var endDateTime: Date
    public var recordingMethod: String
    public var source: String
    public var stats: [SahhaStat] = []
}

Array response

Samples are returned as an array of objects in JSON format.

Older samples will be at the start of the array.

Newer samples will be at the end of the array.

An example response includes these fields:

RESPONSE
JSON
[
	{
		"endDateTime": "2024-12-19T12:25:53.44+09:00",
		"source": "com.apple.health.0C1972B1-DBA3-4B25-9FE7-E9C00DF1DCE6",
		"unit": "count",
		"startDateTime": "2024-12-19T12:16:16.82+09:00",
		"value": 111,
		"type": "steps",
		"id": "4CD8C605-46CB-4349-B317-FFD984E5015A"
	},
	{
		"type": "steps",
		"source": "com.apple.health.0C1972B1-DBA3-4B25-9FE7-E9C00DF1DCE6",
		"startDateTime": "2024-12-19T12:35:09.56+09:00",
		"value": 198,
		"id": "3F16DFB3-6013-452A-95A0-EC89455F9059",
		"unit": "count",
		"endDateTime": "2024-12-19T12:40:52.96+09:00"
	},
	{
		"unit": "count",
		"id": "AA60B687-18BB-47EA-8541-D9EBE4788B82",
		"startDateTime": "2024-12-19T12:51:10.59+09:00",
		"source": "com.apple.health.0C1972B1-DBA3-4B25-9FE7-E9C00DF1DCE6",
		"value": 47,
		"endDateTime": "2024-12-19T12:56:36.07+09:00",
		"type": "steps"
	}
]

Empty response

If no samples are found for the SahhaSensor and time period you specify, you will receive an error message.

RESPONSE
JSON
"No samples found"

Using SahhaSensor

Samples are grouped by SahhaSensor type.

For example, use getSamples with the heart_rate sensor to get samples of a user's heart rate.

Choose a SahhaSensor

You must specify which SahhaSensor to use for getSamples.

SahhaSensorAndroidiOS
genderSensor Not AvailableSensor Not Available
date_of_birthSensor Not AvailableSensor Not Available
sleep✔✔
steps✔✔
floors_climbed✔✔
heart_rate✔✔
resting_heart_rate✔✔
walking_heart_rate_averageSensor Not Available✔
heart_rate_variability_rmssd✔Sensor Not Available
heart_rate_variability_sdnnSensor Not Available✔
blood_pressure_systolic✔✔
blood_pressure_diastolic✔✔
blood_glucose✔✔
vo2_max✔✔
oxygen_saturation✔✔
respiratory_rate✔✔
active_energy_burned✔✔
basal_energy_burnedSensor Not Available✔
total_energy_burned✔Sensor Not Available
basal_metabolic_rate✔Sensor Not Available
time_in_daylightSensor Not Available✔
body_temperature✔✔
basal_body_temperature✔✔
sleeping_wrist_temperatureSensor Not Available✔
height✔✔
weight✔✔
lean_body_mass✔✔
body_mass_indexSensor Not Available✔
body_fat✔✔
body_water_mass✔Sensor Not Available
bone_mass✔Sensor Not Available
waist_circumferenceSensor Not Available✔
stand_timeSensor Not Available✔
move_timeSensor Not Available✔
exercise_timeSensor Not Available✔
activity_summarySensor Not AvailableSensor Not Available
device_lockSensor Not AvailableSensor Not Available
exercise✔✔
energy_intake✔✔
water_intake✔✔
protein_intake✔✔
fat_intake✔✔
fat_saturated_intake✔✔
fat_monounsaturated_intake✔✔
fat_polyunsaturated_intake✔✔
cholesterol_intake✔✔
carbohydrate_intake✔✔
sugar_intake✔✔
fiber_intake✔✔
vitamin_a_intake✔✔
vitamin_c_intake✔✔
vitamin_d_intake✔✔
vitamin_e_intake✔✔
vitamin_k_intake✔✔
thiamin_intake✔✔
riboflavin_intake✔✔
niacin_intake✔✔
pantothenic_acid_intake✔✔
vitamin_b6_intake✔✔
biotin_intake✔✔
folate_intake✔✔
vitamin_b12_intake✔✔
calcium_intake✔✔
iron_intake✔✔
magnesium_intake✔✔
phosphorus_intake✔✔
potassium_intake✔✔
sodium_intake✔✔
zinc_intake✔✔
chloride_intake✔✔
copper_intake✔✔
manganese_intake✔✔
chromium_intake✔✔
molybdenum_intake✔✔
selenium_intake✔✔
iodine_intake✔✔
caffeine_intake✔✔
menstrual_flowSensor Not AvailableSensor Not Available
menstrual_periodSensor Not AvailableSensor Not Available
intermenstrual_bleedingSensor Not AvailableSensor Not Available
cervical_mucusSensor Not AvailableSensor Not Available
ovulation_testSensor Not AvailableSensor Not Available
sexual_activitySensor Not AvailableSensor Not Available
running_ground_contact_timeSensor Not Available✔
running_powerSensor Not Available✔
running_speedSensor Not Available✔
running_stride_lengthSensor Not Available✔
running_vertical_oscillationSensor Not Available✔
six_minute_walk_test_distanceSensor Not Available✔
stair_ascent_speedSensor Not Available✔
stair_descent_speedSensor Not Available✔
walking_asymmetry_percentageSensor Not Available✔
walking_double_support_percentageSensor Not Available✔
walking_speedSensor Not Available✔
walking_steadinessSensor Not Available✔
walking_step_lengthSensor Not Available✔
infrequent_menstrual_cyclesSensor Not AvailableSensor Not Available
irregular_menstrual_cyclesSensor Not AvailableSensor Not Available
persistent_intermenstrual_bleedingSensor Not AvailableSensor Not Available
prolonged_menstrual_periodsSensor Not AvailableSensor Not Available
contraceptiveSensor Not AvailableSensor Not Available
pregnancySensor Not AvailableSensor Not Available
pregnancy_testSensor Not AvailableSensor Not Available
progesterone_testSensor Not AvailableSensor Not Available
lactationSensor Not AvailableSensor Not Available
abdominal_crampsSensor Not AvailableSensor Not Available
acneSensor Not AvailableSensor Not Available
appetite_changesSensor Not AvailableSensor Not Available
bladder_incontinenceSensor Not AvailableSensor Not Available
bloatingSensor Not AvailableSensor Not Available
breast_painSensor Not AvailableSensor Not Available
chest_tightness_or_painSensor Not AvailableSensor Not Available
chillsSensor Not AvailableSensor Not Available
constipationSensor Not AvailableSensor Not Available
coughingSensor Not AvailableSensor Not Available
diarrheaSensor Not AvailableSensor Not Available
dizzinessSensor Not AvailableSensor Not Available
dry_skinSensor Not AvailableSensor Not Available
faintingSensor Not AvailableSensor Not Available
fatigueSensor Not AvailableSensor Not Available
feverSensor Not AvailableSensor Not Available
generalized_body_acheSensor Not AvailableSensor Not Available
hair_lossSensor Not AvailableSensor Not Available
headacheSensor Not AvailableSensor Not Available
heartburnSensor Not AvailableSensor Not Available
hot_flashesSensor Not AvailableSensor Not Available
loss_of_smellSensor Not AvailableSensor Not Available
loss_of_tasteSensor Not AvailableSensor Not Available
lower_back_painSensor Not AvailableSensor Not Available
memory_lapseSensor Not AvailableSensor Not Available
mood_changesSensor Not AvailableSensor Not Available
nauseaSensor Not AvailableSensor Not Available
night_sweatsSensor Not AvailableSensor Not Available
pelvic_painSensor Not AvailableSensor Not Available
rapid_pounding_or_fluttering_heartbeatSensor Not AvailableSensor Not Available
runny_noseSensor Not AvailableSensor Not Available
shortness_of_breathSensor Not AvailableSensor Not Available
sinus_congestionSensor Not AvailableSensor Not Available
skipped_heartbeatSensor Not AvailableSensor Not Available
sleep_changesSensor Not AvailableSensor Not Available
sore_throatSensor Not AvailableSensor Not Available
vaginal_drynessSensor Not AvailableSensor Not Available
vomitingSensor Not AvailableSensor Not Available
wheezingSensor Not AvailableSensor Not Available
nutritionSensor Not Available✔
reproductiveSensor Not AvailableSensor Not Available
symptomSensor Not AvailableSensor Not Available
Docs