Confirm Purchases with Triggered Sends

This page contains conceptual and scenario information about using triggered sends to confirm online purchases. You can use the information in this document as a model to create your own triggered sends using the SOAP API.

Scenario 

Northern Trail Outfitters uses an internal system to process work-related airline tickets for their employees. When the employees book their travel via the internal site, they receive an email confirmation that includes a summary of the information regarding their travel plans. To make this system work, Northern Trail Outfitters performs the following tasks:

  1. Create the confirmation email.
  2. Created the data extension used to store the confirmation information.
  3. Create the triggered send used to send the confirmation email.
  4. Create the API call.

The internal system submits the triggered send using a Java API call that includes the email address of the subscriber, the subscriber key, and confirmation information in XML format.

Create the Confirmation Email 

The email itself uses AMPscript to display information taken from the confirmation XML. This example uses the BuildRowSetFromXML() AMPscript function to create each record row for the email message, and it formats date and currency values automatically.

1%%[
2    var @xml, @subject, @tempxml
3    var @passengers, @passengers_rows, @passenger_count, @passenger_rows
4    var @first_name, @middle_name, @last_name, @account_number, @ticket_number
5    var @confirmation_date, @confirmation_number
6    var @flights, @flights_rows, @flight_count, @flight_rows, @flight_xml, @flight_date, @flight_number
7    var @depart_time, @depart_airport, @arrive_time, @arrive_airport, @stops
8    var @trip_price, @taxes, @trip_flex, @seat_selections, @bag_fees, @total_cost
9    var @line_bgcolor
10    set @line_bgcolor = "#cbdadf"
11    set @xml = confirmation_xml
12    set @subject             = Field(Row(BuildRowSetFromXML(@xml, "/confirmation/subject"), 1), 'value')
13    set @passengers          = BuildRowSetFromXML(@xml, "/confirmation/passengers")
14    set @tempxml             = concat("<root>", Field(Row(@passengers, 1), "xml"), "</root>")
15    set @passengers_rows     = BuildRowSetFromXML(@tempxml, "//passenger")
16    set @passenger_count     = RowCount(@passengers_rows)
17    set @confirmation_date   = Format(Field(Row(BuildRowSetFromXML(@xml, "/confirmation/confirmation_date"), 1), 'value'), "MMMM d, yyyy")
18    set @confirmation_number = Field(Row(BuildRowSetFromXML(@xml, "/confirmation/confirmation_number"), 1), 'value')
19    set @flights             = BuildRowSetFromXML(@xml, "/confirmation/flights")
20    set @tempxml             = concat("<root>", Field(Row(@flights, 1), "xml"), "</root>")
21    set @flights_rows        = BuildRowSetFromXML(@tempxml, "//flight")
22    set @flight_count        = RowCount(@flights_rows)
23    set @trip_price          = Format(Field(Row(BuildRowsetFromXml(@xml, "/confirmation/trip_price"), 1), "Value"), "$#,#.00;-$#,#.00")
24    set @taxes               = Format(Field(Row(BuildRowsetFromXml(@xml, "/confirmation/taxes"), 1), "Value"), "$#,#.00;-$#,#.00")
25    set @trip_flex           = Format(Field(Row(BuildRowsetFromXml(@xml, "/confirmation/trip_flex"), 1), "Value"), "$#,#.00;-$#,#.00")
26    set @seat_selections     = Format(Field(Row(BuildRowsetFromXml(@xml, "/confirmation/seat_selections"), 1), "Value"), "$#,#.00;-$#,#.00")
27    set @bag_fees            = Format(Field(Row(BuildRowsetFromXml(@xml, "/confirmation/bag_fees"), 1), "Value"), "$#,#.00;-$#,#.00")
28    set @total_cost          = Format(Field(Row(BuildRowsetFromXml(@xml, "/confirmation/total_cost"), 1), "Value"), "$#,#.00;-$#,#.00")
29]%%

The next section provides the header for the email message.

1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2<html xmlns="http://www.w3.org/1999/xhtml">
3  <head>
4    <style type="text/css">
5      .ReadMsgBody {
6        width: 100%;
7      }
8      .ExternalClass {
9        width: 100%;
10      }
11    </style>
12  </head>
13  <body padding-top: 10px; margin: 0 auto; color:#000;">
14  <table
15    style="padding:0; margin: 0 auto; width: 558px;"
16    cellpadding="0"
17    cellspacing="0"
18    align="center"
19    width="558"
20  >
21    <!-- Link To Web-Only Version -->
22    <tr>
23      <td
24        style="text-align:center; font-size:11px; font-family:Arial, Helvetica, sans-serif; color:#000;"
25      >
26        Having trouble viewing this email?
27        <a href="%%view_email_url%%" style="color:#000; font-size:11px; text-decoration:none;"
28          >View the web-only version</a
29        >.
30      </td>
31    </tr>
32    <!-- Header, Nav, Headline -->
33    <tr>
34      <td>
35        <a href="http://www.example.com"
36          ><img
37            src="http://sale.example.com/images/_header2.jpg"
38            width="558"
39            height="78"
40            border="0"
41            style="display:block;"
42            alt="Header Image"
43        /></a>
44        <img
45          src="http://sale.example.com/images/_mainnav2.jpg"
46          width="558"
47          height="31"
48          border="0"
49          alt="Book Travel | Hotel | Travel Tools"
50          usemap="#Map"
51          style="display:block;"
52        />
53      </td>
54    </tr>
55  </table>
56</html>

The next section retrieves all passengers on the reservation using for/do loops to pull back all customer information.

1<!-- Main Content -->
2<table
3  style="padding:0; margin: 0 auto; width: 558px;"
4  cellpadding="0"
5  cellspacing="0"
6  width="558"
7  bgcolor="#ffffff"
8  border="1"
9>
10  <tr>
11    <td>
12      <img
13        src="http://sale.example.com/images/spacer.gif"
14        width="1"
15        height="15"
16        border="0"
17        alt=""
18        style="display:block;"
19      />
20    </td>
21  </tr>
22  <tr>
23    <td
24      style="font-size:12px; font-family:Arial, Helvetica, sans-serif; text-align:justify; color:#005695;"
25    >
26      <table
27        style="padding:0; margin: 0 auto; width: 558px;"
28        cellpadding="0"
29        cellspacing="0"
30        width="558"
31      >
32        <tr>
33          <td height="28" style="font-weight:bolder">
34            %%[ for @p = 1 to @passenger_count do set @passenger_rows = Row(@passengers_rows, @p)
35            set @passenger_xml = concat("<root>", Field(@passenger_rows, "xml"), "</root>") set
36            @first_name = Field(Row(BuildRowsetFromXml(@passenger_xml, "//first_name"), 1), "Value")
37            set @middle_name = Field(Row(BuildRowsetFromXml(@passenger_xml, "//middle_name"), 1),
38            "Value") set @last_name = Field(Row(BuildRowsetFromXml(@passenger_xml, "//last_name"),
39            1), "Value") ]%% %%=v(@last_name)=%% / %%=v(@first_name)=%% %%=v(@middle_name)=%%<br />
40            %%[ next ]%%
41          </td>
42          <td style="font-weight:bolder">Confirmation Date:<br />%%=v(@confirmation_date)=%%</td>
43          <td style="font-weight:bolder">
44            Confirmation Number:<br />%%=v(@confirmation_number)=%%
45          </td>
46        </tr>
47      </table>
48    </td>
49  </tr>
50  <tr>
51    <td>
52      <img
53        src="http://sale.example.com/images/spacer.gif"
54        width="1"
55        height="15"
56        border="0"
57        alt=""
58        style="display:block;"
59      />
60    </td>
61  </tr>
62</table>

The next section lists all ticket numbers and frequent flyer accounts for all reservations. The code alternates background colors for each line to aid readability of the information.

