1

I feel somewhat inexperienced with this, so my apologies if my question is not as clear as you might need it to be. I will happily clarify anything.

I am trying to reverse engineer how a client's current product receipt email is able to send multiple items. Of course, this receipt might contain an infinite number of products, so I can't just create a new attribute in the DE for each item.

Instead, I have one attribute for each aspect of the product information (i.e. img, name, code, ect)

What I've figured out so far is that the AMPscript in the email needs to receive each Product attribute as a pipe delimited text string.
For example, it needs to receive the list of Product_Names as "Product 1|Product 2|Product 3|Product 4".

My current API call for one product looks like the following:

{
    "From": {
        "Address": "[email protected]",
        "Name": "Email Test"
    },
    "To": {
        "Address": "[email protected]",
        "SubscriberKey": "[email protected]",
        "ContactAttributes": {
            "SubscriberAttributes": {
                "Language": "en_us",
                "Country": "USA",
                "Full_Name": "Test Name",
                "Shipping_Address_First_Names": "John",
                "Shipping_Address_Last_Names": " Doe",
                "Shipping_Address_Streets": "Street Ave",
                "Shipping_Address_Street_Numbers": "400",
                "Shipping_Address_Cities": "Citytown",
                "Shipping_Address_Zip_codes": "1M3N5N",
                "Shipping_Address_States": "CA",
                "Shipping_Address_Countries": "USA",
                "Shipping_Address_Product_Names": "Spatula",
                "Shipping_Address_Product_Images": "http://fillmurray.com/600/400",
                "Shipping_Address_Product_Prices": "33.33",
                "Shipping_Address_Product_Quantities": "3",
                "Shipping_Address_Product_Codes": "41424",
                "Shipping_Address_Product_Sub_Totals": "44.44",
            }
        }
    },
    "OPTIONS": {
        "RequestType": "ASYNC"
    }
}

I have been told that I just need to utilize nesting in my API call for each Product and it's information, BUT I don't understand how

  1. this allows for a changing number of products in each email and
  2. at what point would each of the product's info be concatenated and pipe delimited into a text string before it is stored in the Data Extension

Any direction you can provide for this would be a huge help or any documentation you can share with me that addresses this.

2 Answers 2

2

I'm sure there are a few ways of addressing this, but I tend to take the receipt information and create an XML document from it that you can then use as the basis for the content of your email. Consider this XML document...

<?xml version="1.0" encoding="utf-8"?>
<order>
  <header order_number="00002123455" order_date="2016-08-26 19:21:26" >
      <firstname>John</firstname>
      <lastname>Doe</lastname>
      <billing>
          <address1>12/25 Billing Street</address1>
          <address2></address2>
          <address3></address3>
          <city>Sydney</city>
          <state>NSW</state>
          <postcode>2000</postcode>
          <country>AU</country>
      </billing>
      <shipping>
          <address1>105 Shipping Lane</address1>
          <address2></address2>
          <address3></address3>
          <city>Melbourne</city>
          <state>VIC</state>
          <postcode>3000</postcode>
          <country>AU</country>
      </shipping>
  </header>
  <items>
      <item sku="12345" quantity="1" description="Some Product" unit_price="47.50" total="47.50"/>
      <item sku="55421" quantity="2" description="Another Product" unit_price="28.25" total="56.50"/>
  </items>
</order>

You can't safely use this within your JSON payload, so you encode it with Base64 and place the encoded string into an attribute you're passing in your REST call...

POST https://www.exacttargetapis.com/interaction/v1/events
Request Headers:
Content-Type: application/json
Authorization: Bearer 7HhTCzVSOZx2387bou3ZgdGL
{
    "ContactKey": "123456789",
    "EventDefinitionKey":"order",
    "EstablishContactKey": true,
    "Data": {
          "SubscriberKey":"123456789",
"EmailAddress":"[email protected]",
"MobilePhone":"61444444444",
"Data":"PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjxvcmRlcj4NCiAgPGhlYWRlciBvcmRlcl9udW1iZXI9IjAwMDAyMTIzNDU1IiBvcmRlcl9kYXRlPSIyMDE2LTA4LTI2IDE5OjIxOjI2IiA+DQoJICA8Zmlyc3RuYW1lPkpvaG48L2ZpcnN0bmFtZT4NCgkgIDxsYXN0bmFtZT5Eb2U8L2xhc3RuYW1lPg0KCSAgPGJpbGxpbmc+DQoJCSAgPGFkZHJlc3MxPjEyLzI1IEJpbGxpbmcgU3RyZWV0PC9hZGRyZXNzMT4NCgkJICA8YWRkcmVzczI+PC9hZGRyZXNzMj4NCgkJICA8YWRkcmVzczM+PC9hZGRyZXNzMz4NCgkJICA8Y2l0eT5TeWRuZXk8L2NpdHk+DQoJCSAgPHN0YXRlPk5TVzwvc3RhdGU+DQoJCSAgPHBvc3Rjb2RlPjIwMDA8L3Bvc3Rjb2RlPg0KCQkgIDxjb3VudHJ5PkFVPC9jb3VudHJ5Pg0KCSAgPC9iaWxsaW5nPg0KCSAgPHNoaXBwaW5nPg0KCQkgIDxhZGRyZXNzMT4xMDUgU2hpcHBpbmcgTGFuZTwvYWRkcmVzczE+DQoJCSAgPGFkZHJlc3MyPjwvYWRkcmVzczI+DQoJCSAgPGFkZHJlc3MzPjwvYWRkcmVzczM+DQoJCSAgPGNpdHk+TWVsYm91cm5lPC9jaXR5Pg0KCQkgIDxzdGF0ZT5WSUM8L3N0YXRlPg0KCQkgIDxwb3N0Y29kZT4zMDAwPC9wb3N0Y29kZT4NCgkJICA8Y291bnRyeT5BVTwvY291bnRyeT4NCgkgIDwvc2hpcHBpbmc+DQogIDwvaGVhZGVyPg0KICA8aXRlbXM+DQoJICA8aXRlbSBza3U9IjEyMzQ1IiBxdWFudGl0eT0iMSIgZGVzY3JpcHRpb249IlNvbWUgUHJvZHVjdCIgdW5pdF9wcmljZT0iNDcuNTAiIHRvdGFsPSI0Ny41MCIvPg0KCSAgPGl0ZW0gc2t1PSI1NTQyMSIgcXVhbnRpdHk9IjIiIGRlc2NyaXB0aW9uPSJBbm90aGVyIFByb2R1Y3QiIHVuaXRfcHJpY2U9IjI4LjI1IiB0b3RhbD0iNTYuNTAiLz4NCiAgPC9pdGVtcz4NCjwvb3JkZXI+"
    }
}

