Email Script Token Input from tokens using API trigged email invocation | Community
Skip to main content
Level 2
July 15, 2021
Solved

Email Script Token Input from tokens using API trigged email invocation

  • July 15, 2021
  • 1 reply
  • 6985 views

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)

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by sssingh

There’s no method $util.parseJson, don’t know where you’re getting this from.

 

It still seems like you don’t understand the approach.

 

Once again: do not send raw JSON as the {{my.token}} value.

 

Send VTL, including #set(), as the {{my.token}} value.

 

Thus as far as Velocity knows, you’re passing a #set statement that creates a LinkedHashMap (with nested LinkedHashMaps). You‘re not passing a JSON string (it is never parsed as JSON, even if it some of it looks like JSON),

 

If this still doesn’t make sense, you should wait for me to blog about it at greater length.


@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" } ] } }'

 

1 reply

SanfordWhiteman
Level 10
July 15, 2021

You can’t read another Text {{my.token}} as plain text from a Velocity {{my.token}}.

 

But you can write inline Velocity in a Text {{my.token}} — it cannot have any dependencies, that is, it can’t reference any lead or object fields — that #sets a variable in the context, then read that variable from a Velocity {{my.token}} located after it in the email.

sssinghAuthor
Level 2
July 16, 2021

@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.