api_user
Description
Makes an API user request.
api_user( object options [, string id ] )
This is for use only within a trigger custom zephyr script. Make a user API Request
options
A Key/Value Hash containing one or all itemskey
the key type of idfields
the fields to returnkeys
set some or all of the user keyskeysconflict
define behavior if keys conflict with existing keyslists
key/value hash; each key is the name of a list, and each value is 1 to subscribe the user from that list and 0 to remove the user from the listvars
key/value hash of replacement variables you want to set or a json stringoptout_email
set email opt-out status to `none`, `all`, or `blast`login
mark the user as logged in – pass site to represent a site login, app to represent an app login, and optionally user_agent and ip
id
If not set, ID (SID) will be used
This function is basically a User API call in POST mode
Examples
api_user({"lists": {"listA": 1, "listB": 0}})
To set for a different email:
api_user({"lists": {"listA": 1, "listB": 0, "key": "email"}}, "joe@example.com")
Set Random Variable on Users for Future Cohort Testing
Use Case: Use in conjunction with Sailthru Trigger functionality to set a value between 0-9 on users upon receipt of a Welcome transactional. This allows you to pre-segment out your users immediately for down-the-line testing (ex. Exclude everyone with “welcome_segment = 0” from the rest of the Welcome Series or a Reengagement Series as a testing benchmark). Used in conjunction with “random()”
Zephyr:
{api_user({"vars": {"welcome_received": random(10)}})}
Output:
Explanation:
This script uses the api_user() function to set a custom field (var called “welcome_received”) on a user upon receipt of a transactional template (in this scenario, a Welcome email). For user segmentation purposes, the script also uses random() to create a randomized value between 0-9 upon receiving this transactional. This is beneficial for future cohort testing as you’ll have pre-established user buckets.Set Current Date/Time as User Profile Field Value
Use Case: Used in conjunction with the date() function, apply a date value to a user profile after they receive a “Subscription Cancellation” template in order to re-target down the line (ex. 30 days later, send an offer for 15% off if they resubscribe)
Zephyr:
{api_user({"vars" : {"canceled_date" : date('yyyy-MM-dd', time("now"))}})}
Output:
Explanation: