1

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.

4

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>
5
  • 1
    You can use te ampscript API functions which mimic soap. I apologize they are just soap envelope samples, not ssjs. May 15 '17 at 18:59
  • 1
    @MarioRuiz - I made some edits to my answer that may better help solve your issue. May 18 '17 at 14:26
  • 1
    put it into a content area (inside classic) then call that content block with a SSJS script activity. You can then put that into an automation in Automation Studio. May 26 '17 at 17:18
  • Its hard to beat the SSJS functions I added in my edit, could you share your current solution? I am always curious about different ways to solve issues and finding the best ones. Jun 19 '17 at 16:30
  • Thanks man, this is absolutely useful!
    – mario ruiz
    Mar 24 at 0:10
2

If you have more than 2500 triggered sends in your BU, use this code which kind of pages through all available triggered sends. SOAP calls in general respond with a max of 2500 records.

Please use the external key to init the triggered send, not the name.

<script runat="server">

Platform.Load("Core","1");

// Retrieve API call to get all triggered send definitions

var rr = Platform.Function.CreateObject("RetrieveRequest");
Platform.Function.SetObjectProperty(rr, "ObjectType", "TriggeredSendDefinition");
Platform.Function.AddObjectArrayItem(rr, "Properties", "CustomerKey");
Platform.Function.AddObjectArrayItem(rr, "Properties", "TriggeredSendStatus");


// do while loop to do paging if there are more than 2500 triggered sends definitions

do {

    var results = [0,0];
    var rows = Platform.Function.InvokeRetrieve(rr, results);

    var runstatus = results[0];
    var requestId = results[1];

    if (rows != null) {

        // loop through all triggered send definitions

        for (var i in rows) {

            var key = rows[i].CustomerKey;
            var status = rows[i].TriggeredSendStatus;
            var now = Now();

            // if triggered send status is active, pause, publish, start triggered send definition

            if (status == "Active") {

                var tsd = TriggeredSend.Init(key);

                var pause = tsd.Pause();
                var publish = tsd.Publish();
                var start = tsd.Start();

            }
        } 
    } 

    rr.ContinueRequest = requestId;
    
} while (runstatus == "MoreDataAvailable")
1
  • Your code works but it is lack of </script> at the end of the code.
    – duyduc27
    Aug 11 at 7:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.