Docs
/
/

Templates mAPI reference

Complete reference documentation for the Templates resource.

Templates

#

Templates represent the templated contents of a message sent to an individual recipient on a specific channel.

There are no endpoints for working directly with templates, instead you must do so through modifying a workflow.

Preview a template

#

Renders a template preview, without requiring a template to be persisted within Knock. This is useful for previewing templates in isolation, without the need to use a workflow.

For email templates, you can optionally specify a layout by key or provide inline layout content.

Endpoint

POST/v1/templates/preview

Query parameters

environment
string

The environment slug.

branch
string

The slug of a branch to use. This option can only be used when environment is "development".

Request body

The actor to reference in the preview.

channel_type
enum(string)
Required

The channel type of the template to preview.

emailsmspushchatin_app_feed
data
object(any)

The data to pass to the template for rendering.

layout
object

Email layout configuration. Only applicable for email channel type. Falls back to environment default if not provided.

html_content
string

Inline HTML content for the layout. Must include {{ content }} placeholder.

key
string

The key of an existing email layout to use.

text_content
string

Inline text content for the layout.

recipient
2 possible types
Required

A recipient reference, used when referencing a recipient by either their ID (for a user), or by a reference for an object.

template
5 possible types
Required

The template content to preview. Structure depends on channel_type.

tenant
string

The tenant to associate with the preview. Must not contain whitespace.

workflow
object

Optional workflow context for variable hydration. When provided, recipient/actor/tenant are resolved via Knock.

categories
string[]

Workflow categories.

commercial
boolean

Whether the workflow is marked as commercial messaging.

key
string
Required

The workflow key.

override_preferences
boolean

Whether to ignore recipient preferences for a given type of notification. If true, will send for every channel in the workflow even if the recipient has opted out of a certain kind. Defaults to false.

Returns

PreviewTemplateResponse

A response to a template preview request.

content_type
enum(string)

The content type of the preview.

emailin_app_feedpushchatsms
errors
object[]

A list of errors encountered during rendering. Present when result is "error".

field
string

The template field that caused the error, if available.

line
integer

The line number where the error occurred, if available.

message
string
Required

A human-readable description of the error.

result
enum(string)

The result of the preview.

successerror
template
5 possible types

The rendered template, ready to be previewed.

ChatTemplate

#

A chat template.

Attributes

json_body
string

A JSON template for the chat notification message payload. Only present if not using the markdown body.

markdown_body
string

The markdown body of the chat template.

summary
string

The summary of the chat template. Used by some chat apps in their push notifications.

EmailTemplate

#

An email message template.

Attributes

html_body
string

An HTML or MJML template for the email body. Required if visual_blocks is not provided. Only one of html_body or visual_blocks should be set. When is_mjml is true, this must contain MJML components. Supports Liquid templating with variables like {{ recipient.name }}, {{ actor.name }}, {{ vars.app_name }}, {{ data.custom_field }}, and {{ tenant.name }}. See the template variables reference for available variables.

is_mjml
boolean

Whether this template uses MJML format. When true, the template content will be compiled from MJML to HTML. Only valid when the selected layout is also MJML or when no layout is selected.

settings
EmailTemplateSettings

The settings for the email template. Must be supplied with at least layout_key.

attachment_key
string

The object path in the workflow trigger's data payload to resolve attachments.Defaults to attachments.

layout_key
string

The key of the email layout that wraps the email template. When omitted, the email template will need to define the <html> structure.

pre_content
string

A liquid template that will be injected into the email layout above the message template content. Useful for setting variables that should be available to the email layout.

subject
string

The subject of the email. Supports Liquid templating with variables like {{ recipient.name }}, {{ actor.name }}, {{ vars.app_name }}, {{ data.custom_field }}, and {{ tenant.name }}. See the template variables reference for available variables.

text_body
string

A text template for the email body. When omitted, the email template will be autogenerated from the html_body or visual_blocks.

visual_blocks
object[]

The visual blocks that make up the email template. Required if html_body is not provided. Only one of html_body or visual_blocks should be set.

PushTemplate

#

A push notification template.

Attributes

settings
object

The settings for the push template.

delivery_type
enum(string)

The delivery type of the push notification. Set as silent to send a data-only notification. When set to silent, no body will be sent.

silentcontent
payload_overrides
string

A JSON object that overrides the payload sent to the push provider.

text_body
string

The body of the push notification.

title
string

The title of the push notification.

SmsTemplate

#

An SMS template.

Attributes

settings
object

The settings for the SMS template. Can be omitted.

text_body
string

The message of the SMS.

InAppFeedTemplate

#

An in-app feed template.

Attributes

action_buttons
object[]

The action buttons of the in-app feed message.

action
string
Required

The URI for this action.

label
string
Required

The label of the action button.

action_url
string

The URL to navigate to when the in-app feed is tapped. Can be omitted for multi-action templates, where the action buttons will be used instead.

markdown_body
string

The markdown body of the in-app feed.

RequestTemplate

#

A request template for a fetch function step.

Attributes

body
string

The body of the request. Only used for POST or PUT requests.

headers
2 possible types

The headers of the request. Can be a template string or a list of key-value pairs.

method
enum(string)

The HTTP method of the request.

getpostputdeletepatch
query_params
2 possible types

The query params of the request. Can be a template string or a list of key-value pairs.

url
string

The URL of the request.

WebhookTemplate

#

A webhook template. By default, a webhook step will use the request settings you configured in your webhook channel. You can override this as you see fit on a per-step basis.

Attributes

body
string

The body of the request. Only used for POST or PUT requests.

headers
object[]

A list of key-value pairs for the request headers. Each object should contain key and value fields with string values.

key
string
Required

The key of the header.

value
string
Required

The value of the header.

method
enum(string)

The HTTP method of the webhook.

getpostputdeletepatch
query_params
object[]

A list of key-value pairs for the request query params. Each object should contain key and value fields with string values.

key
string
Required

The key of the query param.

value
string
Required

The value of the query param.

url
string

The URL of the webhook.

New chat