---
title: "Ingest a batch of health-platform samples for the current user (Apple HealthKit / Google Health Connect). Stores in health_samples, upserts sync anchors and device-connection rows, invalidates the capabilities cache. Up to 500 samples per request — clients paginate larger backfills. Premium-only."
method: POST
path: "/api/health/sync"
tags: ["Health"]
---

# Ingest a batch of health-platform samples for the current user (Apple HealthKit / Google Health Connect). Stores in health_samples, upserts sync anchors and device-connection rows, invalidates the capabilities cache. Up to 500 samples per request — clients paginate larger backfills. Premium-only.

`POST /api/health/sync`

## Request

- Base URL: `https://api.rewritelifestyle.ai` (the document declares no server; this is the origin it was published from)
- URL: `https://api.rewritelifestyle.ai/api/health/sync`
- Auth: HTTP bearer

## Request body

- HealthSyncRequestDto
  - `platform` 'apple_health' | 'health_connect', required
  - `samples` HealthSyncSampleDto[], required: Up to 500 samples per request. Larger batches must be paginated by the client.
    - `sample_type` 'weight' | 'body_fat_percentage' | 'lean_body_mass' | 'bmi' | 'waist_circumference' | 'dietary_energy' | 'dietary_protein' | 'dietary_carbs' | 'dietary_fat' | 'dietary_sugar' | 'dietary_fiber' | 'dietary_water' | 'steps' | 'active_energy_burned' | 'apple_exercise_time' | 'exercise_session' | 'distance' | 'floors_climbed' | 'stand_hour' | 'sleep_session' | 'heart_rate' | 'resting_heart_rate' | 'hrv' | 'blood_glucose' | 'blood_pressure_systolic' | 'blood_pressure_diastolic', required: Normalized sample type key
    - `value` object, nullable: Primary numeric value. Nullable for category samples whose meaning is in metadata (e.g. workout type without a primary number).
    - `unit` string, required: Unit string — lbs, kg, kcal, mg/dL, bpm, oz, g, min, count, etc.
    - `start_date` string, required: Sample window start (ISO 8601)
    - `end_date` string, required: Sample window end (ISO 8601). Equals start_date for point-in-time samples.
    - `source_bundle_id` string, required: App or device that originally wrote this sample to the platform hub. Used for cross-source dedup priority. Examples: com.apple.health.1234ABCD, com.withings.wiscale2, com.dexcom.cgm.G7
    - `source_name` string: Human-readable display name. Examples: "Apple Watch", "Withings Body+"
    - `category` object, nullable: Sub-type for category-type samples. sleep_session: "session" (full-night summary), "light", "deep", "rem", "asleep", "awake", "out_of_bed", "unknown". exercise_session: "running", "cycling", "swimming", etc. Null / omitted for scalar samples (weight, steps, hrv, etc.).
    - `metadata` object: Type-specific structured payload — sleep stages, workout details, glucose-meter context, blood-pressure pairing, etc.
  - `anchors` HealthSyncAnchorDto[], required: Anchor positions per (sample_type, platform). Server upserts these so the client can resume from where it left off after a reinstall or device switch.
    - `sample_type` 'weight' | 'body_fat_percentage' | 'lean_body_mass' | 'bmi' | 'waist_circumference' | 'dietary_energy' | 'dietary_protein' | 'dietary_carbs' | 'dietary_fat' | 'dietary_sugar' | 'dietary_fiber' | 'dietary_water' | 'steps' | 'active_energy_burned' | 'apple_exercise_time' | 'exercise_session' | 'distance' | 'floors_climbed' | 'stand_hour' | 'sleep_session' | 'heart_rate' | 'resting_heart_rate' | 'hrv' | 'blood_glucose' | 'blood_pressure_systolic' | 'blood_pressure_diastolic', required
    - `last_anchor` string, required: Timestamp of the most recent sample successfully read on the client (ISO 8601)
    - `hk_anchor` object, nullable: iOS-only — opaque token from HKAnchoredObjectQuery for efficient resumption. Null on Android.
  - `preferred_sources` object: Platform-resolved preferred source per sample type. Key = sample_type (e.g. "steps"), value = source_bundle_id the platform considers authoritative (e.g. "com.apple.health.9B9B995F-..."). When present, the backend records these in user_source_preferences so all aggregate queries (step totals, HRV, sleep) return the same numbers the user sees in Apple Health / Google Fit. Omit types for which the platform has no clear preference.

## Response `200`

---

[API](https://skmtc.dev/rewritelifestyle/apis/rewrite-lifestyle-api.md) - [All operations](https://skmtc.dev/rewritelifestyle/apis/rewrite-lifestyle-api/llms.txt) - [OpenAPI document](https://skmtc.dev/rewritelifestyle/apis/rewrite-lifestyle-api/revisions/28695827f27a?raw)
