# Template

En esta sección se encuentran los servicios que permiten crear, consultar, actualizar y eliminar templates de mensajes en WhatsApp Business. Los template son mensajes prediseñados y aprobados por Meta que garantizan consistencia y cumplimiento con las políticas de WhatsApp, ideales para campañas de notificación, confirmaciones, recordatorios o mensajes de marketing.

A diferencia de los mensajes regulares, los template son el único tipo de mensaje permitido para iniciar una conversación con un usuario que no te ha escrito en las últimas 24 horas. Pueden incluir un encabezado multimedia (imagen, video o documento), un cuerpo con variables dinámicas, un pie de página y hasta tres botones interactivos (tipo URL, número telefónico o respuesta rápida).

#### Listar template

Obtén todas las plantillas asociadas a tu cuenta.

## GET /templates

>

```json
{"openapi":"3.0.3","info":{"title":"B2Chat WhatsApp Cloud API","version":"0.0.1"},"tags":[{"name":"Templates","description":"Create, retrieve, update and delete WhatsApp message templates"}],"servers":[{"url":"https://wabsp.b2chat.io/","description":"Production environment"}],"security":[{"OAuth2ClientCredentials":[]}],"components":{"securitySchemes":{"OAuth2ClientCredentials":{"type":"oauth2","flows":{"clientCredentials":{"tokenUrl":"/auth/token","scopes":{}}}}},"schemas":{"TemplateListResponse":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/TemplateResponse"}}}},"TemplateResponse":{"type":"object","properties":{"id":{"type":"string"},"name":{"type":"string"},"status":{"type":"string","enum":["APPROVED","PENDING","REJECTED"]},"category":{"type":"string"},"language":{"type":"string"},"components":{"type":"array","items":{"$ref":"#/components/schemas/TemplateComponent"}}}},"TemplateComponent":{"type":"object","required":["type"],"properties":{"type":{"type":"string","enum":["BODY","HEADER","FOOTER","BUTTONS"],"description":"Component type"},"format":{"type":"string","enum":["TEXT","IMAGE","VIDEO","DOCUMENT"],"description":"Required when type is HEADER"},"text":{"type":"string","description":"Component text content (supports variables like {{1}})"},"buttons":{"type":"array","items":{"$ref":"#/components/schemas/TemplateButton"}}}},"TemplateButton":{"type":"object","required":["type","text"],"properties":{"type":{"type":"string","enum":["QUICK_REPLY","PHONE_NUMBER","URL"]},"text":{"type":"string"},"phone_number":{"type":"string"},"url":{"type":"string"}}},"ErrorResponse":{"type":"object","properties":{"error":{"type":"string"},"error_description":{"type":"string"}}}},"responses":{"Unauthorized":{"description":"Unauthorized – missing or invalid token","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}},"paths":{"/templates":{"get":{"tags":["Templates"],"operationId":"listTemplates","responses":{"200":{"description":"List of templates","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TemplateListResponse"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}}}}
```

#### Obtener template por ID

Consulta el detalle de una plantilla específica usando su ID.

## GET /templates/{messageTemplateId}

>

```json
{"openapi":"3.0.3","info":{"title":"B2Chat WhatsApp Cloud API","version":"0.0.1"},"tags":[{"name":"Templates","description":"Create, retrieve, update and delete WhatsApp message templates"}],"servers":[{"url":"https://wabsp.b2chat.io/","description":"Production environment"}],"security":[{"OAuth2ClientCredentials":[]}],"components":{"securitySchemes":{"OAuth2ClientCredentials":{"type":"oauth2","flows":{"clientCredentials":{"tokenUrl":"/auth/token","scopes":{}}}}},"parameters":{"messageTemplateId":{"name":"messageTemplateId","in":"path","required":true,"description":"The unique identifier of the message template","schema":{"type":"string"}}},"schemas":{"TemplateResponse":{"type":"object","properties":{"id":{"type":"string"},"name":{"type":"string"},"status":{"type":"string","enum":["APPROVED","PENDING","REJECTED"]},"category":{"type":"string"},"language":{"type":"string"},"components":{"type":"array","items":{"$ref":"#/components/schemas/TemplateComponent"}}}},"TemplateComponent":{"type":"object","required":["type"],"properties":{"type":{"type":"string","enum":["BODY","HEADER","FOOTER","BUTTONS"],"description":"Component type"},"format":{"type":"string","enum":["TEXT","IMAGE","VIDEO","DOCUMENT"],"description":"Required when type is HEADER"},"text":{"type":"string","description":"Component text content (supports variables like {{1}})"},"buttons":{"type":"array","items":{"$ref":"#/components/schemas/TemplateButton"}}}},"TemplateButton":{"type":"object","required":["type","text"],"properties":{"type":{"type":"string","enum":["QUICK_REPLY","PHONE_NUMBER","URL"]},"text":{"type":"string"},"phone_number":{"type":"string"},"url":{"type":"string"}}},"ErrorResponse":{"type":"object","properties":{"error":{"type":"string"},"error_description":{"type":"string"}}}},"responses":{"Unauthorized":{"description":"Unauthorized – missing or invalid token","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"NotFound":{"description":"Not Found – resource does not exist","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}},"paths":{"/templates/{messageTemplateId}":{"get":{"tags":["Templates"],"operationId":"getTemplateById","parameters":[{"$ref":"#/components/parameters/messageTemplateId"}],"responses":{"200":{"description":"Template details","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TemplateResponse"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}}}}
```

