POST /api/templates Create a new notification template. Link it to channels, define a variable schema for personalization, and optionally assign a custom template ID.

Headers

appid
string
required
Your CometChat App ID.
apikey
string
required
Your CometChat API Key.

Request body

name
string
required
Display name for the template.
channelIds
string[]
required
Array of channel IDs to link this template to.
templateId
string
Optional custom template identifier. Auto-generated if omitted.
category
string
Optional category for organizing templates.
config
object
Optional template-level configuration.
variableSchema
object
Variable declarations. Each key is a variable name with a type of string, image, or action.

Example request

curl -X POST https://{appId}.api-{region}.cometchat.io/v3/business-messaging/api/templates \
  -H "appid: YOUR_APP_ID" \
  -H "apikey: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Welcome Message",
    "channelIds": ["664a1b2c3d4e5f6a7b8c9d0e"],
    "category": "onboarding",
    "variableSchema": {
      "userName": { "type": "string" },
      "profileUrl": { "type": "action" }
    }
  }'

Example response

{
  "id": "665b2c3d4e5f6a7b8c9d0e1f",
  "appId": "YOUR_APP_ID",
  "name": "Welcome Message",
  "templateId": "welcome-message",
  "status": "draft",
  "category": "onboarding",
  "channelIds": ["664a1b2c3d4e5f6a7b8c9d0e"],
  "variableSchema": {
    "userName": { "type": "string" },
    "profileUrl": { "type": "action" }
  },
  "config": {},
  "createdAt": "2024-01-15T09:30:00.000Z",
  "updatedAt": "2024-01-15T09:30:00.000Z"
}
New templates are created in draft status. Update the status to approved via the update template endpoint before using it for notifications.