This article demonstrates how to send an email, using the API to trigger an External Event, and populating some simple external data into the email.
The following HTML will be used:
<html>
<head>
<title>API Exercise 3 Example</title>
</head>
<body>
<h2>
Exercise 3 - Placeholders
</h2>
<p>
Dear {{event.firstName}} ,<br>
Please find your order details below:
</p>
<ul>
<li>Ordernumber: {{event.orderNumber}}</li>
<li>Product: {{event.productName}}</li>
<li>Quantity: {{event.Quantity}}</li>
<li>Price: {{event.Price}}</li>
</ul>
</body>
</html>
In this example, there are five different placeholders:
- A first name
- An order number
- The name of the product
- The quantity of the product
- The price of the product
API placeholders always have the following syntax: {{event.placeholdername}}
It must contain the event.
prefix, otherwise it will not work!
Use the name of the placeholder (e.g. firstName
) in your JSON Payload. The JSON of this campaign will look like the following:
{
"key_id": "3",
"external_id": "jack.example@gmail.com",
"data":{
"firstName": "Jack",
"orderNumber": "12345",
"Quantity": "3",
"Price": "45.95"
}
}
The following image shows when the API call is triggered using the Emarsys Dev Hub:
The result of the email will show the data:
Broadcast Events
Broadcast events are used when you need to send triggered emails to contacts who are not in your contact database. Since no personalization data is available for these virtual contacts, the email address and all personalization data must be provided in the payload of the API request.
You need to add {{ event.body|raw }}
as a personalization into your email campaign to have personalized data. In the sent out mail, the raw part is replaced by the content from the body
that you provide in the API call.
For broadcast emails, which are sent to virtual contacts (for example, to email addresses that do not exist in the Contact database), we do not collect any opens or clicks, so no email statistics are available on the Emarsys Platform or Open Data.
An example for the call and the JSON payload that contains body
:
POST https://suite99.emarsys.net/api/v2/email/12345678/broadcast
{
"email": "virtual_stan@gets.it",
"data": {
"global": {
"body": "test message"
}
}
}
The following two images show the email being created in the editor and the sent out message. For more information, see the Developer Hub.