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

# Sync templates from WhatsApp

> Reconcile this project's templates against WhatsApp. Two things happen per connected WhatsApp Business Account: templates that exist on Meta but not in Zavu are imported (or linked to an existing template with the same name), and the approval status of the templates Zavu already knows about is refreshed from Meta.

This is what to call when a template was created outside Zavu — in Meta Business Manager, or by another tool — or when a `template.status_changed` webhook was missed and a template is stuck in `pending`. Status changes normally arrive by webhook; this endpoint is the recovery path and the only path for a template Zavu never created.

Templates that Meta reports as rejected or disabled are not imported; they are counted in `skipped`. Existing local templates are matched first by Meta template ID, then by name.

By default every sender in the project with a WhatsApp Business Account is synced. Pass `senderId` to sync only that sender's account. The call is synchronous — it waits for Meta and returns what changed — so it can take a few seconds per account. A failure on one account does not fail the request: it is reported in `errors` and the remaining accounts are still synced.



## OpenAPI

````yaml /openapi.json post /v1/templates/sync
openapi: 3.0.3
info:
  title: Zavu Unified Messaging Layer API
  version: 0.2.0
  description: >
    Unified multi-channel messaging API for Zavu.


    Supported channels:

    - **SMS**: Simple text messages

    - **WhatsApp**: Rich messaging with media, buttons, lists, CTA URL buttons,
    location requests, and templates

    - **Telegram**: Bot messaging with text, media, and interactive elements

    - **Email**: Transactional emails via Amazon SES


    Design goals:

    - Simple `send()` entrypoint for developers

    - Project-level authentication via Bearer token

    - Support for all WhatsApp message types (text, image, video, audio,
    document, sticker, location, contact, buttons, list, cta_url,
    location_request, reaction, template)

    - If a non-text message type is sent, WhatsApp channel is used automatically

    - 24-hour WhatsApp conversation window enforcement

    - Universal `to` field accepts phone numbers (E.164), email addresses, or
    numeric chat IDs (Telegram/Instagram/Messenger)
servers:
  - url: https://api.zavu.dev
security:
  - bearerAuth: []
paths:
  /v1/templates/sync:
    post:
      summary: Sync templates from WhatsApp
      description: >-
        Reconcile this project's templates against WhatsApp. Two things happen
        per connected WhatsApp Business Account: templates that exist on Meta
        but not in Zavu are imported (or linked to an existing template with the
        same name), and the approval status of the templates Zavu already knows
        about is refreshed from Meta.


        This is what to call when a template was created outside Zavu — in Meta
        Business Manager, or by another tool — or when a
        `template.status_changed` webhook was missed and a template is stuck in
        `pending`. Status changes normally arrive by webhook; this endpoint is
        the recovery path and the only path for a template Zavu never created.


        Templates that Meta reports as rejected or disabled are not imported;
        they are counted in `skipped`. Existing local templates are matched
        first by Meta template ID, then by name.


        By default every sender in the project with a WhatsApp Business Account
        is synced. Pass `senderId` to sync only that sender's account. The call
        is synchronous — it waits for Meta and returns what changed — so it can
        take a few seconds per account. A failure on one account does not fail
        the request: it is reported in `errors` and the remaining accounts are
        still synced.
      operationId: syncTemplates
      requestBody:
        required: false
        content:
          application/json:
            schema:
              type: object
              properties:
                senderId:
                  type: string
                  description: >-
                    Sync only the WhatsApp Business Account attached to this
                    sender. If omitted, every WhatsApp sender in the project is
                    synced.
                  example: sender_12345
            examples:
              all:
                summary: Sync every WhatsApp account in the project
                value: {}
              one_sender:
                summary: Sync one sender's account
                value:
                  senderId: sender_12345
      responses:
        '200':
          description: Sync completed. Counts are totals across every account synced.
          content:
            application/json:
              schema:
                type: object
                required:
                  - accountsSynced
                  - imported
                  - linked
                  - updated
                  - skipped
                  - errors
                properties:
                  accountsSynced:
                    type: integer
                    description: WhatsApp Business Accounts reconciled in this call.
                  imported:
                    type: integer
                    description: >-
                      Templates that existed on Meta and were created in Zavu by
                      this call.
                  linked:
                    type: integer
                    description: >-
                      Existing Zavu templates that were matched to a Meta
                      template by name and bound to its Meta ID.
                  updated:
                    type: integer
                    description: Templates whose approval status changed to match Meta.
                  skipped:
                    type: integer
                    description: >-
                      Meta templates left alone: already linked to a Zavu
                      template, or rejected/disabled on Meta.
                  errors:
                    type: array
                    items:
                      type: string
                    description: >-
                      Problems hit while syncing. Non-empty with a 200 means
                      part of the sync did not complete — the rest still did.
              example:
                accountsSynced: 1
                imported: 2
                linked: 1
                updated: 3
                skipped: 12
                errors: []
        '400':
          description: >-
            No sender in the project has a WhatsApp Business Account connected,
            or the given sender has none.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                code: invalid_request
                message: >-
                  No sender in this project has a WhatsApp Business Account
                  connected
        '401':
          description: Unauthorized.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: Sender not found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      security:
        - bearerAuth: []
components:
  schemas:
    Error:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: string
          example: invalid_request
        message:
          type: string
          example: Phone number is invalid
        details:
          type: object
          additionalProperties: true
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

````