#### Crear un template

Crea una nueva plantilla de mensaje. Una vez creada, Meta la revisará antes de aprobarla para su uso.

## POST /templates

>

```json
{"openapi":"3.0.3","info":{"title":"B2Chat WhatsApp Cloud API","version":"0.0.1"},"tags":[{"name":"Templates","description":"Create, retrieve, update and delete WhatsApp message templates"}],"servers":[{"url":"https://wabsp.b2chat.io/","description":"Production environment"}],"security":[{"OAuth2ClientCredentials":[]}],"components":{"securitySchemes":{"OAuth2ClientCredentials":{"type":"oauth2","flows":{"clientCredentials":{"tokenUrl":"/auth/token","scopes":{}}}}},"schemas":{"TemplateCreateRequest":{"type":"object","required":["name","language","category","components"],"properties":{"name":{"type":"string"},"language":{"type":"string"},"category":{"type":"string","enum":["MARKETING","UTILITY","AUTHENTICATION","TRANSACTIONAL"]},"components":{"type":"array","items":{"$ref":"#/components/schemas/TemplateComponent"}}}},"TemplateComponent":{"type":"object","required":["type"],"properties":{"type":{"type":"string","enum":["BODY","HEADER","FOOTER","BUTTONS"],"description":"Component type"},"format":{"type":"string","enum":["TEXT","IMAGE","VIDEO","DOCUMENT"],"description":"Required when type is HEADER"},"text":{"type":"string","description":"Component text content (supports variables like {{1}})"},"buttons":{"type":"array","items":{"$ref":"#/components/schemas/TemplateButton"}}}},"TemplateButton":{"type":"object","required":["type","text"],"properties":{"type":{"type":"string","enum":["QUICK_REPLY","PHONE_NUMBER","URL"]},"text":{"type":"string"},"phone_number":{"type":"string"},"url":{"type":"string"}}},"TemplateResponse":{"type":"object","properties":{"id":{"type":"string"},"name":{"type":"string"},"status":{"type":"string","enum":["APPROVED","PENDING","REJECTED"]},"category":{"type":"string"},"language":{"type":"string"},"components":{"type":"array","items":{"$ref":"#/components/schemas/TemplateComponent"}}}},"ErrorResponse":{"type":"object","properties":{"error":{"type":"string"},"error_description":{"type":"string"}}}},"responses":{"BadRequest":{"description":"Bad Request – invalid parameters or body","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"Unauthorized":{"description":"Unauthorized – missing or invalid token","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}},"paths":{"/templates":{"post":{"tags":["Templates"],"operationId":"createTemplate","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/TemplateCreateRequest"}}}},"responses":{"200":{"description":"Template created successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TemplateResponse"}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"}}}}}}
```

{% hint style="warning" %}
*El campo `example` es requerido por Meta cuando tu template contiene variables dinámicas (`{{1}}`, `{{2}}`, etc.). Sin él, el template puede ser rechazada durante la revisión*\
\
*Y Al crear un template, su estado inicial será `PENDING` hasta que Meta la revise y apruebe. Solo los template con estado `APPROVED` pueden usarse para enviar mensajes*
{% endhint %}

#### Actualizar un template

Modifica el contenido de un template existente usando su ID.

## POST /templates/{messageTemplateId}

>

```json
{"openapi":"3.0.3","info":{"title":"B2Chat WhatsApp Cloud API","version":"0.0.1"},"tags":[{"name":"Templates","description":"Create, retrieve, update and delete WhatsApp message templates"}],"servers":[{"url":"https://wabsp.b2chat.io/","description":"Production environment"}],"security":[{"OAuth2ClientCredentials":[]}],"components":{"securitySchemes":{"OAuth2ClientCredentials":{"type":"oauth2","flows":{"clientCredentials":{"tokenUrl":"/auth/token","scopes":{}}}}},"parameters":{"messageTemplateId":{"name":"messageTemplateId","in":"path","required":true,"description":"The unique identifier of the message template","schema":{"type":"string"}}},"schemas":{"TemplateCreateRequest":{"type":"object","required":["name","language","category","components"],"properties":{"name":{"type":"string"},"language":{"type":"string"},"category":{"type":"string","enum":["MARKETING","UTILITY","AUTHENTICATION","TRANSACTIONAL"]},"components":{"type":"array","items":{"$ref":"#/components/schemas/TemplateComponent"}}}},"TemplateComponent":{"type":"object","required":["type"],"properties":{"type":{"type":"string","enum":["BODY","HEADER","FOOTER","BUTTONS"],"description":"Component type"},"format":{"type":"string","enum":["TEXT","IMAGE","VIDEO","DOCUMENT"],"description":"Required when type is HEADER"},"text":{"type":"string","description":"Component text content (supports variables like {{1}})"},"buttons":{"type":"array","items":{"$ref":"#/components/schemas/TemplateButton"}}}},"TemplateButton":{"type":"object","required":["type","text"],"properties":{"type":{"type":"string","enum":["QUICK_REPLY","PHONE_NUMBER","URL"]},"text":{"type":"string"},"phone_number":{"type":"string"},"url":{"type":"string"}}},"TemplateResponse":{"type":"object","properties":{"id":{"type":"string"},"name":{"type":"string"},"status":{"type":"string","enum":["APPROVED","PENDING","REJECTED"]},"category":{"type":"string"},"language":{"type":"string"},"components":{"type":"array","items":{"$ref":"#/components/schemas/TemplateComponent"}}}},"ErrorResponse":{"type":"object","properties":{"error":{"type":"string"},"error_description":{"type":"string"}}}},"responses":{"BadRequest":{"description":"Bad Request – invalid parameters or body","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"Unauthorized":{"description":"Unauthorized – missing or invalid token","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}},"paths":{"/templates/{messageTemplateId}":{"post":{"tags":["Templates"],"operationId":"updateTemplate","parameters":[{"$ref":"#/components/parameters/messageTemplateId"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/TemplateCreateRequest"}}}},"responses":{"200":{"description":"Template updated successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TemplateResponse"}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"}}}}}}
```

#### Eliminar un template

Elimina un template usando su nombre.

## DELETE /templates

>

```json
{"openapi":"3.0.3","info":{"title":"B2Chat WhatsApp Cloud API","version":"0.0.1"},"tags":[{"name":"Templates","description":"Create, retrieve, update and delete WhatsApp message templates"}],"servers":[{"url":"https://wabsp.b2chat.io/","description":"Production environment"}],"security":[{"OAuth2ClientCredentials":[]}],"components":{"securitySchemes":{"OAuth2ClientCredentials":{"type":"oauth2","flows":{"clientCredentials":{"tokenUrl":"/auth/token","scopes":{}}}}},"responses":{"Unauthorized":{"description":"Unauthorized – missing or invalid token","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"NotFound":{"description":"Not Found – resource does not exist","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}},"schemas":{"ErrorResponse":{"type":"object","properties":{"error":{"type":"string"},"error_description":{"type":"string"}}}}},"paths":{"/templates":{"delete":{"tags":["Templates"],"operationId":"deleteTemplate","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["name"],"properties":{"name":{"type":"string","description":"Name of the template to delete"}}}}}},"responses":{"200":{"description":"Template deleted successfully"},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}}}}
```

{% hint style="warning" %}
*La eliminación de un template es irreversible. Si el template está siendo usada en campañas activas, asegúrate de detenerlas antes de eliminarla.*
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://b2chat.gitbook.io/b2chat-api-mensajeria-whatsapp/nuestros-servicios/template.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
