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

## readQuantityDataWithType

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

> [PLATFORM] iOS

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

### Method signature

```typescript
readQuantityDataWithType(params: Object)
```

### Description

Read Quantity health data by type and time range [iOS only]

### Parameters

| Property | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `permissions` | `string[]` | No | - | 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 | - | 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 | - | 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 | - | Write permission type (used by the API for checking write permission). See the enumeration list below for specific values |
| `value` | `number` | No | - | Value to write (the specific measurement for Quantity or Category data) |
| `unitType` | `string` | No | - | 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 | - | Start time, timestamp in seconds |
| `endTime` | `number` | No | - | End time, timestamp in seconds |
| `type` | `number` | No | - | Data type to read/write (used by the read/write APIs). See the enumeration list below for specific values |
| `complete` | `() => void` | No | - | Completion callback (executed on both success and failure) |
| `success` | `(params: Object) => void` ↓see below | No | - | Callback on successful API call |
| `fail` | `(params: Object) => void` ↓see below | No | - | Failure callback |

#### success callback parameters

| Property | Type | Since | Description |
| --- | --- | --- | --- |
| `value` | `Record<string, any>[]` | `5.18.4` | Data read; an array in which each item is a dictionary, defined as follows: value: Integer The value read; meaning varies by type—see Apple’s official documentation startDate: Double Start timestamp of the entry endDate: Double End timestamp of the entry |

#### 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 |
| --- | --- |
| `1` | AppleHealthParamsError |

### Examples

#### Read weight data for a specified time range

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

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

health.readQuantityDataWithType({
  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);
  },
});
```
