I need to send an order confirmation email using the Transactional Messaging API. The email references the array of ordered items. Rather than store the ordered items as rows in another data extension that we lookup using AMPscript and loop through for each order ID, I'm parsing the JSON using Guide Template Language.
I have created a triggered send data extension and have included an extra text field called Attributes. I've manually added a record to this data extension for testing purposes and the value in the Attributes field is:
{
"Environment":"Local",
"FirstName":"Firstname",
"DeliveryLastName":"Lastname",
"PurchaseInfo":[
{
"ProductCode":"DB001",
"ProductName":"Book",
"ProductImageUrl":"https://gallery.mailchimp.com/8aef41944e1b62c25146a4016/images/83e0f82b-7ee8-4903-b2ca-069e919cf693.png",
"Quantity":4,
"ProductAmount":7.95
},
{
"ProductCode":"AB001",
"ProductName":"Magazine",
"ProductImageUrl":"https://gallery.mailchimp.com/8aef41944e1b62c25146a4016/images/83e0f82b-7ee8-4903-b2ca-069e919cf693.png",
"Quantity":1,
"ProductAmount":6.95
}
],
"ShippingCost":6.6,
"TotalSavings":3.0,
"TotalPrice":81.75,
"VoucherCode":"20PERCENTOFF",
"DiscountDescriptions":[
"20% On Books",
"10% On Magazines"
],
"IncludeShippingAddress":true,
"CurrencyCode":"GBP",
"OrderReference":"368517588278312960123",
"OrderDateUTC":"2021-10-20T13:49:18.037Z",
"ShippingAddress":{
"AddressLine1":"AddressLine1",
"AddressLine2":"AddressLine2",
"City":"City",
"State":"State",
"County":"County",
"Zip":"Zip",
"Country":"Country"
}
}
}
}
I can target the various objects and arrays successfully with Guide Template Language.
%%[
var @json
set @json = Attributes
]%%
{{.datasource Json type=variable}}
{{.data}}
{ "target" : "@Json" }
{{/data}}
SOME CONTENT with some {{attribute}}
{{/datasource}}
However:
How can I get the JSON from the API call to populate my triggered data extension field? Do I just need to create an attribute called 'Attributes' and pass the JSON as an attribute?
Bonus question - should I be using SSJS to parse the JSON instead?