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

> ## Agent Instructions
> Integrating Pilot Status end to end? Follow https://docs.pilotstatus.com.br/guides/integrate-with-ai.md (pt-BR: https://docs.pilotstatus.com.br/pt-BR/guides/integrate-with-ai.md). No step requires contacting support: every credential is shown in the dashboard or in an API response, and a lost one is regenerated, not recovered.
> Webhook signing secret: shown ONCE in the Signing secret window right after creating the webhook on /webhooks, and in the `secret` field of the POST /v1/webhooks response (MCP: webhooks_create). Lost it: Edit Webhook → Generate a new secret, POST /v1/webhooks/{id}/rotate-secret, or webhooks_rotate_secret (the old one stops working at once). Verify `x-pilot-status-signature` = hex HMAC-SHA256 of the raw request body keyed with that secret.
> Meta verify token (number connected with the user's own Meta app credentials): Meta Number Created! window after connecting, then the number's card on Numbers (workspace Owner), or webhook.verifyToken in the POST /v1/numbers/meta response. It is not the webhook signing secret.
> REST auth: `x-api-key: ps_...` header, never Authorization: Bearer. MCP: https://mcp.pilotstatus.com.br/mcp (148 tools, OAuth 2.1 or x-api-key); Code Mode: https://mcp.pilotstatus.com.br/code. Destructive MCP tools return a preview and a confirm_token: show the preview and call again only after the user's explicit yes. Over OAuth, revealing or creating ps_ API keys is workspace Owner only.

# Start Chatwoot history sync

> Replays the already-stored history of a Meta coexistence number (the history imported at Embedded Signup) into its Chatwoot inbox, oldest first. Answers 202 and runs in the background — follow it with GET. Optional body: `windowDays` (`30` or `90`; any other value means `30`) and `markRead` (default `true`: on finish, in API-mirror mode, touched conversations are marked read and resolved). The number checks run before the body is read. Idempotent: only re-posts messages that never landed.



## OpenAPI

````yaml openapi.json POST /v1/chatwoot/history-sync
openapi: 3.1.0
info:
  title: Pilot Status API
  version: 1.0.0
  license:
    name: Pilot Status Terms of Service
    url: https://pilotstatus.com.br/terms
  description: >-
    Public REST API for Pilot Status. Authenticate with the `x-api-key: ps_...`
    header (or `x-api-key-id`). Base URL: https://pilotstatus.com.br
servers:
  - url: https://pilotstatus.com.br
security:
  - apiKey: []
  - apiKeyId: []
paths:
  /v1/chatwoot/history-sync:
    post:
      tags:
        - Chatwoot
      summary: Start Chatwoot history sync
      description: >-
        Replays the already-stored history of a Meta coexistence number (the
        history imported at Embedded Signup) into its Chatwoot inbox, oldest
        first. Answers 202 and runs in the background — follow it with GET.
        Optional body: `windowDays` (`30` or `90`; any other value means `30`)
        and `markRead` (default `true`: on finish, in API-mirror mode, touched
        conversations are marked read and resolved). The number checks run
        before the body is read. Idempotent: only re-posts messages that never
        landed.
      operationId: post_chatwoot_history_sync
      parameters:
        - name: x-whatsapp-number-id
          in: header
          required: false
          description: >-
            Scopes to a single number (required for tenant keys / per-number
            OAuth grants).
          schema:
            type: string
          example: num_01HZX...
      requestBody:
        required: false
        content:
          application/json:
            schema:
              type: object
              properties:
                windowDays:
                  type: integer
                  enum:
                    - 30
                    - 90
                  default: 30
                  description: History window, in days.
                markRead:
                  type: boolean
                  default: true
                  description: >-
                    Mark touched conversations read and resolve them on finish
                    (API-mirror mode).
            example:
              windowDays: 90
              markRead: true
      responses:
        '202':
          description: Sync queued
          content:
            application/json:
              example:
                historySync:
                  status: QUEUED
                  windowDays: 30
                  total: 0
                  done: 0
                  failed: 0
                  skippedMedia: 0
                  lastErrorCode: null
                  startedAt: null
                  finishedAt: null
        '400':
          description: >-
            No number resolvable (tenant key / per-number grant without
            x-whatsapp-number-id) — or `INVALID_BODY` when the body is not valid
            JSON
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                  code:
                    type: string
              example:
                error: whatsappNumberId is required (x-whatsapp-number-id header)
                code: NUMBER_REQUIRED
        '401':
          description: Missing or invalid `x-api-key` / `x-api-key-id` header
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                  code:
                    type: string
              example:
                error: Unauthorized
        '403':
          description: >-
            OAuth/MCP token or account key (`ps_account_`) of a user whose
            workspace role lacks `integrations:manage` (Admin or Owner), or who
            is no longer an active member (`WORKSPACE_MEMBERSHIP_REQUIRED`); or
            OAuth token granted other numbers (`NUMBER_NOT_IN_GRANT`)
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                  code:
                    type: string
              example:
                error: >-
                  Your workspace role does not allow this action
                  (integrations:manage).
                code: PERMISSION_DENIED
        '404':
          description: The number does not belong to this tenant
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                  code:
                    type: string
              example:
                error: WhatsApp number not found
                code: NUMBER_NOT_FOUND
        '409':
          description: >-
            A sync is already `QUEUED` or `RUNNING` for the number (the body
            carries `historySync`)
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                  code:
                    type: string
              example:
                historySync:
                  status: RUNNING
                  windowDays: 30
                  total: 120
                  done: 48
                  failed: 0
                  skippedMedia: 2
                  lastErrorCode: null
                  startedAt: '2026-11-09T12:00:05.000Z'
                  finishedAt: null
                code: ALREADY_RUNNING
        '422':
          description: >-
            `FEATURE_NOT_SUPPORTED` (not a Meta number),
            `HISTORY_SYNC_NOT_COEXISTENCE` (not a coexistence number),
            `CHATWOOT_NOT_CONNECTED` (no enabled Chatwoot inbox) or
            `FEATURE_NOT_SUPPORTED_PII` (the number is `RELAY_ONLY` and stores
            no content)
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                  code:
                    type: string
              example:
                error: >-
                  This number is not a coexistence number, so there is no stored
                  history to send.
                code: HISTORY_SYNC_NOT_COEXISTENCE
        '429':
          description: Rate limit exceeded
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                  code:
                    type: string
              example:
                error: Too many requests
components:
  securitySchemes:
    apiKey:
      type: apiKey
      in: header
      name: x-api-key
      description: Your ps_ API key
    apiKeyId:
      type: apiKey
      in: header
      name: x-api-key-id
      description: API key id (alternative to x-api-key)

````

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