# Sync Templates from Meta

Canonical: https://docs.bluehola.com/docs/templates-flows-media/post-v1-templates-sync
OpenAPI: https://docs.bluehola.com/openapi.yaml

<div class="endpoint"><span class="endpoint-method endpoint-method--post">POST</span><code class="endpoint-path">/v1/templates/sync</code></div>

Import/refresh into the local store whatever templates already exist on Meta's side for this WABA.

:::note[Authentication]

Send `Authorization: Bearer <API_KEY>` in the request headers; required scope: `templates:manage`. Which resources an API Key can reach is determined by its current authorization scope.

:::

## Request

Base URL: `https://api.bluehola.com`

### Request body
A request body is required.
### Request body fields

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `wabaId` | string | Yes | The platform's WABA ID |
| `after` | string | No | Continuation cursor: the `nextCursor` from the previous response (at most 512 characters). Omit it to start from the first page |

Content-Type: `application/json`
Schema:

```json
{
  "type": "object",
  "properties": {
    "wabaId": {
      "type": "string",
      "description": "string · required — The platform's WABA ID"
    },
    "after": {
      "type": "string",
      "description": "string · optional — continuation cursor: the nextCursor from the previous response; omit it to start from the first page"
    }
  },
  "required": [
    "wabaId"
  ]
}
```

## Response

| Status | Description |
| --- | --- |
| `200` | OK |
| `4xx` | Client error |

### 200 response schema

```json
{
  "$ref": "#/components/schemas/TemplateSyncResult"
}
```

For the common error envelope and how to handle it, see [Error Codes](../guides/error-codes.md).

## Notes

Onboarding (Embedded Signup) only creates the WABA and phone number — it never touches templates. But the send path requires a matching local template row, so any template the customer already built in WhatsApp Manager and had approved by Meta cannot be sent through this platform at all until it has been imported (you get 404 template not found for this phone number's WABA). The platform syncs automatically once onboarding completes; this endpoint is the entry point for doing it again manually.

#### Idempotency and what it overwrites
- Matched on (wabaId, name, language): an existing row is **updated**, a missing one is **inserted**.
- Updates only overwrite the fields Meta is authoritative for: status / category / components / rejected_reason / metaTemplateId; `name` and `language` are left alone.
- **It never deletes** local template rows that have no match. Deletion is destructive, and Meta's list is paginated — seeing only part of it and finding "extra" local rows is normal, not a reason to delete them.

#### Pagination
One call follows Meta's pagination cursor for at most 5 pages (200 templates per page). When everything has been read, the response has `truncated=false` and `nextCursor=null`; otherwise it has `truncated=true` and a `nextCursor` — call again with `after=<nextCursor>` to continue from where it stopped, until `truncated=false`. Calling again without `after` starts over from the first page (idempotent, but it will not reach the later pages).

#### Nothing is submitted to Meta
This is a pure read plus a local write; it does not consume any of Meta's template review quota and can be called repeatedly and safely.