Note that above is a call to fire the customer into a Journey Builder Interaction. For the send of an email, your JSON would be similar to your example, but with the Base 64 encoded document passed as a subscriber attribute. I'd encourage you to consider Journey Builder as it gives you flexibility to decide to add follow on messaging, like post purchase messaging in the future, with little extra technical work.

Once the XML document is stored in a field in your triggered send data extension or in your event entry data extension, you're then free to use AMPScript to Base64Decode the content of the XML, use BuildRowSetFromXML to pull out the content or (preferably) use TransformXML AMPScript functions to render the data in the XML on the page.

1

As Andrew points out, there are lots of different approaches to this.

We've done something very similar for order and shipping confirmation emails for an online retailer.

My approach would be to store the multiple items in a single Data Extension field as a single JSON object and personalise the email using Guide Template Language. This document-oriented approach to storage will enable you to create an "infinite number of products" and even add nested objects for your products.

As you are working with Triggered Sends (from looking at your code) and you want to store the data in a DE, you would need to make the DE field length either very large or unlimited (by simply removing the length value) when you create your Triggered Send Data Extension.

As an example, if you store multiple product items in an array:

{  
   "cases":[  
      {  
         "name":"Sport iPhone Case",
         "colour":"Heritage",
         "image":"https://raw.githubusercontent.com/eliotharper/gtl-demo/master/images/prod.jpg"
      },
      {  
         "name":"iPhone Fold Wallet",
         "colour":"Smoke",
         "image":"https://raw.githubusercontent.com/eliotharper/gtl-demo/master/images/prod2.jpg"
      },
      {  
         "name":"Draw iPhone Case",
         "colour":"Stand / Heritage",
         "image":"https://raw.githubusercontent.com/eliotharper/gtl-demo/master/images/prod3.jpg"
      }
   ]
}

Then in your messageDefinitionSends API request could look something like this:

{
    "From": {
        "Address": "[email protected]",
        "Name": "Email Test"
    },
    "To": {
        "Address": "[email protected]",
        "SubscriberKey": "[email protected]",
        "ContactAttributes": {
            "SubscriberAttributes": {
                "data": "{\"cases\":[{\"name\":\"Sport iPhone Case\",\"colour\":\"Heritage\",\"image\":\"https://raw.githubusercontent.com/eliotharper/gtl-demo/master/images/prod.jpg\"},{\"name\":\"iPhone Fold Wallet\",\"colour\":\"Smoke\",\"image\":\"https://raw.githubusercontent.com/eliotharper/gtl-demo/master/images/prod2.jpg\"},{\"name\":\"Draw iPhone Case\",\"colour\":\"Stand / Heritage\",\"image\":\"https://raw.githubusercontent.com/eliotharper/gtl-demo/master/images/prod3.jpg\"}]}"
            }
        }
    },
    "OPTIONS": {
        "RequestType": "ASYNC"
    }
}

You don't need to minify the json, but you will need to escape the quotation marks.

In your email, you would define the data source like I have done in this working example which should be enough to get you started.

Essentially, GTL iterates through the number of items in the cases array, populating values from the JSON in GTL tags:

{{.datasource featuredCases type=variable source=@featuredCases}}
{{.data}}
   {"target" : "@featuredCases"}
{{/data}}
  {{.datasource products type=nested}}
{{.data}}
      {"target":"featuredCases.cases"}
{{/data}}
<div class="prod">
    <table bgcolor="" class="social" width="100%">
    <tr>
        <td>
            <p>
                <img src="{{image}}"/>
            </p>
        </td>
    </tr>
    <tr>
        <td>
            <table align="left" width="100%">
                    <p><h6>{{name}}</h6></p>
                    <p class="colour">{{colour}}</p>                    
            </table>
        </td>
    </tr>
    </table>
</div>
  {{/datasource}}
{{/datasource}}

When the email is rendered, the products in the 'cases' array are displayed:

rendered email

1
  • Yeah. Very similar approach. I prefer it to my own, if JSON's your thing. It is for me.
    – Macca
    Commented Jun 7, 2017 at 12:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .