Skip to content

Using templates and workflows in Nylas

The Nylas Templates and Workflows endpoints work together to enable custom message flows triggered by specific events.

You can create templates and workflows associated with either a Nylas application or a specific grant. For the purposes of this documentation, we reference the application-level Templates and Workflows endpoints.

You can use the Templates endpoints to create and manage reusable email templates with custom variables. When you create a template, you specify its content and the templating engine to use when rendering it.

Nylas supports the following templating engines:

After you create a template, you can pass its ID in a Create Workflow request to define the message the workflow sends.

When you create a template, you might want to show a date or time in it given a Unix timestamp. Nylas supports formatDate, a helper function for Handlebars, Nunjucks, and Twig that renders dates and times from a Unix timestamp.

mustache }} doesn’t support helper functions. If you choose to use it to render your templates, it won’t format Unix timestamps as a date or time.

formatDate accepts the following parameters:

ParameterDescriptionDefault
timestamp *The time to render, in seconds using the Unix timestamp format.
timezoneThe IANA-formatted time zone used to calculate the output."UTC"
formatThe output format. Supports the options described in the Luxon library."fff"
localeThe output language. Supports the language codes defined in ISO 639."en"

When you use formatDate, the ordering of its parameters matters. If you want to use only one optional parameter, you need to pass null for the other options. When a parameter is null, Nylas uses its default value.

Format dates and times in Handlebars templates

Section titled “Format dates and times in Handlebars templates”

formatDate follows the {{ formatDate timestamp timezone format locale }} format in Handlebars templates.

Format dates and times in Nunjucks and Twig templates

Section titled “Format dates and times in Nunjucks and Twig templates”

formatDate follows the {{ timestamp|formatDate(timezone, format, locale) }} format in Nunjucks and Twig templates.

Use notification data in template variables

Section titled “Use notification data in template variables”

Workflows support all notifications that Nylas sends. When an event triggers a workflow, Nylas automatically includes the information from its data object as a set of template variables. For example, if your project receives a booking.created notification, you can access its information in your template.

If you’re sending notifications to a single recipient, Nylas automatically passes their email address, first name, and last name to the template as a set of variables: recipient.email, recipient.first_name, and recipient.last_name respectively. You can reference these variables in your template to personalize the notification.

For trigger events that include a participants object (for example, booking.created notifications), you can set up your workflow to send a message to all participants at once, or each participant individually.

By default, Nylas sends messages to all participants at once. If you want to notify individual participants for bookings notifications, add "notify_individually": "true" to the additional_fields object.

curl --request POST \
--url "https://api.us.nylas.com/v3/scheduling/bookings?configuration_id=<SCHEDULER_CONFIG_ID>" \
--header 'Accept: application/json, application/gzip' \
--header 'Content-Type: application/json' \
--data '{
"additional_fields": {
"notify_individually": "true"
},
"end_time": 1709645400,
"guest": {
"name": "Nyla",
"email": "[email protected]"
},
"participants": [],
"start_time": 1709643600
}'

To notify individual participants for events notifications, add "notify_individually": "true" to the metadata object.

curl --request POST \
--url "https://api.us.nylas.com/v3/grants/<NYLAS_GRANT_ID>/events?calendar_id=<CALENDAR_ID>" \
--header 'Accept: application/json, application/gzip' \
--header 'Authorization: Bearer <NYLAS_API_KEY>' \
--header 'Content-Type: application/json' \
--data '{
"busy": true,
"description": "Come ready to talk philosophy!",
"location": "New York Public Library, Cave room",
"metadata": {
"notify_individually": "true"
},
"participants": [
{
"name": "Leyah Miller",
"email": "[email protected]"
},
{
"name": "Nyla",
"email": "[email protected]"
}
],
"title": "Annual Philosophy Club Meeting",
"when": {
"start_time": 1674604800,
"end_time": 1722382420,
"start_timezone": "America/New_York",
"end_timezone": "America/New_York"
}
}'