I am trying to pass json data input to email script token from Marketo API invoked Email notification using tokens so that layout data in table format in Email Message Body. I know we can use lead/contact object attributes in addition to other objects like Oppurunity or Account but I have not seen example where we use one custom token ({{my.jasonData}}) into Email Script token so that Velocity script can be used to create html content that can be renderded. Any ideas/suggesstion if this possible and how to do it(with example)
Solved! Go to Solution.
@SanfordWhiteman After your below reply (Send VTL, including #set(), as the {{my.token}} value.), We got the idea that we can pass VTL (velocity template language) from API as token content along with data. By referring to your blog post , we were able to pass json data (see texttemplate variable below) from API itself with VTL included to parse and layout that json data. Here is how final request looks like
curl -X POST \
https://<munchkinid>.mktorest.com/rest/v1/campaigns/1025/trigger.json \
-H 'Accept: */*' \
-H 'Authorization: Bearer <token>' \
-H 'Cache-Control: no-cache' \
-H 'Connection: keep-alive' \
-H 'Content-Type: application/json' \
-H 'Host: <munchkin-id>.mktorest.com' \
-H 'Postman-Token: <postman-token>' \
-H 'User-Agent: PostmanRuntime/7.15.0' \
-H 'accept-encoding: gzip, deflate' \
-H 'cache-control: no-cache' \
-H 'content-length: 1591' \
-d '{
"input": {
"leads": [
{
"id": 2
}
],
"tokens": [
{
"name": "{{my.texttemplate}}",
"value": "<table border=1><tr><th>Email Id</th><th>Full Name</th><th>Date Referred</th><th>Referral Program</th></tr> #set($jsonString = '\''[{\"Email\" : \"joe@example.com\",\"FullName\" : \"Joe Exton\",\"DateReferred\" : \"2016-08-01\",\"ReferralProgram\" : \"Season Pass Holders\"},{\"Email\" : \"jill@example2.com\",\"FullName\" : \"Jill Towson\",\"DateReferred\" : \"2016-08-03\",\"ReferralProgram\" : \"Gold Donors\"}]'\'') #set( $jsonData = '\''#set( $jsonData = '\''+$jsonString+'\'')'\'') #evaluate($jsonData) #foreach($jdata in $jsonData)<tr><td >${jdata.Email}</td><td >${jdata.FullName}</td><td >${jdata.DateReferred}</td><td >${jdata.ReferralProgram}</td></tr> #end </table>"
},
{
"name": "{{my.order-number}}",
"value": "3023532055"
},
{
"name": "{{my.shipment-on-way}}",
"value": "Your order has shipped and is on it'\''s way!"
},
{
"name": "{{my.order-status}}",
"value": "Partially Shipped"
},
{
"name": "{{my.track-shipment}}",
"value": "9012412122"
},
{
"name": "{{my.shipping-method}}",
"value": "Standard (2-Day Guaranteed)"
},
{
"name": "{{my.packing-slip}}",
"value": "7569737098"
},
{
"name": "{{my.ship-to-account-number}}",
"value": "98746892"
},
{
"name": "{{my.ship-to-account-name}}",
"value": "chicago childcare hospital"
},
{
"name": "{{my.delivery-address}}",
"value": "121 s tonne dr, arlington heights, IL from postman"
}
]
}
}'
you do not need to use #evaluate
you do not need to use #evaluate
you do not need to use #evaluate
you do not need to use #evaluate
@SanfordWhiteman Are you suggesting that I can just put velocity script inside html content without using Email Script token to use Velocity script inside my email template. That is how I read you comment. I will try and revert back to you if this works.