# Templates

> Meta message templates. Bodies and answers are Meta's.

Canonical: https://docs.whabuzz.com/api/templates/

Meta message templates. Bodies and answers are Meta's.

Base URL `https://api.whabuzz.com`. Every request needs `Authorization: Bearer <key>` unless the operation says otherwise; see [Authentication](https://docs.whabuzz.com/authentication.md). Errors follow the [two-source contract](https://docs.whabuzz.com/errors.md).

Operations on this page:

- [`GET /v1/templates`](#listTemplates): List templates
- [`POST /v1/templates`](#createTemplate): Submit a template to Meta
- [`GET /v1/templates/{template_id}`](#getTemplate): Get a template
- [`POST /v1/templates/{template_id}`](#editTemplate): Edit a template
- [`DELETE /v1/templates/{template_id}`](#deleteTemplate): Delete a template
- [`POST /v1/templates/sync`](#syncTemplates): Re-read every template from Meta
- [`GET /v1/templates/library`](#listTemplateLibrary): Browse Meta's template library
- [`POST /v1/templates/media-handle`](#createTemplateMediaHandle): Upload a header sample and get a handle for template creation

## List templates {#listTemplates}

`GET /v1/templates`

**Auth:** API key (tenant key, or app key with `X-WhaBuzz-Tenant`). **Operation id:** `listTemplates`.

**Parameters**

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `waba_id` | query | string | no |  |
| `status` | query | `APPROVED` or `PENDING` or `REJECTED` or `PAUSED` or `DISABLED` | no |  |
| `name` | query | string | no |  |

cURL:

```bash
curl -X GET "https://api.whabuzz.com/v1/templates" \
  -H "Authorization: Bearer $WHABUZZ_KEY"
```

**Responses**

**200** Templates

```json
{
  "data": [
    {
      "id": "1689556908129833",
      "waba_id": "26059971920328384",
      "name": "diwali_offer",
      "language": "en",
      "category": "MARKETING",
      "status": "REJECTED",
      "status_reason": "INVALID_FORMAT: Template body contains variables at the start or end.",
      "quality_score": null,
      "parameter_format": "POSITIONAL",
      "meta_object": {
        "id": "1689556908129833",
        "name": "diwali_offer",
        "language": "en",
        "status": "REJECTED",
        "category": "MARKETING",
        "components": [
          {
            "type": "BODY",
            "text": "{{1}} off this Diwali"
          }
        ]
      }
    }
  ]
}
```

## Submit a template to Meta {#createTemplate}

`POST /v1/templates`

Body is Meta's `POST /{waba_id}/message_templates` body plus `waba_id`. Response is Meta's.

**Auth:** API key (tenant key, or app key with `X-WhaBuzz-Tenant`). **Operation id:** `createTemplate`.

**Request body** (`application/json`, required)

Request example:

```json
{
  "waba_id": "26059971920328384",
  "name": "renewal_reminder",
  "language": "en",
  "category": "UTILITY",
  "parameter_format": "POSITIONAL",
  "components": [
    {
      "type": "BODY",
      "text": "Hi {{1}}, your membership renews on {{2}}.",
      "example": {
        "body_text": [
          [
            "Kerry",
            "31 Oct"
          ]
        ]
      }
    },
    {
      "type": "BUTTONS",
      "buttons": [
        {
          "type": "QUICK_REPLY",
          "text": "Renew now"
        }
      ]
    }
  ]
}
```

cURL:

```bash
curl -X POST "https://api.whabuzz.com/v1/templates" \
  -H "Authorization: Bearer $WHABUZZ_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "waba_id": "26059971920328384",
  "name": "renewal_reminder",
  "language": "en",
  "category": "UTILITY",
  "parameter_format": "POSITIONAL",
  "components": [
    {
      "type": "BODY",
      "text": "Hi {{1}}, your membership renews on {{2}}.",
      "example": {
        "body_text": [
          [
            "Kerry",
            "31 Oct"
          ]
        ]
      }
    },
    {
      "type": "BUTTONS",
      "buttons": [
        {
          "type": "QUICK_REPLY",
          "text": "Renew now"
        }
      ]
    }
  ]
}'
```

**Responses**

**200** Meta's response verbatim

```json
{
  "id": "1689556908129832",
  "status": "PENDING",
  "category": "UTILITY"
}
```

**400** Meta rejected the template

```json
{
  "source": "meta",
  "error": {
    "message": "Invalid parameter",
    "type": "OAuthException",
    "code": 100,
    "error_subcode": 2388023,
    "is_transient": false,
    "error_user_title": "Message template language is being deleted",
    "error_user_msg": "New en content can't be added while the existing en content is being deleted. Try again in 4 weeks or consider creating a new message template.",
    "fbtrace_id": "AqXyZ123"
  }
}
```

## Get a template {#getTemplate}

`GET /v1/templates/{template_id}`

**Auth:** API key (tenant key, or app key with `X-WhaBuzz-Tenant`). **Operation id:** `getTemplate`.

**Parameters**

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `template_id` | path | string | yes |  |

cURL:

```bash
curl -X GET "https://api.whabuzz.com/v1/templates/$TEMPLATE_ID" \
  -H "Authorization: Bearer $WHABUZZ_KEY"
```

**Responses**

**200** Template

```json
{
  "id": "1689556908129832",
  "name": "renewal_reminder",
  "language": "en",
  "category": "UTILITY",
  "status": "APPROVED",
  "quality_score": "GREEN",
  "meta_object": {
    "id": "1689556908129832",
    "status": "APPROVED"
  }
}
```

## Edit a template {#editTemplate}

`POST /v1/templates/{template_id}`

**Auth:** API key (tenant key, or app key with `X-WhaBuzz-Tenant`). **Operation id:** `editTemplate`.

**Parameters**

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `template_id` | path | string | yes |  |

**Request body** (`application/json`, required)

Request example:

```json
{
  "components": [
    {
      "type": "BODY",
      "text": "Hi {{1}}, your plan renews on {{2}}.",
      "example": {
        "body_text": [
          [
            "Kerry",
            "31 Oct"
          ]
        ]
      }
    }
  ]
}
```

cURL:

```bash
curl -X POST "https://api.whabuzz.com/v1/templates/$TEMPLATE_ID" \
  -H "Authorization: Bearer $WHABUZZ_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "components": [
    {
      "type": "BODY",
      "text": "Hi {{1}}, your plan renews on {{2}}.",
      "example": {
        "body_text": [
          [
            "Kerry",
            "31 Oct"
          ]
        ]
      }
    }
  ]
}'
```

**Responses**

**200** Meta's response verbatim

```json
{
  "success": true
}
```

## Delete a template {#deleteTemplate}

`DELETE /v1/templates/{template_id}`

**Auth:** API key (tenant key, or app key with `X-WhaBuzz-Tenant`). **Operation id:** `deleteTemplate`.

**Parameters**

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `template_id` | path | string | yes |  |

cURL:

```bash
curl -X DELETE "https://api.whabuzz.com/v1/templates/$TEMPLATE_ID" \
  -H "Authorization: Bearer $WHABUZZ_KEY"
```

**Responses**

**200** Meta's response verbatim

```json
{
  "success": true
}
```

## Re-read every template from Meta {#syncTemplates}

`POST /v1/templates/sync`

**Auth:** API key (tenant key, or app key with `X-WhaBuzz-Tenant`). **Operation id:** `syncTemplates`.

**Request body** (`application/json`)

Request example:

```json
{
  "waba_id": "26059971920328384"
}
```

cURL:

```bash
curl -X POST "https://api.whabuzz.com/v1/templates/sync" \
  -H "Authorization: Bearer $WHABUZZ_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "waba_id": "26059971920328384"
}'
```

**Responses**

**200** Counts

```json
{
  "waba_id": "26059971920328384",
  "fetched": 10,
  "inserted": 0,
  "updated": 2
}
```

## Browse Meta's template library {#listTemplateLibrary}

`GET /v1/templates/library`

Query parameters are passed to Meta unchanged.

**Auth:** API key (tenant key, or app key with `X-WhaBuzz-Tenant`). **Operation id:** `listTemplateLibrary`.

**Parameters**

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `search` | query | string | no |  |
| `topic` | query | string | no |  |
| `language` | query | string | no |  |

cURL:

```bash
curl -X GET "https://api.whabuzz.com/v1/templates/library" \
  -H "Authorization: Bearer $WHABUZZ_KEY"
```

**Responses**

**200** Meta's response verbatim

```json
{
  "data": [
    {
      "name": "appointment_reminder_1",
      "language": "en_US",
      "category": "UTILITY",
      "topic": "APPOINTMENTS",
      "body": "This is a reminder of your upcoming appointment on {{1}} at {{2}}."
    }
  ],
  "paging": {
    "cursors": {
      "before": "QVFI",
      "after": "QVFJ"
    }
  }
}
```

## Upload a header sample and get a handle for template creation {#createTemplateMediaHandle}

`POST /v1/templates/media-handle`

**Auth:** API key (tenant key, or app key with `X-WhaBuzz-Tenant`). **Operation id:** `createTemplateMediaHandle`.

**Request body** (`multipart/form-data`, required)

| Field | Type | Required | Description |
|---|---|---|---|
| `file` | string (binary) | yes |  |

cURL:

```bash
curl -X POST "https://api.whabuzz.com/v1/templates/media-handle" \
  -H "Authorization: Bearer $WHABUZZ_KEY" \
  -F file=@./photo.jpg
```

**Responses**

**200** Meta's response verbatim

```json
{
  "h": "4::aW1hZ2UvanBlZw==:ARZ…"
}
```
