How to create a custom event API call

Overview

Sendlane’s API allows you to create custom events that can be used to trigger Automations. In this guide, you'll learn how to set up your own custom triggered automations using a password reset workflow as an example.

In this guide

  1. Create a custom event in Sendlane
  2. Create an API call
  3. Create an automation triggered by the custom event you created

🚦 Before Getting Started

  1. Set up a Sendlane Custom Integration
  2. Review Sendlane's custom event API documentation
1

 Create a custom event in Sendlane

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.

2

 Create an API call

Use a JSON snippet like the following to build a password reset request API call:

{
   "custom_event": "CUSTOM_EVENT_NAME",
   "token": "CUSTOM_EVENT_TOKEN",
   "email": "jimmykim@sendlane.com",
   "data": {
     "password_reset_url": "https://www.yourwebsite.com/reset/1234567890"
   }
}
  • custom_event - Your custom event’s name (our example event’s name is password-reset)
  • token - Grab the token associated with your custom event by heading to the Sendlane Custom Integration page > Click Settings > Click Copy > Paste in place of CUSTOM_EVENT_TOKEN

Test your call to confirm your setup. You're good to go if your call is successful and you see example data on the custom events page If your event does not show data in the example column like the example below, review your custom event and API call setup:

3

 Create an automation triggered by the custom event you created

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, we selected 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 and data 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() %}

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"
   }
}

Now that we’ve set up our data variable, we can access the password_reset_url via templating syntax:

{{-data.password_reset_url-}}

Pasting this snippet directly into the email will display a raw password reset link. Use the hyperlink function in the email builder, a button, or a custom HTML block to hyperlink the URL.

In the email below, our {{-data.password_reset_url-}} is made into a hyperlink, and our variable scripts disappear when the email is previewed.

Additional Resources

Did this answer your question? Thanks for your feedback! There was a problem submitting your feedback. Please try again!