1<tr>
2  <td
3    style="font-size:11px; font-family:Arial, Helvetica, sans-serif; text-align:left; color:#005695;"
4    align="left"
5  >
6    <table
7      style="padding:0; margin: 0 auto;"
8      cellpadding="0"
9      cellspacing="0"
10      align="left"
11      width="400"
12      border="0"
13    >
14      <tr></tr>
15      <tr>
16        <td style="font-weight:bolder">Passenger(s)</td>
17        <td style="font-weight:bolder">Account Number</td>
18        <td style="font-weight:bolder">Ticket Number</td>
19      </tr>
20      %%[ for @p = 1 to @passenger_count do set @passenger_rows = Row(@passengers_rows, @p) set
21      @passenger_xml = concat("<root>", Field(@passenger_rows, "xml"), "</root
22      >") set @first_name = Field(Row(BuildRowsetFromXml(@passenger_xml, "//first_name"), 1),
23      "Value") set @middle_name = Field(Row(BuildRowsetFromXml(@passenger_xml, "//middle_name"), 1),
24      "Value") set @last_name = Field(Row(BuildRowsetFromXml(@passenger_xml, "//last_name"), 1),
25      "Value") set @account_number = Field(Row(BuildRowsetFromXml(@passenger_xml,
26      "//account_number"), 1), "Value") set @ticket_number =
27      Field(Row(BuildRowsetFromXml(@passenger_xml, "//ticket_number"), 1), "Value") if @line_bgcolor
28      == "#cbdadf" then Set @line_bgcolor = "#e0e9ec" else Set @line_bgcolor = "#cbdadf" endif ]%%
29      <tr bgcolor="%%=v(@line_bgcolor)=%%">
30        <td>%%=v(@first_name)=%% %%=v(@middle_name)=%% %%=v(@last_name)=%%</td>
31        <td>%%=v(@account_number)=%%</td>
32        <td>%%=v(@ticket_number)=%%</td>
33      </tr>
34      %%[ next ]%%
35    </table>
36  </td>
37</tr>
38<tr>
39  <td>
40    <img
41      src="http://sale.example.com/images/spacer.gif"
42      width="1"
43      height="15"
44      border="0"
45      alt=""
46      style="display:block;"
47    />
48  </td>
49</tr>

The next section displays all relevant flight information, including numbers, arrival and departure times, and number of stops.

1<tr>
2  <td
3    style="font-size:11px; font-family:Arial, Helvetica, sans-serif; text-align:left; color:#005695;"
4    align="left"
5  >
6    <table
7      style="padding:0; margin: 0 auto;"
8      cellpadding="0"
9      cellspacing="0"
10      align="left"
11      width="558"
12      border="0"
13    >
14      <tr>
15        <td style="font-weight:bolder">Date</td>
16        <td style="font-weight:bolder" width="100">Flight</td>
17        <td style="font-weight:bolder">Flight Information</td>
18        <td style="font-weight:bolder">Stops</td>
19      </tr>
20      %%[ for @p = 1 to @flight_count do set @flight_rows = Row(@flights_rows, @p) set @flight_xml =
21      concat("<root>", Field(@flight_rows, "xml"), "</root
22      >") set @flight_date = Format(Field(Row(BuildRowsetFromXml(@flight_xml, "//flight_date"), 1),
23      "Value"), "ddd MMM d") set @flight_number = Field(Row(BuildRowsetFromXml(@flight_xml,
24      "//flight_number"), 1), "Value") set @depart_time = Field(Row(BuildRowsetFromXml(@flight_xml,
25      "//depart_time"), 1), "Value") set @depart_airport = Field(Row(BuildRowsetFromXml(@flight_xml,
26      "//depart_airport"), 1), "Value") set @arrive_time = Field(Row(BuildRowsetFromXml(@flight_xml,
27      "//arrive_time"), 1), "Value") set @arrive_airport = Field(Row(BuildRowsetFromXml(@flight_xml,
28      "//arrive_airport"), 1), "Value") set @stops = Field(Row(BuildRowsetFromXml(@flight_xml,
29      "//stops"), 1), "Value") if @line_bgcolor == "#cbdadf" then Set @line_bgcolor = "#e0e9ec" else
30      Set @line_bgcolor = "#cbdadf" endif ]%%
31      <tr bgcolor="%%=v(@line_bgcolor)=%%">
32        <td>%%=v(@flight_date)=%%</td>
33        <td>%%=v(@flight_number)=%%</td>
34        <td>
35          Depart %%=v(@depart_airport)=%% at %%=v(@depart_time)=%%<br />
36          Arrive %%=v(@arrive_airport)=%% at %%=v(@arrive_time)=%%
37        </td>
38        <td>%%=v(@stops)=%%</td>
39      </tr>
40      %%[ next ]%%
41    </table>
42  </td>
43</tr>
44<tr>
45  <td>
46    <img
47      src="http://sale.example.com/images/spacer.gif"
48      width="1"
49      height="15"
50      border="0"
51      alt=""
52      style="display:block;"
53    />
54  </td>
55</tr>

The next section of code itemizes any costs associated with the reservation.

1<table>
2  <tr>
3    <td
4      style="font-size:11px; font-family:Arial, Helvetica, sans-serif; text-align:left; color:#005695;"
5      align="left"
6    >
7      <table
8        style="padding:0; margin: 0 auto;"
9        cellpadding="0"
10        cellspacing="0"
11        align="left"
12        width="200"
13        border="0"
14      >
15        <tr>
16          <td>Trip Price</td>
17          <td>=</td>
18          <td align="right">%%=v(@trip_price)=%%</td>
19        </tr>
20        <tr>
21          <td>Taxes</td>
22          <td>=</td>
23          <td align="right">%%=v(@taxes)=%%</td>
24        </tr>
25        <tr>
26          <td>Trip Flex</td>
27          <td>=</td>
28          <td align="right">%%=v(@trip_flex)=%%</td>
29        </tr>
30        <tr>
31          <td>Seat Selections</td>
32          <td>=</td>
33          <td align="right">%%=v(@seat_selections)=%%</td>
34        </tr>
35        <tr>
36          <td>Baggage Fees</td>
37          <td>=</td>
38          <td align="right">%%=v(@bag_fees)=%%</td>
39        </tr>
40        <tr>
41          <td>Total Cost</td>
42          <td>=</td>
43          <td align="right">%%=v(@total_cost)=%%</td>
44        </tr>
45      </table>
46    </td>
47  </tr>
48</table>

The next section of code places a disclaimer in the email.

1<table
2  style="padding:0 0 15px 0; margin: 0 auto; width: 558px;"
3  cellpadding="0"
4  cellspacing="0"
5  align="center"
6>
7  <!-- DISCLAIMER INFO -->
8  <tr>
9    <td>
10      <img
11        src="http://sale.example.com/images/spacer.gif"
12        width="1"
13        height="15"
14        border="0"
15        alt=""
16        style="display:block;"
17      />
18    </td>
19  </tr>
20  <tr>
21    <td
22      style="font-size:9px; font-family:Arial, Helvetica, sans-serif; text-align:justify; color:#000;"
23    >
24      All fares in US dollars<br />
25      Fares shown are the lowest available and may fluctuate until purchased and confirmed. The
26      lowest fare available on your selected date is displayed and includes any advertised discount
27      available for booking online. Base prices don't include PFC, segment fees or September 11th
28      security fee of up to $10.70 per segment. A segment is one take-off and one landing. A
29      convenience fee of $10.00 per passenger, per segment applies when booked on example.com. A
30      convenience fee of $10.00 per passenger, per segment, plus $14.99 per segment, applies when
31      purchased through our call center. Purchases made at any NTO office do not incur a convenience
32      or call center fee. When purchased at time of booking, a checked bag fee of up to $29.99 per
33      bag, per segment applies for the first two(2) checked bags. If purchased at flight check-in, a
34      fee of $35 per checked bag, per person, per segment applies for the first two bags checked. In
35      all cases more higher fees applies for three or more checked bags. Fare rules, routes and
36      schedules are subject to change without notice. Fares are non-refundable. No credit or refund
37      is given for fare differences or fluctuations after reservation is purchased. Seats are
38      limited and subject to availability. Restrictions apply. Any credits for future travel
39      resulting from changes or cancelations of this reservation can be used for online/web
40      reservations and therefore can be applied to any web-only fares or web discounts. Any changes
41      to travel date may result in a higher price in addition to change fee(s). Customers with
42      credits may call Reservations to make their reservation and is charged the lowest available
43      non-web fare plus any applicable fees. <br />
44      <a href="http://www.example.com/BaggagePolicy.html">Click Here</a> for our Baggage Policy.
45    </td>
46  </tr>
47</table>

The next section of code puts a footer in the email message.

1<!-- Pledge -->
2    <tr>
3        <td><img src="http://sale.example.com/images/spacer.gif" width="1" height="15" border="0" alt="" style="display:block;" /></td>
4    </tr>
5    <tr>
6        <td><img src="http://sale.example.com/images/_pledge.jpg" width="279" height="21" border="0" alt="" style="display:block; margin-left:155px;" />
7            <p style="font:bold 11px Arial, Helvetica, sans-serif; color:#F89728; text-align:center; margin-bottom:0;">Thanks for using our travel system. Have a great flight!</p>
8        </td>
9    </tr>
10    <tr>
11        <td><img src="http://sale.example.com/images/spacer.gif" width="1" height="10" border="0" alt="" style="display:block;" /></td>
12    </tr>
13    <!-- Social Media -->
14    <tr>
15        <td style="text-align:center; padding-top:10px;"><a href="http://www.facebook.com/sharer.php?u=http://www.example.com/samplepage.php" style="color:#fff;"><img src="http://sale.example.com/images/FBshare.png" width="129" height="44" border="0" alt="Facebook" /></a><a href="http://www.example.com/TwitterFeed.php" style="color:#fff;"><img style="margin-left:20px;" src="http://sale.example.com/images/followtwitter.png" width="124" height="44" border="0" alt="Twitter" /></a>
16        </td>
17    </tr>
18    <!-- Spacer -->
19    <tr>
20        <td style="line-height: 10px; border-bottom:1px solid #000;">&nbsp;</td>
21    </tr>
22    <!-- Footer Info -->
23    <tr>
24        <td style="font-family:Arial, Helvetica, sans-serif; font-size:11px; color:#000; text-align:center; padding-top:10px;">
25This is a post-only mailing from Northern Trail Outfitters. Please don't respond to this message.
26        <br /><br />
27        Please add <a href="#" style="color:#000; text-decoration:none;">email@example.com</a> to your Safe Senders list to ensure our mailers deliver to your inbox.
28        <br />
29        <a href="http://www.example.com/allowlist.php" style="color:#000;">Visit our website for more information</a>.
30        <br /><br />
31        Northern Trail Outfitters
32        <br />
33        123 Example Way
34        <br />
35        Indianapolis,I
36        <br /><br />
37        You received this message because you voluntarily provided us with your email address.
38        <br />
39        If you don't wish to receive any special deals <a href="%%subscription_center_url%%" alias="Manage Subscriptions">manage your subscriptions here</a>.
40        </td>
41    </tr>
42</table>

The next section of code puts a menu at the bottom of the email message.

1<map name="Map" id="map">
2            <area shape="rect" coords="17,2,137,25" href="http://www.example.com/aaRes/aaBookingFlow_1.php?bktype=WP" alt="Book Your Travel" />
3            <area shape="rect" coords="148,2,216,25" href="http://www.example.com/Hotel.php" alt="Hotel Partners" />
4            <area shape="rect" coords="224,2,331,25" href="http://www.example.com/destinations.php" alt="Destinations" />
5            <area shape="rect" coords="343,2,430,25" href="http://www.example.com/attractions.php" alt="Attractions" />
6            <area shape="rect" coords="436,2,549,25" href="http://www.example.com/traveltools.php" alt="Travel Tools" />
7        </map>
8        <custom name="opencounter" type="tracking">
9    </body>
10</html>

Sample SOAP Envelope for Triggered Send 

