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

# Trigger Historical Sync



## OpenAPI

````yaml /api-reference/openapi.json post /back-office/sync/historical
openapi: 3.1.0
info:
  title: Payra API
  version: 1.0.0
  description: Documentação da API para Backoffice e Service
servers: []
security: []
paths:
  /back-office/sync/historical:
    post:
      tags:
        - Sync
      summary: Trigger Historical Sync
      operationId: triggerHistoricalSync
      requestBody:
        description: Historical sync parameters
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                connectionId:
                  type: string
                  minLength: 1
                  description: The unique identifier of the connection to sync
                startDate:
                  type: string
                  pattern: ^\d{4}-\d{2}-\d{2}$
                  description: Start date in YYYY-MM-DD format
                endDate:
                  type: string
                  pattern: ^\d{4}-\d{2}-\d{2}$
                  description: End date in YYYY-MM-DD format
                allInvoices:
                  type: boolean
                  default: false
                  description: Whether to fetch all invoices or only OPEN ones
                useWorker:
                  type: boolean
                  default: false
                  description: Whether to enqueue to SQS for distributed processing
                invoiceIds:
                  type: array
                  items:
                    type: string
                  description: >-
                    Optional array that will not work with date range to fetch a
                    specific list of invoices
                customerIds:
                  type: array
                  items:
                    type: string
                  description: >-
                    Optional array of customer IDs to sync (for rutter
                    integrations use emails)
                jobType:
                  type: string
                  enum:
                    - sync_customer
                    - sync_invoice
                  default: sync_invoice
                  description: Type of sync job to run
                slackUsername:
                  type: string
                  description: >-
                    Optional Slack username to notify when sync completes
                    (without @)
              required:
                - connectionId
      responses:
        '200':
          description: Historical sync triggered successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: string
                    enum:
                      - health_status_ok
                      - health_status_error
                      - validation_error
                      - bad_request
                      - unauthorized
                      - forbidden
                      - not_found
                      - method_not_allowed
                      - internal_server_error
                      - organization_not_found
                      - cannot_access_organization
                      - api_key_not_found
                      - resource_already_exists
                  message:
                    type: string
                  data:
                    type: object
                    properties:
                      message:
                        type: string
                      connectionId:
                        type: string
                      mode:
                        type: string
                        enum:
                          - LOCAL
                          - QUEUED
                      syncOptions:
                        type: object
                        properties:
                          startDate:
                            type: string
                          endDate:
                            type: string
                          allInvoices:
                            type: boolean
                          useWorker:
                            type: boolean
                          invoiceIds:
                            type: array
                            items:
                              type: string
                          customerIds:
                            type: array
                            items:
                              type: string
                          jobType:
                            type: string
                            enum:
                              - sync_customer
                              - sync_invoice
                          slackUsername:
                            type: string
                        required:
                          - allInvoices
                          - useWorker
                    required:
                      - message
                      - connectionId
                      - mode
                      - syncOptions
                required:
                  - data
        '400':
          description: Connection not active for historical sync
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: string
                    enum:
                      - health_status_ok
                      - health_status_error
                      - validation_error
                      - bad_request
                      - unauthorized
                      - forbidden
                      - not_found
                      - method_not_allowed
                      - internal_server_error
                      - organization_not_found
                      - cannot_access_organization
                      - api_key_not_found
                      - resource_already_exists
                    default: bad_request
                  message:
                    type: string
                  data: {}
        '404':
          description: Connection not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: string
                    enum:
                      - health_status_ok
                      - health_status_error
                      - validation_error
                      - bad_request
                      - unauthorized
                      - forbidden
                      - not_found
                      - method_not_allowed
                      - internal_server_error
                      - organization_not_found
                      - cannot_access_organization
                      - api_key_not_found
                      - resource_already_exists
                    default: not_found
                  message:
                    type: string
                  data: {}
        '422':
          description: Failed Validation
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: string
                    enum:
                      - health_status_ok
                      - health_status_error
                      - validation_error
                      - bad_request
                      - unauthorized
                      - forbidden
                      - not_found
                      - method_not_allowed
                      - internal_server_error
                      - organization_not_found
                      - cannot_access_organization
                      - api_key_not_found
                      - resource_already_exists
                    default: validation_error
                  message:
                    type: string
                  data:
                    type: array
                    items: {}
        '500':
          description: Server error
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: string
                    enum:
                      - health_status_ok
                      - health_status_error
                      - validation_error
                      - bad_request
                      - unauthorized
                      - forbidden
                      - not_found
                      - method_not_allowed
                      - internal_server_error
                      - organization_not_found
                      - cannot_access_organization
                      - api_key_not_found
                      - resource_already_exists
                    default: internal_server_error
                  message:
                    type: string
                  data: {}
      security:
        - Bearer: []
components:
  securitySchemes:
    Bearer:
      type: http
      scheme: bearer

````