Skip to main content

Health

buildfire.services.health#

The BuildFire Health Service allows plugins to query HealthKit data.

Info

This service works only on iOS devices

Requirements#

Widget#

Include healthAPI.js file in widget header right after buildfire.min.js

<head>
// ...
<script src="../../../scripts/buildfire/buildfire.min.js"></script>
<script src="../../../scripts/buildfire/components/health/healthAPI.js"></script>
</head>

Methods#

requestAuthorization()
#

buildfire.health.requestAuthorization(dataTypes, callback)

Requests read and write access to a set of data types. This method must be called before using the query methods, even if the authorization has already been given at some point in the past.

const dataTypes = [
'steps', 'distance', // Read and write permissions
{
read: ['calories'], // Read only permission
write: ['temperature'] // Write only permission
}
];
buildfire.services.health.requestAuthorization(dataTypes, err => {
if (err) console.log(err);
});

callback(err)#

Executed when the request is complete. Returns an error if something went wrong.

NameTypeDescription
errstringerror string, null when operation is successful

query()
#

buildfire.health.query(options, callback)

Fetches all the data points of a certain data type within a certain time window.

const options = {
dataType: "steps",
limit: 1000,
startDate: new Date(new Date().getTime() - (3 * 864e5)),
endDate: new Date()
};
buildfire.health.query(options, (err, data) => {
if (err) return console.error(err);
console.log(data);
});

options#

NameTypeRequiredDescriptionDefault
dataTypestringyesData type to query. See Supported Data TypesN/A
limitnumbernoSets a maximum number of returned values1000
startDateDateyesStart date for the queryN/A
endDateDateyesEnd date for the queryN/A

callback(err, results)#

Callback function executed after query is complete

NameTypeDescription
errstringError string, null when operation is successful
resultsarrayArray of results

Result entries#

NameTypeDescription
idstringUnique Identifier
unitstringThe unit of measure
valuenumberMeasured value
sourceNamestringMeasuring device name
sourceBundleIdstringMeasuring application bundleId
sourceProductTypestringMeasuring device product identifier (ex: iPhone 12,2)
sourceOSVersionstringMeasuring device OS version
startDatestringStarting date string
endDatestringEnding date string

queryAggregated()
#

buildfire.health.queryAggregated(options, callback)

Fetches all the data points of a certain data type within a certain time window. Aggregates results into buckets.

const options = {
dataType: "steps",
bucket: "day",
startDate: new Date(new Date().getTime() - (3 * 864e5)),
endDate: new Date()
};
buildfire.health.query(options, (err, data) => {
if (err) return console.error(err);
console.log(data);
});

options#

NameTypeRequiredDescriptionDefault
dataTypestringyesData type to query. See Supported Data TypesN/A
bucketstringnoTime scale to segment data byN/A
startDateDateyesStart date for the queryN/A
endDateDateyesEnd date for the queryN/A

callback(err, results)#

Callback function executed after query is complete

NameTypeDescription
errstringError string, null when operation is successful
resultsarrayArray of results. If no bucket is passed, returns only the first object

Result entries#

NameTypeDescription
unitstringThe unit of measure
valuenumberMeasured value
startDatestringStarting date string
endDatestringEnding date string

Supported data types#

The Health service supports the following data types:

