How to Create a Custom Event API Call
In this guide, we’ll set up an event and Automation that sends emails containing password reset links to Contacts who have requested to reset their password.
🚦 Before Getting Started
- Set up a Sendlane Custom Integration
- Review Sendlane's custom event API documentation
- 1
-
Go to your completed Sendlane Custom Integration and click the Events icon. On the Events page, click Create Event > Enter a descriptive name > Create.
We’ll name our example event
password-reset
. -
Create a Custom Event
- 2
-
Use a JSON snippet like the following to build a password reset request API call:
{ "token": "CUSTOM_EVENT_TOKEN", "email": "jimmykim@sendlane.com" "custom_event": "CUSTOM_EVENT_NAME", "data": { "password_reset_url": "https://www.yourwebsite.com/reset/456789745" } }
custom_event
- Your custom event’s name (our example event’s name ispassword-reset
)
token
- Sendlane Custom Integration page > Click Settings > Click Copy
Create an API Call
- 3
-
Create an Automation and select the Custom Event trigger from the Custom integration tab.
Trigger Options
Store - Select your store
Event - Select the password-reset event
Limit Per Contact - Select a limit for how and when Contacts are sent through the Automation. For our password reset example, select No Limit so Contacts can reset their password as many times as needed.
- No Limit - The Contact will be sent through the Automation whenever the trigger conditions are met
- Do not trigger when already in Automation - If the trigger conditions are met but the Contact is already being sent through the Automation, the Contact will not trigger the Automation again
- Once Per Day - If the trigger conditions are met but the Contact has already triggered the Automation on the same day, the Contact will not trigger the Automation again
- One Time Only - Contacts will only trigger the Automation one time
Add a Wait Node
Add a wait node of as the first step of the Automation. For our password reset example, we’ll use 1 minute. Wait nodes default to a 1 hour wait.
Add an Email Node
Create an email node and use Twig templating syntax to pull in data from the payload. Sendlane supports a subset of the Twig language.
Variables
Creating variables allows you to populate data in your email using templating syntax.
For our password reset example, we’ll want to be able to populate the name of our event and data from the payload in our API call. We’ll need two variables;
name
to access the event’s name anddata
to access data from the payload, including a URL to the password reset page.To create variables, add a text box element to your email, then copy and paste the following snippets into the text box. The snippets will not be visible to Contacts who receive your email, they are only visible to you inside the Sendlane email builder.
{% set name = trigger.getCustomEventName() %} {% set data = trigger.getCustomEventData() %}<br>
Once these variables are in place, they can be used to populate data!
Populating Data in an Email
In step 2, we made the API call with the following JSON payload
{ "token": "1234abcd5678edfg", "email": "jimmykim@sendlane.com", "custom_event": "password-reset", "data": { "password_reset_url": "https://www.yourwebsite.com/reset/456789745" } }<br>
Now that we’ve set up our
data
variable, we can access thepassword_reset_url
via Twig{{-data.password_reset_url-}}<br>
Pasting this snippet directly into the email will display a raw password reset link. Use the hyperlink function in the email builder or a custom HTML block to hyperlink the URL.
In the email below, our
password_reset_url
is made into a hyperlink, and our variable scripts disappear when the email is previewed.