[SalesForce] How to restart a Triggered Send from the AmpScript

I have defined a Triggered Send based on a sendable Data Extension and an EMail AMPScript. I have assigned a external key to the Triggered Send and is sending emails when I create a POST request to the endpoint https://www.exacttargetapis.com/messaging/v1/messageDefinitionSends/external_key/send

I would like to know if there's a way to restart the Triggered Send programatically. I know there's a dashboard UI I can use but I'm not interested in do it manually.

Do you know how to do it? I have tons of Triggered Sends and I'd like to automate the pause/publish/restart process for each TS.

Best Answer

EDIT

This is the most optimized solution I could find using AMPScript - albeit part of it is done in SSJS, but that part greatly reduces the code weight and optimizes the speed of the script.

As I was unsure which triggers you wanted to pause or restart, I filtered based on just 'currently active'.

%%[

/************************************

Retrieve Request - list of all Triggered Sends

*************************************/

SET @rr = CreateObject("RetrieveRequest")  
SetObjectProperty(@rr, "ObjectType", "TriggeredSendDefinition")  
AddObjectArrayItem(@rr,"Properties","CustomerKey")  
AddObjectArrayItem(@rr,"Properties","Name")  
AddObjectArrayItem(@rr,"Properties","TriggeredSendStatus")   


/* Invoke the Retrieve Request API */

SET @tsd = InvokeRetrieve(@rr, @Status, @RequestID)  



/*******************************************

FOR loop - to iterate and update all Active Triggers

*******************************************/


FOR @c = RowCount(@tsd) DOWNTO 1  DO    

    SET @row = Row(@tsd ,@c)   
    SET @TSDName = Field(@row ,'Name')   
    SET @TSDKey = Field(@row ,'CustomerKey')
    SET @TSDStatus = Field(@row, 'TriggeredSendStatus')

    IF @TSDStatus == "Active" THEN

]%%

<script runat="server">
Platform.Load("core","1");

var tsdName = Variable.GetValue("@TSDName");
var tsd = TriggeredSend.Init(tsdName);

var pause = tsd.Pause();
var publish = tsd.Publish();
var start = tsd.Start();
</script>


%%[

    ENDIF

NEXT @c
]%%  

I had the same sort of issue and it took a large chunk of my life to solve.

Reference this question/answer for more info on my exact issue: SOAP API to 'publish' a TriggeredSendDefinition?

As I am assuming you want to do a pause, publish and run - See below for API calls which will do a full restart on the triggered email interaction.

You just need to do the requests via the AMPScript API functions.

See below for sample SOAP envelopes to accomplish this:

Pause

<!--***pause***-->

<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: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">
   <soap:Header>
      <wsse:Security soap:mustUnderstand="1">
         <wsse:UsernameToken wsu:Id="UsernameToken-452336374" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
            <wsse:Username>USERNAME</wsse:Username>
            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">PASSWORD</wsse:Password>
         </wsse:UsernameToken>
      </wsse:Security>
   </soap:Header>
   <soap:Body>
      <UpdateRequest xmlns="http://exacttarget.com/wsdl/partnerAPI">
         <Objects xsi:type="TriggeredSendDefinition">
        <!-- This section here is only necessary if you are targeting a Welcome Email within a Business Unit -->
            <Client>
               <ID>YOUR_MID</ID>
            </Client>
        <!--END-->
            <CustomerKey>TriggeredSend-customer-key-goes-here</CustomerKey>
            <TriggeredSendStatus>Inactive</TriggeredSendStatus>
         </Objects>
      </UpdateRequest>
   </soap:Body>
</soap:Envelope>

Publish

<!--***publish***-->

<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: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">
   <soap:Header>
      <wsse:Security soap:mustUnderstand="1">
         <wsse:UsernameToken wsu:Id="UsernameToken-452336374" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
            <wsse:Username>MC_USERNAME</wsse:Username>
            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">PASSWORD</wsse:Password>
         </wsse:UsernameToken>
      </wsse:Security>
   </soap:Header>
   <soap:Body>
      <UpdateRequest xmlns="http://exacttarget.com/wsdl/partnerAPI">
         <Objects xsi:type="TriggeredSendDefinition">
        <!-- This section here is only necessary if you are targeting a Welcome Email within a Business Unit -->
            <Client>
               <ID>YOUR_MID</ID>
            </Client>
        <!--END-->
            <CustomerKey>TriggeredSend-customer-key-goes-here</CustomerKey>
            <RefreshContent>true</RefreshContent>
         </Objects>
      </UpdateRequest>
   </soap:Body>
</soap:Envelope>

Restart

<!--***restart***-->

<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: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">
   <soap:Header>
      <wsse:Security soap:mustUnderstand="1">
         <wsse:UsernameToken wsu:Id="UsernameToken-452336374" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
            <wsse:Username>USERNAME</wsse:Username>
            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">PASSWORD</wsse:Password>
         </wsse:UsernameToken>
      </wsse:Security>
   </soap:Header>
   <soap:Body>
      <UpdateRequest xmlns="http://exacttarget.com/wsdl/partnerAPI">
         <Objects xsi:type="TriggeredSendDefinition">
        <!-- This section here is only necessary if you are targeting a Welcome Email within a Business Unit -->
            <Client>
               <ID>YOUR_MID</ID>
            </Client>
        <!--END-->
            <CustomerKey>TriggeredSend-customer-key-goes-here</CustomerKey>
            <TriggeredSendStatus>Active</TriggeredSendStatus>
         </Objects>
      </UpdateRequest>
   </soap:Body>
</soap:Envelope>
Related Topic