Data typeUnitHealthKit equivalent
mindfulnessminHKCategoryTypeIdentifierMindfulSession
stepscountHKQuantityTypeIdentifierStepCount
stairscountHKQuantityTypeIdentifierFlightsClimbed
distancemHKQuantityTypeIdentifierDistanceWalkingRunning + HKQuantityTypeIdentifierDistanceCycling
appleExerciseTimeminHKQuantityTypeIdentifierAppleExerciseTime
flights_climbedcountHKQuantityTypeIdentifierFlightsClimbed
stand_timeminHKQuantityTypeIdentifierDietaryVitaminE
calorieskcalHKQuantityTypeIdentifierActiveEnergyBurned + HKQuantityTypeIdentifierBasalEnergyBurned
calories.activekcalHKQuantityTypeIdentifierActiveEnergyBurned
calories.basalkcalHKQuantityTypeIdentifierBasalEnergyBurned
activityactivityTypeSee Supported Activites
heightmHKQuantityTypeIdentifierHeight
weightkgHKQuantityTypeIdentifierBodyMass
bmicountHKQuantityTypeIdentifierBodyMassIndex
lean_body_masskgHKQuantityTypeIdentifierLeanBodyMass
heart_ratecount/minHKQuantityTypeIdentifierHeartRate
heart_rate.restingcount/minHKQuantityTypeIdentifierRestingHearRate
heart_rate.variabilitymsHKQuantityTypeIdentifierHeartRateVariabilitySDNN
resp_ratecount/minHKQuantityTypeIdentifierRespiratoryRate
oxygen_saturation%HKQuantityTypeIdentifierOxygenSaturation
vo2maxml/(kg * min)HKQuantityTypeIdentifierVO2Max
temperatureCelsiusHKQuantityTypeIdentifierBodyTemperature
fat_percentage%HKQuantityTypeIdentifierBodyFatPercentage
waist_circumferencemHKQuantityTypeIdentifierWaistCircumference
blood_glucosemmol/LHKQuantityTypeIdentifierBloodGlucose
insulinIUHKQuantityTypeIdentifierInsulinDelivery
blood_pressuremmHgHKCorrelationTypeIdentifierBloodPressure
blood_pressure_systolicmmHgHKQuantityTypeIdentifierBloodPressureSystolic
blood_pressure_diastolicmmHgHKQuantityTypeIdentifierBloodPressureDiastolic
genderHKCharacteristicTypeIdentifierBiologicalSex
date_of_birthHKCharacteristicTypeIdentifierDateOfBirth
mindfulnesssecHKCategoryTypeIdentifierMindfulSession
sleepN/AHKCategoryTypeIdentifierSleepAnalysis
nutritionHKCorrelationTypeIdentifierFood
nutrition.biotinmcgHKQuantityTypeIdentifierDietaryBiotin
nutrition.chloridemgHKQuantityTypeIdentifierDietaryChloride
nutrition.chromiummcgHKQuantityTypeIdentifierDietaryChromium
nutrition.coppermgHKQuantityTypeIdentifierDietaryCopper
nutrition.folatemcgHKQuantityTypeIdentifierDietaryFolate
nutrition.iodinemcgHKQuantityTypeIdentifierDietaryIodine
nutrition.magnesiummgHKQuantityTypeIdentifierDietaryMagnesium
nutrition.molybdenummgHKQuantityTypeIdentifierDietaryMolybdenum
nutrition.niacinmgHKQuantityTypeIdentifierDietaryNiacin
nutrition.pantothenic_acidmgHKQuantityTypeIdentifierDietaryPantothenicAcid
nutrition.phosphorusmgHKQuantityTypeIdentifierDietaryPhosphorus
nutrition.riboflavinmgHKQuantityTypeIdentifierDietaryRiboflavin
nutrition.seleniummcgHKQuantityTypeIdentifierDietarySelenium
nutrition.thiaminmgHKQuantityTypeIdentifierDietaryThiamin
nutrition.vitamin_B6mgHKQuantityTypeIdentifierDietaryVitaminB6
nutrition.vitamin_B12mcgHKQuantityTypeIdentifierDietaryVitaminB12
nutrition.vitamin_DmcgHKQuantityTypeIdentifierDietaryVitaminD
nutrition.vitamin_EmgHKQuantityTypeIdentifierDietaryVitaminE
nutrition.vitamin_KmcgHKQuantityTypeIdentifierDietaryVitaminK
nutrition.zincmgHKQuantityTypeIdentifierDietaryZinc
nutrition.calorieskcalHKQuantityTypeIdentifierDietaryEnergyConsumed
nutrition.fat.totalgHKQuantityTypeIdentifierDietaryFatTotal
nutrition.fat.saturatedgHKQuantityTypeIdentifierDietaryFatSaturated
nutrition.fat.polyunsaturatedgHKQuantityTypeIdentifierDietaryFatPolyunsaturated
nutrition.fat.monounsaturatedgHKQuantityTypeIdentifierDietaryFatMonounsaturated
nutrition.cholesterolmgHKQuantityTypeIdentifierDietaryCholesterol
nutrition.sodiummgHKQuantityTypeIdentifierDietarySodium
nutrition.potassiummgHKQuantityTypeIdentifierDietaryPotassium
nutrition.carbs.totalgHKQuantityTypeIdentifierDietaryCarbohydrates
nutrition.dietary_fibergHKQuantityTypeIdentifierDietaryFiber
nutrition.sugargHKQuantityTypeIdentifierDietarySugar
nutrition.proteingHKQuantityTypeIdentifierDietaryProtein
nutrition.vitamin_amcg (HK), IU (GF)HKQuantityTypeIdentifierDietaryVitaminA
nutrition.vitamin_cmgHKQuantityTypeIdentifierDietaryVitaminC
nutrition.calciummgHKQuantityTypeIdentifierDietaryCalcium
nutrition.ironmgHKQuantityTypeIdentifierDietaryIron
nutrition.watermlHKQuantityTypeIdentifierDietaryWater
nutrition.caffeinegHKQuantityTypeIdentifierDietaryCaffeine

