Skip to content

Templates

A template is a saved body for campaigns. It can use these variables:

Variable Filled with
{{first_name}} The contact’s first name.
{{last_name}} The contact’s last name.
{{custom.<key>}} A custom field, such as {{custom.branch}}.
{{first_name|there}} Any variable with a fallback after |, used when the value is empty. Up to 60 characters.

A missing value without a fallback renders as nothing, and the doubled space it leaves collapses. Anything else in double braces is invalid. Bodies are encrypted at rest. A campaign copies the text when it is created, so editing or deleting a template never changes a campaign.

Field Type Description
id string tpl_…
name string Unique in your organization.
body string The text with variables.
variables string[] Variables used, such as ["first_name", "custom.branch"].
preview object { encoding, segments, characters } of the body rendered for a sample contact.
createdAt, updatedAt string
GET/v1/templatescampaigns:read
Query Type Description
q string Text contained in the name.
limit integer 1 to 200, default 50.
cursor string nextCursor from the previous page.
Terminal window
curl https://api.smsfabric.com/v1/templates \
-H "X-Api-Key: $SMSFABRIC_API_KEY"
POST/v1/templatescampaigns:manage

Returns 201. Supports Idempotency-Key.

Body field Type Required Constraints
name string Yes 1 to 120 characters, unique.
body string Yes 1 to 1,600 characters; valid variables only.
Terminal window
curl https://api.smsfabric.com/v1/templates \
-H "X-Api-Key: $SMSFABRIC_API_KEY" \
-H "Content-Type: application/json" \
-d '{"name": "Winter sale", "body": "Hi {{first_name|there}}, the winter sale starts Friday at {{custom.branch}}. Reply STOP to opt out."}'
{
"id": "tpl_h7k0n3q6t9w2z5c8f1i4l7o0",
"name": "Winter sale",
"body": "Hi {{first_name|there}}, the winter sale starts Friday at {{custom.branch}}. Reply STOP to opt out.",
"variables": ["first_name", "custom.branch"],
"preview": { "encoding": "GSM7", "segments": 1, "characters": 86 },
"createdAt": "2026-11-19T11:20:00.000Z",
"updatedAt": "2026-11-19T11:20:00.000Z"
}
Error When
400 template_invalid An unknown variable, stray braces or a fallback over 60 characters. errors[] lists each one.
409 template_exists A template with this name exists.
POST/v1/templates/previewcampaigns:read

Renders a body for one of your contacts, or for a sample contact. Returns 200, never 400 for template problems: they come back in issues (unknown_variable, malformed or fallback_too_long).

Body field Type Required Constraints
body string Yes 1 to 1,600 characters.
contactId string No A contact in your organization.
Terminal window
curl https://api.smsfabric.com/v1/templates/preview \
-H "X-Api-Key: $SMSFABRIC_API_KEY" \
-H "Content-Type: application/json" \
-d '{"body": "Hi {{first_name}}, your {{custom.tier}} points: {{custom.loyalty_points}}", "contactId": "con_a8d1g4j7m0p3s6v9y2b5e8h1"}'
{
"rendered": "Hi Mona, your points: 1250",
"variables": ["first_name", "custom.tier", "custom.loyalty_points"],
"issues": [],
"segments": { "encoding": "GSM7", "segments": 1, "characters": 26 }
}

404 not_found if contactId is not in your organization.

GET/v1/templates/:idcampaigns:read
Terminal window
curl https://api.smsfabric.com/v1/templates/tpl_h7k0n3q6t9w2z5c8f1i4l7o0 \
-H "X-Api-Key: $SMSFABRIC_API_KEY"
PATCH/v1/templates/:idcampaigns:manage

Takes name and body, both optional, with the create constraints. Returns the template.

Terminal window
curl -X PATCH https://api.smsfabric.com/v1/templates/tpl_h7k0n3q6t9w2z5c8f1i4l7o0 \
-H "X-Api-Key: $SMSFABRIC_API_KEY" \
-H "Content-Type: application/json" \
-d '{"body": "Hi {{first_name|there}}, the winter sale starts Thursday. Reply STOP to opt out."}'
DELETE/v1/templates/:idcampaigns:manage

Returns 204. Campaigns that used it keep their own copy of the text.

Terminal window
curl -X DELETE https://api.smsfabric.com/v1/templates/tpl_h7k0n3q6t9w2z5c8f1i4l7o0 \
-H "X-Api-Key: $SMSFABRIC_API_KEY"