---
name: "saveQuantityDataSync"
mode: "kit"
versionRequirements:
  - { name: "HealthKit", version: "5.18.3" }
  - { name: "@ray-js/ray", version: "1.6.17" }
platform:
  - "iOS"
title: "health.saveQuantityDataSync - Write Quantity data [iOS only]"
---

## saveQuantityDataSync

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

> [PLATFORM] iOS

### Description

Write health data of type Quantity (with start/end time) [iOS only]

### Parameters

| Property | Type | Required | Default | Since | Description |
| --- | --- | --- | --- | --- | --- |
| `permissions` | `string[]` | No | - | `5.18.0` | Permission types (used by the API that requests read/write permissions). See the enumeration list below for specific values, e.g., ["1","2"] |
| `readPermissions` | `string[]` | No | - | `5.18.0` | Read permission types (used by the API that checks whether the user has previously authorized). See the enumeration list below for specific values, e.g., ["1","2"] |
| `writePermissions` | `string[]` | No | - | `5.18.0` | Write permission types (used by the API that checks whether the user has previously authorized). See the enumeration list below for specific values, e.g., ["1","2"] |
| `writePermission` | `number` | No | - | `5.18.0` | Write permission type (used by the API for checking write permission). See the enumeration list below for specific values |
| `value` | `number` | No | - | `5.18.0` | Value to write (the specific measurement for Quantity or Category data) |
| `unitType` | `string` | No | - | `5.18.0` | Unit to pass in, e.g., "mg/dL", "g", "cm", "count". Required when querying or writing Quantity data. For units corresponding to each data type, refer to Apple’s official HKTypeIdentifiers.h file |
| `startTime` | `number` | No | - | `5.18.0` | Start time, timestamp in seconds |
| `endTime` | `number` | No | - | `5.18.0` | End time, timestamp in seconds |
| `type` | `number` | No | - | `5.18.0` | Data type to read/write (used by the read/write APIs). See the enumeration list below for specific values |

### Error Codes

| Error Code | Error Message |
| --- | --- |
| `1` | AppleHealthParamsError |
| `2` | AppleHealthNoPermission |

### Examples

#### Write weight data at a specified time

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

const endTime = Math.floor(Date.now() / 1000);
const startTime = endTime - 60 * 60;

health.saveQuantityData({
  permissions: ["4"],
  readPermissions: ["4"],
  writePermissions: ["4"],
  writePermission: 4,
  value: 65.5,
  unitType: "kg",
  startTime,
  endTime,
  type: 4,
  success: data => {
    console.log(data);
  },
  fail: error => {
    console.error(error);
  },
});
```
