Makes an API send request.

api_send( string template [, string email [,  object vars [, string schedule_time [, object options [, object evars ]]]]] )
api_send( object parameters)

This is for use only within a trigger custom zephyr script.

Make a send API Request:

    • templateName of the valid template
    • emailthe email address to send to; if multi-send, use comma separated email strings
    • varsa key/value hash of the replacement vars to use in the send. Each var may be referenced as {varname} within the template itself
    • schedule_timedo not send the email immediately, but at some point in the future. Any date recognized by PHP’s strtotime function is valid, but be sure to specify timezone or use a UTC time to avoid confusion
    • optionsA key/value hash containing all or one of the following keys: replytotest or behalf_email
    • evarsApplicable only for multi-send; A Key/value hash where each key is an email address, and each value is a key/value hash of variables for that particular email address

This function is basically a Send API call in POST mode


Description: Send email to specific template using given user profile email

{api_send('template_name', 'praj@sailthru.com,ian@sailthru.com')}
Description: Send multiple emails to given template

{api_send('template_name', email + ',praj@sailthru.com')}
Description: Send multiple emails to given template using custom email and user profile email

{api_send({'template':'template_name', 'email':email + ',praj@sailthru.com'})}
Description: Send multiple emails to given template using custom email and user profile email utilizing a map instead of order of parameters

Trigger a Dynamic Welcome Follow Up

Use Case: You have a Welcome Stream that gets triggered after a user subscribes. If the user opens the first message, you want to take them down a certain “engaged users” stream. If they do not, you want to take them down a “disengaged users” stream. Used in conjunction with “if/else” template variables.


{if message.open_time}
{api_send("Welcome 2A - Openers")}
{api_send("Welcome 2B - NonOpeners")}


This script is included in a trigger at the template level and uses a conditional “if” statement to determine whether after a certain amount of time (designated when creating the trigger) a user has opened the message. (Note: this information is stored in and accessible in Zephyr from the “message” object.) After the evaluation has been made, the script uses the api_send() function to send an “Openers” template to those who opened the previous message, and a NonOpeners template to those users who did not.

Cancel and Resend Template Based on a Date (Avoiding Weekends)

Use Case: You have a certain transactional (such as a Welcome email) that you don’t want going out on the weekends. Instead, you’d like it to go out the following Monday.


In the Setup:

{cancel(date("EEEE", time('now')) == "Saturday" || date("EEEE", time('now')) == "Sunday", "It's the weekend")}

In the Trigger:

Event: On Cancel
Time: 0 minutes
Action: Custom Zephyr:

{if date("EEEE",time('now'))=="Sunday"}
{api_send({'template':'Welcome', 'schedule_time':date("EEEE, MMMM d, yyyy hh:mma",time("+24 hours"))})}
{else if date("EEEE",time('now'))=="Saturday"}
{api_send({'template':'Welcome', 'schedule_time':date("EEEE, MMMM d, yyyy hh:mma",time("+48 hours"))})}


This script uses the time() function to return the timestamp of the current day and time, which the “date” function converts to a human readable value. Then using the cancel() function, an evaluation is made to check if the value equals “Saturday” or “Sunday”. Note: The double pipe  (“||”) acts as on “OR” statement.

Assuming that this is the only cancel() statement within the template, a script is triggered in the “Triggers” tab on event send. Using an “if” statement, and similarly using the date() and time() functions, a check is done to see which day it is. If it’s Sunday, the api_send() function will queue the template to resend itself in 24 hours (i.e. on Monday) at the current time. So if the template canceled at 12:30PM on Sunday, it will resend at 12:30PM on Monday. Similarly, if the template canceled on Saturday, api_send() will queue it to resend to the user in 48 hours, i.e. the following Monday.