Submit a Triggered Send Definition Using the Asynchronous API
This Page
All Documentation
This page contains information regarding submitting triggered send definitions using the asynchronous API.
Why Submit a Triggered Send Definition Using the Asynchronous API
By using the asynchronous API, you can assign priorities to your API calls or sequence and schedule them for a later date. The asynchronous API also holds calls in queue until it processes them, meaning that the system doesn’t lose your calls in case of an unplanned outage. The asynchronous nature of the calls also prevents unintentional call replays.
How to Submit a Triggered Send Definition Using the Asynchronous API
Use the sample code below as a model to submit your own triggered send definition call to the asynchronous API:
Sample .NET Code
1//Create a new Subscriber to send the TriggerSend to2 Subscriber newSub = new Subscriber();3 newSub.EmailAddress = emailAddress;4 newSub.SubscriberKey = emailAddress;5 //Create Subscriber Attributes6 newSub.Attributes = new Attribute[2];7 //Attribute 18 newSub.Attributes[0] = new Attribute();9 newSub.Attributes[0].Name = "FromName";10 newSub.Attributes[0].Value = "From John Doe";11 //Attribute 212 newSub.Attributes[1] = new Attribute();13 newSub.Attributes[1].Name = "HTML__Content";14 newSub.Attributes[1].Value = "<b>Sent Asynchronously!</b>";15 //Create a TriggeredSend that uses an existing TriggeredSendDefinition16 TriggeredSend ts = new TriggeredSend();17 ts.TriggeredSendDefinition = new TriggeredSendDefinition();18 ts.TriggeredSendDefinition.CustomerKey = "ETWSEX_TSD";19 ts.TriggeredSendDefinition.Priority = "High";//This is another feature20 //Instantiate the CreateOptions object for the create call of TSD21 CreateOptions cOptionsTS = new CreateOptions();22 cOptionsTS.RequestType = RequestType.Asynchronous;23 cOptionsTS.RequestTypeSpecified = true;24 cOptionsTS.QueuePriority = Priority.High;25 cOptionsTS.QueuePrioritySpecified = true;26 ts.Subscribers = new Subscriber[] { newSub };27 try28 {29 //Create the TriggeredSend30 string tsRequestID = "";31 string tsStatus = "";32 CreateResult[] tsResults = client.Create(cOptionsTS, new APIObject[] { ts }, out tsRequestID, out tsStatus);33 TriggeredSendCreateResult tsCreateResults = tsResults[0] as TriggeredSendCreateResult;34 //Check for Error35 if (tsStatus != "OK") { throw new Exception(); }36 }37 catch (Exception exCreate)38 {39 }
Setting the priority on a triggered sendrequires that more functionality be enabled for your account. Contact your Account Executive for more details on this feature and to enable this feature for your account.
How to Retrieve the Status
Use the sample code below as a model to retrieve the status of the triggered send API call:
Sample .NET Code
1//Check the ResultItem2//Create the filter, passing in the RequestID of the TriggeredSend3SimpleFilterPart sfp = new SimpleFilterPart();4sfp.Property = "RequestID";5sfp.SimpleOperator = SimpleOperators.equals;6sfp.Value = new string[] { requestID };7//Create a String Array of Properties to Retreive for the Object8string[] oProps = new string[] { "RequestType", "ErrorCode", "StatusCode" };9//Create RetreiveRequest Object10RetrieveRequest rr = new RetrieveRequest();11rr.ObjectType = "ResultItem";12rr.Properties = oProps;13rr.Filter = sfp;14//Call the Retrieve Method for the RetrieveRequest Object15APIObject[] rResults;16string rStatus = "";17string rRequestID = "";18rStatus = client.Retrieve(rr, out rRequestID, out rResults);