# WhatsApp Templates

## Send WhatsApp Template to Contact

> Send a WhatsApp template to a contact, even if the chat is closed. The API will also reopen the chat session.\
> \
> \*\*Template Variable Processing:\*\*\
> Templates support advanced variable syntax with the following features:\
> \
> 1\. \*\*Basic Variables\*\*: {{first\_name}}, {{email}}, {{company}}\
> 2\. \*\*Default Values\*\*: {{field|Default Text}} - Shows default if field is empty\
> 3\. \*\*Text Transformations\*\*: \
> &#x20;  \- {{field|uppercase}} - Converts to UPPERCASE\
> &#x20;  \- {{field|lowercase}} - Converts to lowercase\
> &#x20;  \- {{field|capitalize}} - Capitalizes first letter of each word\
> 4\. \*\*Combined Syntax\*\*: {{field|Default Value|transformation}}\
> &#x20;  Example: {{company|Your Company|uppercase}}\
> \
> \*\*Note:\*\* WhatsApp templates require Meta approval. The system automatically converts named variables to numbered placeholders ({{1}}, {{2}}, etc.) for WhatsApp API compatibility.<br>

```json
{"openapi":"3.1.0","info":{"title":"DM Champ API","version":"1.0.0"},"servers":[{"url":"https://api.dmchamp.com/v1","description":"Production API Server"}],"security":[{"ApiKeyAuth":[]},{"UserIdAuth":[]}],"components":{"securitySchemes":{"ApiKeyAuth":{"type":"apiKey","in":"query","name":"apiKey","description":"Your DM Champ API key. Obtain from Settings → API Keys."},"UserIdAuth":{"type":"apiKey","in":"query","name":"userId","description":"Your DM Champ User ID. Alternative to apiKey authentication. Cannot be used for agency-only endpoints."}},"parameters":{"ApiKeyParam":{"name":"apiKey","in":"query","description":"API key for authentication. At least one of apiKey or userId is required for protected endpoints.","required":false,"schema":{"type":"string"}}}},"paths":{"/whatsapp-templates/send":{"post":{"summary":"Send WhatsApp Template to Contact","description":"Send a WhatsApp template to a contact, even if the chat is closed. The API will also reopen the chat session.\n\n**Template Variable Processing:**\nTemplates support advanced variable syntax with the following features:\n\n1. **Basic Variables**: {{first_name}}, {{email}}, {{company}}\n2. **Default Values**: {{field|Default Text}} - Shows default if field is empty\n3. **Text Transformations**: \n   - {{field|uppercase}} - Converts to UPPERCASE\n   - {{field|lowercase}} - Converts to lowercase\n   - {{field|capitalize}} - Capitalizes first letter of each word\n4. **Combined Syntax**: {{field|Default Value|transformation}}\n   Example: {{company|Your Company|uppercase}}\n\n**Note:** WhatsApp templates require Meta approval. The system automatically converts named variables to numbered placeholders ({{1}}, {{2}}, etc.) for WhatsApp API compatibility.\n","tags":["WhatsApp Templates"],"parameters":[{"$ref":"#/components/parameters/ApiKeyParam"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["contactId","whatsappTemplateId"],"properties":{"contactId":{"type":"string","description":"ID of the contact to send the template to"},"whatsappTemplateId":{"type":"string","description":"ID of the WhatsApp template to send"}}}}}},"responses":{"200":{"description":"Template sent successfully","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean"},"data":{"type":"string"}}}}}},"400":{"description":"Invalid request","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean"},"error_code":{"type":"integer"},"error":{"type":"string"}}}}}},"403":{"description":"Twilio credentials not found","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean"},"error_code":{"type":"integer"},"error":{"type":"string"}}}}}},"500":{"description":"Server error","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean"},"error_code":{"type":"integer"}}}}}}}}}}}
```

## Get WhatsApp Templates

> Retrieve all WhatsApp templates for the authenticated user

```json
{"openapi":"3.1.0","info":{"title":"DM Champ API","version":"1.0.0"},"servers":[{"url":"https://api.dmchamp.com/v1","description":"Production API Server"}],"security":[{"ApiKeyAuth":[]},{"UserIdAuth":[]}],"components":{"securitySchemes":{"ApiKeyAuth":{"type":"apiKey","in":"query","name":"apiKey","description":"Your DM Champ API key. Obtain from Settings → API Keys."},"UserIdAuth":{"type":"apiKey","in":"query","name":"userId","description":"Your DM Champ User ID. Alternative to apiKey authentication. Cannot be used for agency-only endpoints."}},"parameters":{"ApiKeyParam":{"name":"apiKey","in":"query","description":"API key for authentication. At least one of apiKey or userId is required for protected endpoints.","required":false,"schema":{"type":"string"}}}},"paths":{"/whatsapp-templates":{"get":{"summary":"Get WhatsApp Templates","description":"Retrieve all WhatsApp templates for the authenticated user","tags":["WhatsApp Templates"],"parameters":[{"$ref":"#/components/parameters/ApiKeyParam"}],"responses":{"200":{"description":"Successfully retrieved WhatsApp templates","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean"},"data":{"type":"array","items":{"type":"object","properties":{"id":{"type":"string","description":"Template ID"},"name":{"type":"string","description":"Template name"},"status":{"type":"string","description":"Template approval status"},"language":{"type":"string","description":"Template language"},"category":{"type":"string","description":"Template category"},"components":{"type":"array","description":"Template components"},"createdAt":{"type":"string","format":"date-time","description":"Template creation timestamp"},"template":{"type":"object","description":"Full template data"}}}}}}}}},"400":{"description":"Invalid request","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean"},"error_code":{"type":"integer"},"error":{"type":"string"}}}}}},"500":{"description":"Server error","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean"},"error_code":{"type":"integer"},"error":{"type":"string"}}}}}}}}}}}
```
