---
name: "insertRecords"
mode: "kit"
versionRequirements:
  - { name: "HealthKit", version: "5.18.0" }
  - { name: "@ray-js/ray", version: "1.6.17" }
platform:
  - "Android"
async: true
title: "health.insertRecords - Sync data to Health Connect [Android only]"
---

## insertRecords

> [VERSION] HealthKit >= 5.18.0 | @ray-js/ray >= 1.6.17

> [PLATFORM] Android

> ⚡ **Supports Promise** — Returns a Promise when success / fail / complete callbacks are omitted.

### Description

Batch write health records to Health Connect [Android only]

### Parameters

| Property | Type | Required | Default | Since | Description |
| --- | --- | --- | --- | --- | --- |
| `request` | `string` | Yes | - | `5.18.0` | JSON array string of RecordData list |
| `complete` | `() => void` | No | - | - | Completion callback (executed on both success and failure) |
| `success` | `(params: boolean) => void` | No | - | - | Callback on successful API call |
| `fail` | `(params: Object) => void` ↓see below | No | - | - | Failure callback |

#### fail callback parameters

| Property | Type | Description |
| --- | --- | --- |
| `errorMsg` | `string` | Error message |
| `errorCode` | `string \| number` | Error code |
| `innerError` | `Object` | Error extension |

##### fail(params).innerError properties

| Property | Type | Description |
| --- | --- | --- |
| `errorCode` | `string \| number` | Error extension code |
| `errorMsg` | `string` | Error extension message |


### Error Codes

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

### Examples

#### Basic call

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

const { insertRecords } = health;

const records = JSON.stringify([{ type: 'steps', value: 1000 }]);
insertRecords({
  request: records,
  success: (result) => {
    console.log('insertRecords success', result);
  },
  fail: (error) => {
    console.log('insertRecords fail', error.errorMsg);
  },
});
```
