insertRecords(params: Object)

Requires:
HealthKit≥5.18.0@ray-js/ray≥1.6.17
Platforms:
Android
import { health } from '@ray-js/ray';

const { insertRecords } = health;

// Promise usage
try {
  const res = await insertRecords({ ...params });
  console.log(res);
} catch (err) {
  console.log(err.errorMsg);
}

Description

Batch write health records to Health Connect [Android only]

Parameters

PropertyTypeRequiredDescription
requeststringYesJSON array string of RecordData list
complete() => voidNoCompletion callback (executed on both success and failure)
NoCallback on successful API call
fail(params: Object) => voidNoFailure callback
fail callback parameters
PropertyTypeDescription
errorMsgstringError message
errorCodestring | numberError code
Error extension

Return Value

None

Error Code

Error CodeError Message
-1001Unsupported phone OS version
-1002Data conversion error
-1003No data
-1004Failed to submit to Health Connect
-1005Service error. Please check that Health Connect has auto-start enabled and is not restricted by power management

Examples

Batch write Health Connect weight records

import { health } from '@ray-js/ray'

health.insertRecords({
  request: JSON.stringify([
    {
      dpCode: "weight",
      time: Date.now(),
      devId: "vdev123",
      data: 65.5,
    },
  ]),
  success: data => {
    console.log(data);
  },
  fail: error => {
    console.error(error);
  },
});