> ## Documentation Index
> Fetch the complete documentation index at: https://openwearables.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Sync Historical Data

> Trigger a historical sync of the user's data from a connected provider.

Each provider strategy decides how to dispatch the sync (REST polling,
webhook backfill, etc.). The ``days`` parameter is capped at the
provider's ``max_historical_days``.

**Automatic historical sync on connect (grace period)**

v0.4.2 introduced this endpoint as the canonical, opt-in way to
backfill historical data - the long-term goal is that connecting a
provider only sets up live sync, and history is pulled on demand.

To make migration painless, the pre-0.4.2 behaviour is kept for now
behind a grace-period flag (``HISTORICAL_SYNC_ON_CONNECT``, default:
``true``): a historical sync is auto-dispatched after a successful
OAuth callback (up to 90 days for pull-based providers; up to 30
days for Garmin, whose webhook-based backfill is capped at 30 days
from the user's consent date).

Once your integration calls this endpoint explicitly, set
``HISTORICAL_SYNC_ON_CONNECT=false``. The flag will default to
``false`` in a future release and is planned for removal afterwards.



## OpenAPI

````yaml /openapi.json post /api/v1/providers/{provider}/users/{user_id}/sync/historical
openapi: 3.1.0
info:
  title: Open Wearables API
  version: 1.0.0
servers: []
security: []
paths:
  /api/v1/providers/{provider}/users/{user_id}/sync/historical:
    post:
      tags:
        - 'External: Data Sync'
      summary: Sync Historical Data
      description: |-
        Trigger a historical sync of the user's data from a connected provider.

        Each provider strategy decides how to dispatch the sync (REST polling,
        webhook backfill, etc.). The ``days`` parameter is capped at the
        provider's ``max_historical_days``.

        **Automatic historical sync on connect (grace period)**

        v0.4.2 introduced this endpoint as the canonical, opt-in way to
        backfill historical data - the long-term goal is that connecting a
        provider only sets up live sync, and history is pulled on demand.

        To make migration painless, the pre-0.4.2 behaviour is kept for now
        behind a grace-period flag (``HISTORICAL_SYNC_ON_CONNECT``, default:
        ``true``): a historical sync is auto-dispatched after a successful
        OAuth callback (up to 90 days for pull-based providers; up to 30
        days for Garmin, whose webhook-based backfill is capped at 30 days
        from the user's consent date).

        Once your integration calls this endpoint explicitly, set
        ``HISTORICAL_SYNC_ON_CONNECT=false``. The flag will default to
        ``false`` in a future release and is planned for removal afterwards.
      operationId: >-
        sync_historical_data_api_v1_providers__provider__users__user_id__sync_historical_post
      parameters:
        - name: provider
          in: path
          required: true
          schema:
            $ref: '#/components/schemas/ProviderName'
            description: Data provider
          description: Data provider
        - name: user_id
          in: path
          required: true
          schema:
            type: string
            format: uuid
            title: User Id
        - name: days
          in: query
          required: false
          schema:
            type: integer
            maximum: 3650
            minimum: 1
            description: >-
              Days of historical data to fetch (default: 90, max: 3650). Capped
              at the provider's own limit (e.g. Garmin: 30 days, Polar: 365
              days); the response `days` reflects the window scheduled for sync.
            default: 90
            title: Days
          description: >-
            Days of historical data to fetch (default: 90, max: 3650). Capped at
            the provider's own limit (e.g. Garmin: 30 days, Polar: 365 days);
            the response `days` reflects the window scheduled for sync.
        - name: X-Open-Wearables-API-Key
          in: header
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: X-Open-Wearables-Api-Key
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                type: object
                additionalProperties: true
                title: >-
                  Response Sync Historical Data Api V1 Providers  Provider 
                  Users  User Id  Sync Historical Post
        '422':
          description: Validation Error
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/ValidationProblem'
        4XX:
          description: Client error
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        5XX:
          description: Server error
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      security:
        - OAuth2PasswordBearer: []
components:
  schemas:
    ProviderName:
      type: string
      enum:
        - apple
        - samsung
        - garmin
        - health_connect
        - google_health
        - polar
        - suunto
        - whoop
        - strava
        - oura
        - fitbit
        - ultrahuman
        - sensorbio
        - withings
        - unknown
        - internal
      title: ProviderName
      description: Supported data providers.
    ValidationProblem:
      description: A 422 for a request that failed validation, listing every failure.
      examples:
        - code: VALIDATION_ERROR
          detail: >-
            body.email: value is not a valid email address: An email address
            must have an @-sign. (and 1 more)
          errors:
            - loc:
                - body
                - email
              msg: >-
                value is not a valid email address: An email address must have
                an @-sign.
              type: value_error
            - loc:
                - body
                - first_name
              msg: String should have at most 100 characters
              type: string_too_long
          status: 422
          title: Unprocessable Content
      properties:
        title:
          description: HTTP status phrase
          title: Title
          type: string
        status:
          description: HTTP status code, the same as the response's
          title: Status
          type: integer
        detail:
          description: Human-readable explanation of this occurrence
          title: Detail
          type: string
        code:
          description: Machine-readable error code, stable across releases
          title: Code
          type: string
        errors:
          description: Every validation failure in the request
          items:
            $ref: '#/components/schemas/ValidationErrorItem'
          title: Errors
          type: array
      required:
        - title
        - status
        - detail
        - code
        - errors
      title: ValidationProblem
      type: object
    Problem:
      description: >-
        An error response: RFC 9457 Problem Details, served as
        ``application/problem+json``.


        ``type`` is omitted, which per the RFC means ``about:blank``: ``title``
        is the status

        phrase, and ``code`` tells errors with the same status apart.
      examples:
        - code: NOT_FOUND
          detail: 'User with ID: 123e4567-e89b-12d3-a456-426614174000 not found.'
          status: 404
          title: Not Found
      properties:
        title:
          description: HTTP status phrase
          title: Title
          type: string
        status:
          description: HTTP status code, the same as the response's
          title: Status
          type: integer
        detail:
          description: Human-readable explanation of this occurrence
          title: Detail
          type: string
        code:
          description: Machine-readable error code, stable across releases
          title: Code
          type: string
      required:
        - title
        - status
        - detail
        - code
      title: Problem
      type: object
    ValidationErrorItem:
      properties:
        loc:
          description: Where the invalid value is, e.g. ['body', 'email']
          items:
            anyOf:
              - type: string
              - type: integer
          title: Loc
          type: array
        msg:
          description: What is wrong with it
          title: Msg
          type: string
        type:
          description: Pydantic error type, e.g. 'missing'
          title: Type
          type: string
      required:
        - loc
        - msg
        - type
      title: ValidationErrorItem
      type: object
  securitySchemes:
    OAuth2PasswordBearer:
      type: oauth2
      flows:
        password:
          scopes: {}
          tokenUrl: /api/v1/auth/login

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.