External data

This topic describes how to process external data using field functions.

Use your specific data and recipient list fields, and test the field functions before using them in a mailing.

Displaying a JSON string as text in a mailing

If you retrieve data via API Stands for "application programming interface". The API specifies how some software components should interact with each other, such as accessing a database or computer hardware, or easing the work of programming graphical user interface components. APIs often are in the form of a library that includes specifications for routines, data structures, object classes, and variables. See also: https://world.optimizely.com/documentation/class-libraries/ and store it as a JSON string, you can display the content as text with the following velocity code:

#set ($jsonContent = $json.readFromString(${jsonString}))

If recipient list fields contain data as JSON, you can display the content as text using the following velocity code:

#set ($jsonContent = $json.readFromString($!{user.data.RECIPIENTLISTFIELD}))


You have a recipient list with a custom field in text format that contains the following JSON string:

{"clearname": "John Smith", "unsubscribelink": "http://www.example.com/unsubscribe/user-id-1234"}

In the mailing, you can use the JSON string using velocity code as follows:

#set ($jsonContent = $json.readFromString($!{user.data.custom}))
Hello ${jsonContent.clearname}! To unsubscribe from the newsletter, click <a href="${jsonContent.unsubscribelink}">here</a>.

Displaying post-click data

Velocity lets you access the following post-click data and display it in a mailing:

  • service ("name_of_service")
  • stringValue("x")
    • is()
    • isNot()
  • floatValue("X")
    • isGreaterThan("y")
    • isLessThan("y")
    • isGreaterThanOrEqualTo("y")
    • isLessThanOrEqualTo("y")

Using velocity field functions, you can display only the most recent post-click data. You cannot display older data.


The following Velocity code lets you display the value of gvalue10 in the serviceName service:

#set($strGvalue = $!postClick.find().where().service().is("serviceName").getStringResult(10))