The templates system is used manage templates and render content from existing templates. Templates can be used, for instance, when sending emails and text messages. Custom branding and dynamic fields can be added into templates.
The templates system consists of two main components: Template Descriptors and Template Versions (also sometimes simply referred to as "templates"). A Template Descriptor is a configuration object that defines the structure of a template. A Template Version is a specific instance of a template that contains the actual content.
A Template Descriptor many have many Template Versions associated with it. There can be only one "active" Template Version at a time.
Peach uses Jinja templating. Therefore all templates use Jinja template syntax, and must be a valid Jinja template to render.
When a template is rendered, context variables are passed into the template. If a template looks like:
Hello {{foo}}, your loan is due on {{bar}}.
then the context variables in the template are foo
and bar
. If, when the template is
rendered, the provided context is:
{
"foo": "John",
"bar": "2021-01-01"
}
...then the rendered template will be:
Hello John, your loan is due on 2021-01-01.
OK
Bad request
[- {
- "id": "TD-AAAA-BBBB",
- "companyId": "CP-AAAA-BBBB",
- "activeVersionId": "string",
- "subject": "annualPrivacyPolicyNotice",
- "channel": "voice",
- "language": "en",
- "productId": "LT-AAAA-BBBB",
- "sensitive": false,
- "enabled": true,
- "name": "string"
}
]
OK
Bad request
{- "subject": "annualPrivacyPolicyNotice",
- "channel": "voice",
- "language": "en",
- "productId": "LT-AAAA-BBBB",
- "sensitive": false,
- "enabled": true,
- "name": "string"
}
{- "id": "TD-AAAA-BBBB",
- "companyId": "CP-AAAA-BBBB",
- "activeVersionId": "string",
- "subject": "annualPrivacyPolicyNotice",
- "channel": "voice",
- "language": "en",
- "productId": "LT-AAAA-BBBB",
- "sensitive": false,
- "enabled": true,
- "name": "string"
}
OK
Bad request
{- "id": "TD-AAAA-BBBB",
- "companyId": "CP-AAAA-BBBB",
- "activeVersionId": "string",
- "subject": "annualPrivacyPolicyNotice",
- "channel": "voice",
- "language": "en",
- "productId": "LT-AAAA-BBBB",
- "sensitive": false,
- "enabled": true,
- "name": "string"
}
The updated template descriptor
OK
Bad request
{- "subject": "annualPrivacyPolicyNotice",
- "channel": "voice",
- "language": "en",
- "productId": "LT-AAAA-BBBB",
- "sensitive": false,
- "enabled": true,
- "name": "string"
}
{- "id": "TD-AAAA-BBBB",
- "companyId": "CP-AAAA-BBBB",
- "activeVersionId": "string",
- "subject": "annualPrivacyPolicyNotice",
- "channel": "voice",
- "language": "en",
- "productId": "LT-AAAA-BBBB",
- "sensitive": false,
- "enabled": true,
- "name": "string"
}
List all template versions for the given template descriptor.
OK
[- {
- "id": "TV-AAAA-BBBB",
- "descriptorId": "TD-AAAA-BBBB",
- "status": "draft",
- "subjectLineTemplate": "Hello {{foobar}}",
- "contentTextTemplate": "Hello {{foobar}}",
- "contentHtmlTemplate": "Hello,<br/><p>{{foobar}}</p>"
}
]
List all template versions.
Deprecated in favor of /v2/communicator/templates
.
This dumps all template versions (regardless of active status) without paging.
OK
[- {
- "id": "TV-AAAA-BBBB",
- "descriptorId": "TD-AAAA-BBBB",
- "status": "draft",
- "subjectLineTemplate": "Hello {{foobar}}",
- "contentTextTemplate": "Hello {{foobar}}",
- "contentHtmlTemplate": "Hello,<br/><p>{{foobar}}</p>"
}
]
Create a new template versions.
The new version will not be active until it is activated with the activate endpoint.
The new template
OK
Bad request
{- "descriptorId": "TD-AAAA-BBBB",
- "status": "draft",
- "subjectLineTemplate": "Hello {{foobar}}",
- "contentTextTemplate": "Hello {{foobar}}",
- "contentHtmlTemplate": "Hello,<br/><p>{{foobar}}</p>"
}
{- "id": "TV-AAAA-BBBB",
- "descriptorId": "TD-AAAA-BBBB",
- "status": "draft",
- "subjectLineTemplate": "Hello {{foobar}}",
- "contentTextTemplate": "Hello {{foobar}}",
- "contentHtmlTemplate": "Hello,<br/><p>{{foobar}}</p>"
}
List all Templates Versions for all Template Descriptors.
OK
{- "status": 0,
- "count": 0,
- "data": [
- {
- "id": "TV-AAAA-BBBB",
- "descriptorId": "TD-AAAA-BBBB",
- "status": "draft",
- "subjectLineTemplate": "Hello {{foobar}}",
- "contentTextTemplate": "Hello {{foobar}}",
- "contentHtmlTemplate": "Hello,<br/><p>{{foobar}}</p>"
}
]
}
{- "id": "TV-AAAA-BBBB",
- "descriptorId": "TD-AAAA-BBBB",
- "status": "draft",
- "subjectLineTemplate": "Hello {{foobar}}",
- "contentTextTemplate": "Hello {{foobar}}",
- "contentHtmlTemplate": "Hello,<br/><p>{{foobar}}</p>"
}
OK
Bad request
{- "descriptorId": "TD-AAAA-BBBB",
- "status": "draft",
- "subjectLineTemplate": "Hello {{foobar}}",
- "contentTextTemplate": "Hello {{foobar}}",
- "contentHtmlTemplate": "Hello,<br/><p>{{foobar}}</p>"
}
{- "id": "TV-AAAA-BBBB",
- "descriptorId": "TD-AAAA-BBBB",
- "status": "draft",
- "subjectLineTemplate": "Hello {{foobar}}",
- "contentTextTemplate": "Hello {{foobar}}",
- "contentHtmlTemplate": "Hello,<br/><p>{{foobar}}</p>"
}
Set's the given template version as active.
A template descriptor can have exactly one "active" version. The active template version is what's used to generate the content of the messages.
OK
Render the template contents of the given Template Version using the given context.
The three contents are returned in a single JSON response, they are contentHtml
,
contentText
and subjectLine
.
Context data
OK
{- "personId": "string",
- "context": { }
}
{- "subjectLine": "string",
- "contentHtml": "string",
- "contentText": "string"
}
Render a file (text
, html
or pdf
) from this Template Version and download it.
Only the content matching the fmt
query parameter is returned in the file.
The rendered template file is then downloaded as an attachment. (i.e., a
response is sent with the header Content-Disposition: attachment
.)
Note: that a Document Descriptor is NOT created.
Template selectors and the data
OK
{- "subject": "annualPrivacyPolicyNotice",
- "channel": "email",
- "personId": "string",
- "loanId": "string",
- "caseId": "string",
- "context": { },
- "overrideTemplateId": "TV-AAAA-BBBB"
}
List all context variables used in the given template version.
If a template looks like:
Hello {{name}},
Your loan {{loanName}} is due on {{dueDate}}.
Thanks,
{{companyName}}
{{SOME_MACRO()}}
The context variables are name
, loanName
, dueDate
and companyName
as
well as whatever context variables are defined in SOME_MACRO()
(but
SOME_MACRO
itself is NOT a context variable). Note that this means
sometimes a Template Version may contain many context variables since all possible
context variables are included in this list.
OK
[- "string"
]
Export all template descriptors and template versions for a company. The export is in JSON format. It can be used with the import endpoint to restore templates.
OK
[- null
]
Import exported template descriptors and template versions for a company. The exported
data should come from the /communicator/templates/export
endpoint.
The import will create new template descriptor if a matching one does not exist and will create new template versions if a matching one does not exist. This is often used to "promote" templates from a testing environment to a production environment.
The exported template data
Successfully imported
[- null
]
Request sandbox access