External JSON and Scriptlets
Maileon provides a way to dynamically request JSON data from an external external URL inside all mailing types. The URL for this request can be personalized, so the data can be dependant on all the generally available personalization options (contact fields, transaction attributes, mailing properties, etc..).
The data is requested during generation time (including generating previews) and is cached based on the URL provided. This means that the number of requests made during email generation is proportional to the different possible personalized URLs. For example using a contact field that is different for each contact means that to generate the whole mailing a request for each contact’s URL is made.
External JSON
You can define an external JSON source using the following merge tag syntax:
[[EXTERNAL-JSON|<alias of file>|<personalized url>]]
In the example above the ‘alias of file’ will be used to refer to the included JSON data in the scripting of the email, while the ‘personalized url’ specifies the URL to query to get the JSON data.
Example usage
[[EXTERNAL-JSON|myData|"http://www.xqueue.com/[CONTACT|jsonfile]"]]
Using Scriptlets
After the JSON source has been defined you can use the Maileon scriptlet syntax to process and manipulate data. The scriptlet language uses parenthesized prefix notation. The documentation is available here: https://xqueue.atlassian.net/wiki/spaces/DEV/pages/5963784/
Continuing from aboce, Scriptlets can be used to access the values using “ext_json” method, e.g.:
[[% ext_json 'myData' 'recommendations[1].product_id']]
To save the array into variable myVar:
To save the first array element from myVar (example above) into variable myElement
Or simply use loops to display all elements
Example usage in CMS2
There are two ways to add these scriptlets in a mailing. Using the UI you can define them as ‘visibility conditions’:
Or you can add them directly as comments in the HTML source of the mailing:
A full example using the second method:
The following code is part of a template that generates a mailing using external JSON data:
After a similar code is added around the relevant rows/cells the properties defined in the code can be referenced in the Drag and Drop editor: