Promo Code Added via API
Let's see how to add promo codes to trigger messages using API methods:
- Generate event (via workflow),
- Send prepared message (without workflow).
Generate Event Method
The Generate event method allows you to send any custom events that can launch workflows.
To substitute a promo code transmitted via API into a trigger message, do the following:
- Set up the transfer of the necessary parameters in the event.
- Add a variable to the message.
- Create a workflow.
1. Setting event parameters
The event must contain a promo code and contact identifier for sending the message (e.g., an email address for sending an email or a token for mobile app).
Event parameters:
{
"params": [
{
"name": "token",
"value": "fx19jopCg0VUllNEkYPYoK:APA91bHwrnt1Gs6bt3aokzMsLaxfrpbOIQa3wcRdzGb7JdHqM_g4wSMKKHP9yzdnZ2k_tJrBcmCaOtMmJ2JjPu8uvhpY40-krp7Xav2zugh63pe_Ro2_AmVLcac9KBhUxSB4eRZtMKp4"
},
{
"name": "promocode",
"value": "ABC-123"
}
]
}
, where code is the variable's name used in the message, and ABC-123 is the promotional code the contact will receive.
2. Substituting variable in the message
Insert the variable's name containing the promo code into the message in the $!data.get('code') format. Instead of a variable, the contact will see the promo code passed in the event.

3. Creating the workflow
In the message block in the workflow, specify the event parameter that contains the contact identifier for sending the message (in our example, this is a token; for other channels, use the appropriate IDs).

Read more about launching a workflow on an event in the instructions >
Send Prepared Message Method
The Send prepared message method allows you to send campaigns to one or more contacts.
You can send a unique promo code to each contact.
Request format:
{
"recipients": [{
"locator": "mail@example.com",
"jsonParam": "{\"code\":\"ABC-123\"}"
}],
"email": true
}
, where the recipients array contains elements with jsonParam. It can be used to send any data to a message, including a promo code. The data for the message must be in JSON format converted to a string.
Use message ID instead of {id} in https://api.esputnik.com/api/v1/message/{id}/smartsend
request.
In the message, use a variable in the $!data.get('code')
format.
Updated 3 days ago