SOLVED

Re: Email Script Token Input from tokens using API trigged email invocation

Go to solution
sssingh
Level 2

Re: Email Script Token Input from tokens using API trigged email invocation

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

 

SanfordWhiteman
Level 10 - Community Moderator

Re: Email Script Token Input from tokens using API trigged email invocation

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

Arun_Sharma9
Level 4

Re: Email Script Token Input from tokens using API trigged email invocation

Hi @SS 

Your Payload needs to be updated for tokens as below (as mentioned by @SanfordWhiteman), you can add remaining fields in similar way to the payload:

{
    "input": {
        "leads": [
            {
                "id": 5
            }
        ],
        "tokens": [
            {
                "name": "{{my.order-number}}",
                "value": "3023532055"
            },
            {
                "name": "{{my.pname}}",
                "value": "Mr.Prudhvi"
            },
            {
                "name": "{{my.shipment-on-way}}",
                "value": "Your order has shipped and is on it's way!"
            },
            {
                "name": "{{my.order-status}}",
                "value": "Partially Shipped"
            }
        ]
    }
}

Above should work fine, as I tested below:

Arun_Sharma9_0-1627457193240.png

 

Tokens in the program:

Arun_Sharma9_1-1627457215246.png

Tokens in email:

Arun_Sharma9_2-1627457281303.png

 

Hope above helps your cause.

 

Thanks

Arun Sharma