1<soap:envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
2    <soap:header>
3    <wsse:security soap:mustunderstand="1">
4    <wsse:usernametoken wsu:id="SecurityToken-884da619-59bb-4db6-834d-138322342442">
5    <wsse:username>ccc</wsse:username>
6    <wsse:password type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">ccc</wsse:password>
7    </wsse:usernametoken>
8    </wsse:security>
9    </soap:header>
10    <soap:body>
11    <createrequest xmlns="http://exacttarget.com/wsdl/partnerAPI">
12    <options></options>
13    <objects xsi:type="TriggeredSend">
14    <partnerkey xsi:nil="true"></partnerkey>
15    <objectid xsi:nil="true"></objectid>
16    <triggeredsenddefinition>
17    <partnerkey xsi:nil="true"></partnerkey>
18    <objectid xsi:nil="true"></objectid>
19    <customerkey>zz_test_confirmation</customerkey>
20    </triggeredsenddefinition>
21    <subscribers>
22    <partnerkey xsi:nil="true"></partnerkey>
23    <objectid xsi:nil="true"></objectid>
24    <emailaddress>subscriber1@example.com</emailaddress>
25    <subscriberkey>subscriber1@example.com</subscriberkey>
26    <attributes>
27    <name>confirmation_xml</name>
28    <value>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&lt;confirmation&gt;&lt;confirmation_number&gt;WXX9Q9&lt;/confirmation_number&gt;&lt;confirmation_date&gt;12/16/2011&lt;/confirmation_date&gt;&lt;subject&gt;&lt;![CDATA[Here is your Flight Confirmation]]&gt;&lt;/subject&gt;&lt;passengers&gt;&lt;passenger&gt;&lt;first_name&gt;Angela&lt;/first_name&gt;&lt;middle_name&gt;A&lt;/middle_name&gt;&lt;last_name&gt;Cruz&lt;/last_name&gt;&lt;account_number&gt;1234567&lt;/account_number&gt;&lt;ticket_number&gt;123456&lt;/ticket_number&gt;&lt;/passenger&gt;&lt;passenger&gt;&lt;first_name&gt;Jane&lt;/first_name&gt;&lt;middle_name&gt;S&lt;/middle_name&gt;&lt;last_name&gt;Doe&lt;/last_name&gt;&lt;account_number&gt;- None Entered -&lt;/account_number&gt;&lt;ticket_number&gt;12345678&lt;/ticket_number&gt;&lt;/passenger&gt;&lt;/passengers&gt;&lt;flights&gt;&lt;flight&gt;&lt;flight_date&gt;01/20/2012&lt;/flight_date&gt;&lt;flight_number&gt;773&lt;/flight_number&gt;&lt;depart_time&gt;10:25am&lt;/depart_time&gt;&lt;arrive_time&gt;12:45pm&lt;/arrive_time&gt;&lt;depart_airport&gt;FORT WAYNE, IN (FWA)&lt;/depart_airport&gt;&lt;arrive_airport&gt;ORLANDO/SANFORD, FL (SFB)&lt;/arrive_airport&gt;&lt;stops&gt;Nonstop&lt;/stops&gt;&lt;/flight&gt;&lt;flight&gt;&lt;flight_date&gt;01/23/2012&lt;/flight_date&gt;&lt;flight_number&gt;772&lt;/flight_number&gt;&lt;depart_time&gt;7:15am&lt;/depart_time&gt;&lt;arrive_time&gt;9:40am&lt;/arrive_time&gt;&lt;depart_airport&gt;ORLANDO/SANFORD, FL (SFB)&lt;/depart_airport&gt;&lt;arrive_airport&gt;FORT WAYNE, IN (FWA)&lt;/arrive_airport&gt;&lt;stops&gt;Nonstop&lt;/stops&gt;&lt;/flight&gt;&lt;/flights&gt;&lt;trip_price&gt;329.96&lt;/trip_price&gt;&lt;taxes&gt;81.80&lt;/taxes&gt;&lt;trip_flex&gt;46.00&lt;/trip_flex&gt;&lt;seat_selections&gt;71.96&lt;/seat_selections&gt;&lt;priority_boarding&gt;39.96&lt;/priority_boarding&gt;&lt;bag_fees&gt;79.96&lt;/bag_fees&gt;&lt;total_cost&gt;649.64&lt;/total_cost&gt;&lt;reorder_url&gt;&lt;![CDATA[http://www.example.com]]&gt;&lt;/reorder_url&gt;&lt;/confirmation&gt;</value>
29    </attributes>
30    </subscribers>
31    </objects>
32    </createrequest>
33    </soap:body>
34</soap:envelope>

Axis2 Java Sample Code for Triggered Send 

1package com.exacttarget.client;
2import java.text.DateFormat;
3import java.text.SimpleDateFormat;
4import java.util.ArrayList;
5import java.util.Calendar;
6import java.util.List;
7import org.apache.axis2.addressing.EndpointReference;
8import org.apache.axis2.client.Options;
9import org.apache.axis2.client.ServiceClient;
10import org.apache.axis2.context.ConfigurationContext;
11import org.apache.axis2.context.ConfigurationContextFactory;
12import org.apache.log4j.Logger;
13import com.exacttarget.wsdl.partnerapi.APIObject;
14import com.exacttarget.wsdl.partnerapi.APIProperty;
15import com.exacttarget.wsdl.partnerapi.Attribute;
16import com.exacttarget.wsdl.partnerapi.ClientID;
17import com.exacttarget.wsdl.partnerapi.CreateOptions;
18import com.exacttarget.wsdl.partnerapi.CreateRequestDocument;
19import com.exacttarget.wsdl.partnerapi.CreateResponseDocument;
20import com.exacttarget.wsdl.partnerapi.CreateResponseDocument.CreateResponse;
21import com.exacttarget.wsdl.partnerapi.DataExtension;
22import com.exacttarget.wsdl.partnerapi.DataExtensionObject;
23import com.exacttarget.wsdl.partnerapi.CreateRequestDocument.CreateRequest;
24import com.exacttarget.wsdl.partnerapi.ObjectExtension.Properties;
25import com.exacttarget.wsdl.partnerapi.Options.SaveOptions;
26import com.exacttarget.wsdl.partnerapi.PartnerAPIStub;
27import com.exacttarget.wsdl.partnerapi.RequestType;
28import com.exacttarget.wsdl.partnerapi.SaveAction;
29import com.exacttarget.wsdl.partnerapi.SaveOption;
30import com.exacttarget.wsdl.partnerapi.Subscriber;
31import com.exacttarget.wsdl.partnerapi.TriggeredSend;
32import com.exacttarget.wsdl.partnerapi.TriggeredSendDefinition;
33import com.exacttarget.wsdl.partnerapi.UpdateOptions;
34import com.exacttarget.wsdl.partnerapi.UpdateRequestDocument;
35import com.exacttarget.wsdl.partnerapi.UpdateResponseDocument;
36import com.exacttarget.wsdl.partnerapi.UpdateRequestDocument.UpdateRequest;
37public class ETClient_TrigSend {
38    private PartnerAPIStub stub;
39    private static final String AXIS2_BASE_CONFIGURATION_FILE = PropertiesUtil.getInstance().getProperty("axis2File");
40    private static final String AXIS2_REPOSITORY_FOLDER = PropertiesUtil.getInstance().getProperty("repositoryFolder");
41    private static final String ET_END_POINT_REFERENCE = PropertiesUtil.getInstance().getProperty("endPoint");
42    private static Logger logger = Logger.getLogger(ETClient_TrigSend.class);
43    public ETClient_TrigSend() {
44        try{
45        ConfigurationContext configurationContext =
46        ConfigurationContextFactory.createConfigurationContextFromFileSystem(
47            AXIS2_REPOSITORY_FOLDER, AXIS2_BASE_CONFIGURATION_FILE);
48            EndpointReference endPointReference = new EndpointReference(ET_END_POINT_REFERENCE);
49            stub = new PartnerAPIStub(configurationContext, ET_END_POINT_REFERENCE);
50
51            ServiceClient serviceClient = stub._getServiceClient();
52            Options options = new Options();
53            options.setTo(endPointReference);
54            serviceClient.setOptions(options);
55        } catch(Exception e) {
56            logger.fatal(e);
57        }
58    }
59    public static void main(String a[]) {
60        ETClient_TrigSend ETClient_TrigSend = new ETClient_TrigSend();
61
62        ETClient_TrigSend.contructTriggeredSend();
63    }
64
65    public void contructTriggeredSend() {
66        TriggeredSendDefinition confirmationTrigger = TriggeredSendDefinition.Factory.newInstance();
67        confirmationTrigger.setCustomerKey("zz_test_confirmation");
68        confirmationTrigger.setNilObjectID();
69        confirmationTrigger.setNilPartnerKey();
70
71        Attribute XMLContent = Attribute.Factory.newInstance();
72        XMLContent.setName("confirmation_xml");
73        XMLContent.setValue("<?xml version=\"1.0\" encoding=\"UTF-8\"?><confirmation><confirmation_number>WXX9Q9</confirmation_number><confirmation_date>12/16/2011</confirmation_date><subject><![CDATA[Here is your Flight Confirmation]]></subject><passengers><passenger><first_name>Angela</first_name><middle_name>A</middle_name><last_name>Cruz</last_name><account_number>1234567</account_number><ticket_number>123456</ticket_number></passenger><passenger><first_name>Jane</first_name><middle_name>S</middle_name><last_name>Doe</last_name><account_number>- None Entered -</account_number><ticket_number>12345678</ticket_number></passenger></passengers><flights><flight><flight_date>01/20/2012</flight_date><flight_number>773</flight_number><depart_time>10:25am</depart_time><arrive_time>12:45pm</arrive_time><depart_airport>FORT WAYNE, IN (FWA)</depart_airport><arrive_airport>ORLANDO/SANFORD, FL (SFB)</arrive_airport><stops>Nonstop</stops></flight><flight><flight_date>01/23/2012</flight_date><flight_number>772</flight_number><depart_time>7:15am</depart_time><arrive_time>9:40am</arrive_time><depart_airport>ORLANDO/SANFORD, FL (SFB)</depart_airport><arrive_airport>FORT WAYNE, IN (FWA)</arrive_airport><stops>Nonstop</stops></flight></flights><trip_price>329.96</trip_price><taxes>81.80</taxes><trip_flex>46.00</trip_flex><seat_selections>71.96</seat_selections><priority_boarding>39.96</priority_boarding><bag_fees>79.96</bag_fees><total_cost>649.64</total_cost><reorder_url><![CDATA[http://www.example.com]]></reorder_url></confirmation>");
74//     XMLContent.setValue("");
75        DateFormat dateFormat       = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
76        Calendar cal                = Calendar.getInstance();
77        System.out.println("current time ::: " +dateFormat.format(cal.getTime()));
78//        Month value is 0-based. e.g., 0 for January.
79//        scheduledTime.set(2011, Calendar.NOVEMBER, 13, 12, 16);
80        Subscriber subscriber = Subscriber.Factory.newInstance();
81        subscriber.setAttributesArray(new Attribute[] {XMLContent});
82        subscriber.setEmailAddress("subscriber1@example.com");
83        subscriber.setSubscriberKey("subscriber1@example.com.com");
84//     Subscriber subscriber2 = Subscriber.Factory.newInstance();
85//     subscriber2.setAttributesArray(new Attribute[] {XMLContent});
86//     subscriber2.setEmailAddress("subscriber2@example.com");
87//     subscriber2.setSubscriberKey("subscriber2@example.com"); <-- this can be customerID, or any unique identifier
88//     Subscriber subscriber3 = Subscriber.Factory.newInstance();
89//     subscriber3.setAttributesArray(new Attribute[] {XMLContent});
90//     subscriber3.setEmailAddress("subscriber3@example.com");
91//     subscriber3.setSubscriberKey("subscriber3@example.com");
92//     Subscriber subscriber4 = Subscriber.Factory.newInstance();
93//     subscriber4.setAttributesArray(new Attribute[] {XMLContent});
94//     subscriber4.setEmailAddress("subscriber4@example.com");
95//     subscriber4.setSubscriberKey("subscriber4@example.com");
96        TriggeredSend triggeredSend = TriggeredSend.Factory.newInstance();
97        triggeredSend.setSubscribersArray(new Subscriber[] {subscriber});
98//     triggeredSend.setSubscribersArray(new Subscriber[] {subscriber, subscriber2, subscriber3, subscriber4});
99
100        triggeredSend.setTriggeredSendDefinition(confirmationTrigger);
101        doTriggeredSend(triggeredSend);
102    }
103    private String doTriggeredSend(APIObject apiObject) {
104        String statusCode = null;
105        try {
106            CreateOptions createOptions = CreateOptions.Factory.newInstance();
107//         createOptions.setRequestType(RequestType.ASYNCHRONOUS);
108            CreateRequest createRequest = CreateRequest.Factory.newInstance();
109            createRequest.setObjectsArray(new APIObject[] {apiObject});
110            createRequest.setOptions(createOptions);
111            CreateRequestDocument createRequestDocument = CreateRequestDocument.Factory.newInstance();
112            createRequestDocument.setCreateRequest(createRequest);
113            CreateResponseDocument createResponseDocument = this.stub.create(createRequestDocument);
114            System.out.println(createResponseDocument.getCreateResponse());
115
116            logger.fatal("create response :::  " + createResponseDocument.getCreateResponse());
117            statusCode = createResponseDocument.getCreateResponse().getResultsArray()[0].getStatusCode();
118        }catch(Exception e) {
119            logger.fatal(e);
120        }
121return statusCode;
122    }
123}

Create the Data Extension 

Create the data extension to hold the confirmation information using the information listed below:

  1. Create the data extention from the TriggeredSendDataExtension template.

  2. Check the Used for Sending checkbox.

  3. Choose EmailAddress in the first drop-down menu under the Type heading.

  4. Choose Email Address in the second drop-down menu under the Type heading.

  5. Under the Fields heading, enter the following information in the third field under SubscriberKey and EmailAddress:

    • Name: confirmation_xml
    • Data Type: Text
    • Length: 2000
  6. Click the Use Data Retention checkbox.

Create the Triggered Send 

You can create the triggered send used to send the confirmation information in the web interface or by using the SOAP API. Include the following information in your triggered send and start the triggered send once you have completed it:

  1. Select Default Commercial in the Send Classification drop-down menu.
  2. Select the email you created for this triggered send in the Email window.
  3. Select the data extension you created for this triggered send in the “Triggered Send” Data Extensions field.

See Also