> ## Documentation Index
> Fetch the complete documentation index at: https://kapso-1adbad2d.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Sync WhatsApp templates

> Synchronize WhatsApp templates from Meta with the local database.

**Sync Options:**
- With `whatsapp_config_id`: Queue sync for that specific config
- With `customer_id`: Queue sync for all production configs of that customer
- With no parameters: Queue sync for all production configs in the project

**Important Notes:**
- Sync operations are grouped by WhatsApp Business Account ID
- Only one active sync can run per Business Account at a time
- If a sync is already running/queued for a Business Account, the existing sync request is returned
- The sync operation is asynchronous and runs in the background
- Use the sync_status endpoint to track progress

**Response Structure:**
The response includes an array of sync requests (one per Business Account) with:
- Individual sync request details and status
- Summary statistics (total requests, jobs enqueued, already in progress)




## OpenAPI

````yaml api/legacy/openapi-whatsapp.yaml post /whatsapp_templates/sync
openapi: 3.0.3
info:
  title: Kapso External API - WhatsApp API
  description: >-
    API for programmatically interacting with Kapso agents, executions, and
    WhatsApp conversations. This specification includes only WhatsApp API
    endpoints.
  version: 1.0.0
  contact:
    name: Kapso Support
servers:
  - url: https://app.kapso.ai/api/v1
    description: Production server
security:
  - ApiKeyAuth: []
paths:
  /whatsapp_templates/sync:
    post:
      tags:
        - WhatsApp Templates
      summary: Sync WhatsApp templates
      description: >
        Synchronize WhatsApp templates from Meta with the local database.


        **Sync Options:**

        - With `whatsapp_config_id`: Queue sync for that specific config

        - With `customer_id`: Queue sync for all production configs of that
        customer

        - With no parameters: Queue sync for all production configs in the
        project


        **Important Notes:**

        - Sync operations are grouped by WhatsApp Business Account ID

        - Only one active sync can run per Business Account at a time

        - If a sync is already running/queued for a Business Account, the
        existing sync request is returned

        - The sync operation is asynchronous and runs in the background

        - Use the sync_status endpoint to track progress


        **Response Structure:**

        The response includes an array of sync requests (one per Business
        Account) with:

        - Individual sync request details and status

        - Summary statistics (total requests, jobs enqueued, already in
        progress)
      operationId: syncWhatsappTemplates
      requestBody:
        required: false
        content:
          application/json:
            schema:
              type: object
              properties:
                whatsapp_config_id:
                  type: string
                  format: uuid
                  description: Specific WhatsApp configuration to sync templates for
                  example: 550e8400-e29b-41d4-a716-446655440000
                customer_id:
                  type: string
                  format: uuid
                  description: >-
                    Customer ID to sync templates for all their production
                    configs
                  example: 550e8400-e29b-41d4-a716-446655440001
            examples:
              sync_specific_config:
                summary: Sync templates for specific config
                value:
                  whatsapp_config_id: 550e8400-e29b-41d4-a716-446655440000
              sync_customer_configs:
                summary: Sync templates for all customer configs
                value:
                  customer_id: 550e8400-e29b-41d4-a716-446655440001
              sync_all_configs:
                summary: Sync templates for all project configs
                value: {}
      responses:
        '202':
          description: Sync request accepted and queued
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: queued
                    description: Overall status of the sync request
                  sync_requests:
                    type: array
                    description: Array of sync requests (one per Business Account)
                    items:
                      $ref: '#/components/schemas/WhatsappTemplateSyncRun'
                  summary:
                    type: object
                    description: Summary of sync operations
                    properties:
                      total_requests:
                        type: integer
                        description: Total number of sync requests created/found
                        example: 2
                      jobs_enqueued:
                        type: integer
                        description: Number of new sync jobs that were enqueued
                        example: 1
                      already_in_progress:
                        type: integer
                        description: >-
                          Number of sync requests that were already
                          running/queued
                        example: 1
              examples:
                new_sync:
                  summary: New sync request created
                  value:
                    status: queued
                    sync_requests:
                      - id: sync-run-123abc
                        business_account_id: '123456789012345'
                        anchor_whatsapp_config_id: config-123abc
                        status: queued
                        templates_synced: 0
                        templates_created: 0
                        templates_updated: 0
                        templates_removed: 0
                        queued_at: '2024-01-15T10:30:00Z'
                        started_at: null
                        finished_at: null
                        job_id: job-456def
                        error_class: null
                        error_message: null
                        results: {}
                        affected_whatsapp_config_ids:
                          - config-123abc
                        anchor_whatsapp_config:
                          id: config-123abc
                          name: Main WhatsApp
                          display_phone_number: '+1234567890'
                    summary:
                      total_requests: 1
                      jobs_enqueued: 1
                      already_in_progress: 0
                existing_sync:
                  summary: Sync already in progress
                  value:
                    status: queued
                    sync_requests:
                      - id: sync-run-789ghi
                        business_account_id: '123456789012345'
                        anchor_whatsapp_config_id: config-456def
                        status: running
                        templates_synced: 5
                        templates_created: 2
                        templates_updated: 2
                        templates_removed: 1
                        queued_at: '2024-01-15T10:25:00Z'
                        started_at: '2024-01-15T10:26:00Z'
                        finished_at: null
                        job_id: job-789xyz
                        results:
                          config-456def:
                            templates_synced: 5
                            templates_created: 2
                            templates_updated: 2
                            templates_removed: 1
                        affected_whatsapp_config_ids:
                          - config-456def
                    summary:
                      total_requests: 1
                      jobs_enqueued: 0
                      already_in_progress: 1
                multiple_business_accounts:
                  summary: Multiple Business Accounts synced
                  value:
                    status: queued
                    sync_requests:
                      - id: sync-run-111aaa
                        business_account_id: '111111111111111'
                        status: queued
                        templates_synced: 0
                        affected_whatsapp_config_ids:
                          - config-111
                          - config-222
                      - id: sync-run-222bbb
                        business_account_id: '222222222222222'
                        status: running
                        templates_synced: 3
                        affected_whatsapp_config_ids:
                          - config-333
                    summary:
                      total_requests: 2
                      jobs_enqueued: 1
                      already_in_progress: 1
        '401':
          description: Unauthorized - invalid or missing API key
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: WhatsApp config or customer not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                config_not_found:
                  summary: WhatsApp config not found
                  value:
                    error: Production WhatsApp configuration not found
                customer_not_found:
                  summary: Customer not found
                  value:
                    error: Customer not found
        '422':
          description: Validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                missing_business_account_id:
                  summary: Config missing business account ID
                  value:
                    error: WhatsApp configuration missing business account id
                    whatsapp_config_ids:
                      - config-123abc
                no_configs:
                  summary: No production configs available
                  value:
                    error: No production WhatsApp configurations found
components:
  schemas:
    WhatsappTemplateSyncRun:
      type: object
      description: >-
        Represents a WhatsApp template synchronization request grouped by
        Business Account
      properties:
        id:
          type: string
          format: uuid
          example: sync-run-123abc
          description: Unique identifier for the sync run
        business_account_id:
          type: string
          example: '123456789012345'
          description: WhatsApp Business Account ID this sync is for
        anchor_whatsapp_config_id:
          type: string
          format: uuid
          example: config-123abc
          description: Primary WhatsApp config ID used for this sync operation
        status:
          type: string
          enum:
            - queued
            - running
            - succeeded
            - failed
          example: running
          description: Current status of the sync operation
        templates_synced:
          type: integer
          example: 15
          description: Total number of templates synchronized
        templates_created:
          type: integer
          example: 5
          description: Number of new templates created during sync
        templates_updated:
          type: integer
          example: 10
          description: Number of existing templates updated during sync
        templates_removed:
          type: integer
          example: 2
          description: Number of templates removed during sync
        queued_at:
          type: string
          format: date-time
          example: '2024-01-15T10:00:00Z'
          description: When the sync was queued
        started_at:
          type: string
          format: date-time
          nullable: true
          example: '2024-01-15T10:01:00Z'
          description: When the sync started processing
        finished_at:
          type: string
          format: date-time
          nullable: true
          example: '2024-01-15T10:05:00Z'
          description: When the sync completed (success or failure)
        job_id:
          type: string
          nullable: true
          example: job-456def
          description: Background job ID for this sync operation
        error_class:
          type: string
          nullable: true
          example: WhatsappApiError
          description: Error class if sync failed
        error_message:
          type: string
          nullable: true
          example: Invalid access token
          description: Error message if sync failed
        results:
          type: object
          description: Detailed results per WhatsApp config ID
          additionalProperties:
            type: object
            properties:
              templates_synced:
                type: integer
              templates_created:
                type: integer
              templates_updated:
                type: integer
              templates_removed:
                type: integer
          example:
            config-123abc:
              templates_synced: 8
              templates_created: 3
              templates_updated: 4
              templates_removed: 1
            config-456def:
              templates_synced: 7
              templates_created: 2
              templates_updated: 4
              templates_removed: 1
        affected_whatsapp_config_ids:
          type: array
          items:
            type: string
            format: uuid
          example:
            - config-123abc
            - config-456def
          description: List of WhatsApp config IDs affected by this sync
        anchor_whatsapp_config:
          $ref: '#/components/schemas/WhatsappConfig'
          description: The WhatsApp configuration used as anchor for this sync
    Error:
      type: object
      properties:
        error:
          type: string
          example: Resource not found
        status:
          type: integer
          example: 404
        message:
          type: string
          example: The requested resource could not be found
    WhatsappConfig:
      type: object
      description: >
        WhatsApp configuration resource returned by the External API.

        Sensitive write-only fields like `webhook_verify_token`,
        `webhook_destination_url`,

        and `access_token` are intentionally omitted from responses.
      properties:
        id:
          type: string
          example: config-123abc
        name:
          type: string
          example: Client WhatsApp
        display_name:
          type: string
          example: Client WhatsApp (+1234567890)
        phone_number_id:
          type: string
          example: '1234567890'
        business_account_id:
          type: string
          example: '98765432109'
        kind:
          type: string
          enum:
            - production
            - sandbox
          example: production
          description: Configuration environment type
        display_phone_number:
          type: string
          example: +56 9 61461262
          description: Formatted phone number for display purposes
        display_phone_number_normalized:
          type: string
          example: '56961461262'
          description: Normalized phone number without + prefix
        is_coexistence:
          type: boolean
          description: Indicates whether coexistence mode is enabled for this phone number
        webhook_verified_at:
          type: string
          format: date-time
          nullable: true
          description: Timestamp of the last successful webhook verification
        customer_id:
          type: string
          format: uuid
          example: customer-456def
        inbound_processing_enabled:
          type: boolean
          example: true
          description: Whether inbound message processing is enabled for this configuration
        calls_enabled:
          type: boolean
          example: false
          description: Whether voice calling is enabled for this configuration
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-Key
      description: API key required for all endpoints

````