Activities#

The following activities are supported. Pass the Activity Name as dataType to query or queryAggregated.

activity nameHealthKit equivalent
archeryHKWorkoutActivityTypeArchery
badmintonHKWorkoutActivityTypeBadminton
barreHKWorkoutActivityTypeBarre
baseballHKWorkoutActivityTypeBaseball
basketballHKWorkoutActivityTypeBasketball
bikingHKWorkoutActivityTypeCycling
biking.handHKWorkoutActivityTypeHandCycling
biking.mountainHKWorkoutActivityTypeCycling
biking.roadHKWorkoutActivityTypeCycling
biking.spinningHKWorkoutActivityTypeCycling
biking.stationaryHKWorkoutActivityTypeCycling
biking.utilityHKWorkoutActivityTypeCycling
bowlingHKWorkoutActivityTypeBowling
boxingHKWorkoutActivityTypeBoxing
cricketHKWorkoutActivityTypeCricket
cooldownHKWorkoutActivityTypeCooldown
core_trainingHKWorkoutActivityTypeCoreTraining
crossfitHKWorkoutActivityTypeCrossTraining
curlingHKWorkoutActivityTypeCurling
dancingHKWorkoutActivityTypeCardioDance
dancing.socialHKWorkoutActivityTypeSocialDance
disc_sportsHKWorkoutActivityTypeDiscSports
divingHKWorkoutActivityTypeWaterSports
ellipticalHKWorkoutActivityTypeElliptical
fencingHKWorkoutActivityTypeFencing
fitness_gamingHKWorkoutActivityTypeFitnessGaming
fishingHKWorkoutActivityTypeFishing
flexibilityHKWorkoutActivityTypeFlexibility
football.americanKWorkoutActivityTypeAmericanFootball
football.australianHKWorkoutActivityTypeAustralianFootball
football.soccerHKWorkoutActivityTypeSoccer
functional_strengthHKWorkoutActivityTypeFunctionalStrengthTraining
golfHKWorkoutActivityTypeGolf
gymnasticsHKWorkoutActivityTypeGymnastics
handballKWorkoutActivityTypeHandball
interval_training.high_intensityHKWorkoutActivityTypeHighIntensityIntervalTraining
hikingHKWorkoutActivityTypeHiking
hockeyHKWorkoutActivityTypeHockey
horseback_ridingHKWorkoutActivityTypeEquestrianSports
huntingHKWorkoutActivityTypeHunting
ice_skatingHKWorkoutActivityTypeSkatingSports
interval_trainingHKWorkoutActivityTypeHighIntensityIntervalTraining
jump_ropeHKWorkoutActivityTypeJumpRope
kayakingHKWorkoutActivityTypePaddleSports
kick_scooterHKWorkoutActivityTypeCycling
kickboxingHKWorkoutActivityTypeKickboxing
lacrosseHKWorkoutActivityTypeLacrosse
martial_artsHKWorkoutActivityTypeMartialArts
meditationHKWorkoutActivityTypeMindAndBody
martial_arts.mixedHKWorkoutActivityTypeMartialArts
mixed_metabolic_cardioHKWorkoutActivityTypeMixedCardio
activity nameHealthKit equivalent
otherHKWorkoutActivityTypeOther
paddle_sportsHKWorkoutActivityTypePaddleSports
pilatesHKWorkoutActivityTypePilates
playHKWorkoutActivityTypePlay
pickleballHKWorkoutActivityTypePickleball
preparation_and_recoveryHKWorkoutActivityTypePreparationAndRecovery
racquetballHKWorkoutActivityTypeRacquetball
rock_climbingHKWorkoutActivityTypeClimbing
rowingHKWorkoutActivityTypeRowing
rowing.machineHKWorkoutActivityTypeRowing
rugbyHKWorkoutActivityTypeRugby
runningHKWorkoutActivityTypeRunning
running.joggingHKWorkoutActivityTypeRunning
running.sandHKWorkoutActivityTypeRunning
running.treadmillHKWorkoutActivityTypeRunning
sailingHKWorkoutActivityTypeSailing
scuba_divingHKWorkoutActivityTypeWaterSports
skateboardingHKWorkoutActivityTypeSkatingSports
skatingHKWorkoutActivityTypeSkatingSports
skating.crossHKWorkoutActivityTypeSkatingSports
skating.indoorHKWorkoutActivityTypeSkatingSports
skating.inlineHKWorkoutActivityTypeSkatingSports
skiingHKWorkoutActivityTypeSnowSports
skiing.back_countryHKWorkoutActivityTypeSnowSports
skiing.cross_countryHKWorkoutActivityTypeCrossCountrySkiing
skiing.downhillHKWorkoutActivityTypeDownhillSkiing
skiing.kiteHKWorkoutActivityTypeSnowSports
skiing.rollerHKWorkoutActivityTypeSnowSports
sleddingHKWorkoutActivityTypeSnowSports
sleepHKCategoryValueSleepAnalysisAsleep
sleep.lightHKCategoryValueSleepAnalysisAsleep
sleep.deepHKCategoryValueSleepAnalysisAsleep
sleep.remHKCategoryValueSleepAnalysisAsleep
sleep.inBedHKCategoryValueSleepAnalysisInBed
sleep.awakeHKCategoryValueSleepAnalysisAwake
snowboardingHKWorkoutActivityTypeSnowboarding
snowmobileHKWorkoutActivityTypeSnowSports
snowshoeingHKWorkoutActivityTypeSnowSports
snow_sportsHKWorkoutActivityTypeSnowSports
softballHKWorkoutActivityTypeSoftball
squashHKWorkoutActivityTypeSquash
stairsHKWorkoutActivityTypeStairs
stair_climbingHKWorkoutActivityTypeStairClimbing
stair_climbing.machineHKWorkoutActivityTypeStepTraining
standup_paddleboardingHKWorkoutActivityTypePaddleSports
strength_trainingHKWorkoutActivityTypeTraditionalStrengthTraining
surfingHKWorkoutActivityTypeSurfingSports
swimmingHKWorkoutActivityTypeSwimming
swimming.poolHKWorkoutActivityTypeSwimming
swimming.open_waterHKWorkoutActivityTypeSwimming
table_tennisHKWorkoutActivityTypeTableTennis
tai_chiHKWorkoutActivityTypeTaiChi
tennisHKWorkoutActivityTypeTennis
track_and_fieldHKWorkoutActivityTypeTrackAndField
volleyballHKWorkoutActivityTypeVolleyball
volleyball.beachHKWorkoutActivityTypeVolleyball
volleyball.indoorHKWorkoutActivityTypeVolleyball
wakeboardingHKWorkoutActivityTypeWaterSports
walkingHKWorkoutActivityTypeWalking
walking.fitnessHKWorkoutActivityTypeWalking
walking.nordicHKWorkoutActivityTypeWalking
walking.treadmillHKWorkoutActivityTypeWalking
walking.strollerHKWorkoutActivityTypeWalking
water_fitnessHKWorkoutActivityTypeWaterFitness
water_poloHKWorkoutActivityTypeWaterPolo
water_sportsHKWorkoutActivityTypeWaterSports
weightliftingHKWorkoutActivityTypeTraditionalStrengthTraining
wheelchairHKWorkoutActivityTypeWheelchairRunPace
wheelchair.walkpaceHKWorkoutActivityTypeWheelchairWalkPace
wheelchair.runpaceHKWorkoutActivityTypeWheelchairRunPace
windsurfingHKWorkoutActivityTypeWaterSports
wrestlingHKWorkoutActivityTypeWrestling
yogaHKWorkoutActivityTypeYoga