API Docs

Create Template

Create reusable templates for SMS, WhatsApp, and Email notifications. Templates support variable substitution using double curly braces (e.g., {{name}}) for dynamic content.

Headers

  • Authorization: Bearer YOUR_API_KEY
  • Content-Type: application/json

Body Parameters

name

Required - Unique name for the template (alphanumeric and underscores only).

type

Required - Template type: "sms", "whatsapp", or "email".

content

Required - Template content with variable placeholders (e.g., {{name}}).

description

Optional - Description of the template's purpose.

subject

Optional - Email subject line (required for email templates).

Sample Requests

Create SMS Template

curl -X POST https://api.ping.co.zw/v1/notification/api/templates \
-H "Authorization: Bearer sk_test_your_api_key_here" \
-H "Content-Type: application/json" \
-d '{
  "name": "appointment_reminder",
  "type": "sms",
  "content": "Hi {{name}}, your appointment with {{doctor}} is scheduled for {{date}} at {{time}}. Please reply CONFIRM to confirm.",
  "description": "Appointment reminder SMS for patients"
}'

Response Format

Success Response

{
  "result": "success",
  "message": "Template created successfully",
  "environment": "test",
  "template": {
    "id": "template_uuid_here",
    "name": "appointment_reminder",
    "type": "sms",
    "content": "Hi {{name}}, your appointment with {{doctor}} is scheduled for {{date}} at {{time}}. Please reply CONFIRM to confirm.",
    "description": "Appointment reminder SMS for patients",
    "isActive": true,
    "dateCreated": "2024-01-15T10:30:00Z"
  }
}

Error Response

{
  "result": "error",
  "error": {
    "type": "BadRequest",
    "message": "Template name already exists"
  }
}

Template Variables

Templates support variable substitution using double curly braces. Variables are replaced with actual values when sending notifications.

Variable Syntax

  • {{variable_name}} - Basic variable
  • {{user.name}} - Nested object property
  • {{items[0].name}} - Array element

Common Variables

  • name - Customer/user name
  • email - Email address
  • phone - Phone number
  • date - Date values
  • amount - Monetary amounts
  • order_number - Order/transaction IDs
  • company_name - Business name

Template Types

SMS Templates

  • Character limit: 160 characters (longer messages are split)
  • Plain text only
  • Unicode characters supported

Email Templates

  • HTML and plain text content
  • Subject line required
  • CSS styling supported
  • Embedded images via base64

WhatsApp Templates

  • Rich text with emojis
  • Media attachments supported
  • Interactive buttons (requires approval)
  • Must comply with WhatsApp policies

Template Naming Rules

  • Must be unique within your account
  • Alphanumeric characters and underscores only
  • No spaces or special characters
  • Maximum 50 characters
  • Case-sensitive

Best Practices

  • Use descriptive template names (e.g., "welcome_email", "payment_reminder")
  • Test templates with sample data before using in production
  • Keep SMS templates under 160 characters when possible
  • Use consistent variable naming across templates
  • Include fallback content for optional variables
  • Document template variables for team members

Using Templates

Once created, you can use templates when sending notifications by referencing the template name and providing the variable data:

{
  "to_phone": "+263771234567",
  "template_name": "appointment_reminder",
  "template_data": {
    "name": "John Doe",
    "doctor": "Dr. Smith",
    "date": "2024-01-20",
    "time": "2:00 PM"
  }
}