2

I'm trying to find a way to "unpause" a paused automation via API (using SSJS). When an automation is in "Ready" status (status code 2), you're able to invoke a perform (InvokePerform) to kick off the automation. A paused automation (status code 4), for some reason, cannot be "unpaused" this same way. Documentation is pretty scarce for this, so I'm curious if anyone knows how to get an automation back on its schedule via API. My gut instinct would be an UpdateRequest in some way rather than a Perform.

Another idea I was thinking was to "Stop" the automation, then "Start" it again. The code below will not "Stop" a paused automation:

<script runat="server">

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

var automationCustomerKey = "CUSTOMERKEY-OF-AUTOMATION"

var rr = Platform.Function.CreateObject("RetrieveRequest");
Platform.Function.SetObjectProperty(rr, "ObjectType", "Automation");
Platform.Function.AddObjectArrayItem(rr, "Properties", "ProgramID");
Platform.Function.AddObjectArrayItem(rr, "Properties", "CustomerKey");
Platform.Function.AddObjectArrayItem(rr, "Properties", "Status");

var sfp = Platform.Function.CreateObject("SimpleFilterPart");
Platform.Function.SetObjectProperty(sfp, "Property", "CustomerKey");
Platform.Function.SetObjectProperty(sfp, "SimpleOperator", "equals");
Platform.Function.AddObjectArrayItem(sfp, "Value", automationCustomerKey);

Platform.Function.SetObjectProperty(rr, "Filter", sfp);

var retrieveStatus = [0,0,0];

var automationResultSet = Platform.Function.InvokeRetrieve(rr, retrieveStatus);

var ObjectID = automationResultSet[0]["ObjectID"];
var Status = automationResultSet[0]["Status"];

if (ObjectID != "null") {

    /*
    Code Status
    -1   Error
     0   BuildingError
     1   Building
     2   Ready
     3   Running
     4   Paused
     5   Stopped
     6   Scheduled
     7   Awaiting Trigger
     8   InactiveTrigger
    */

    if (Status == 2) {

        var obj = Platform.Function.CreateObject("Automation");
        Platform.Function.SetObjectProperty(obj, "ObjectID", ObjectID);
        var po = Platform.Function.CreateObject("PerformOptions");

        var performResult = [0,0,0];
        var performStatus = Platform.Function.InvokePerform(obj, "stop", performResult, po);

    } else {
      // already running

    }
} else {
   // automation not found
}

</script>

1 Answer 1

2

When writing SSJS, I tend to hunt down SOAP envelopes for what I'm trying to do and then translate them to SSJS.

There are several Automation SOAP examples on this page. These should give you some insight about starting an Automation. Here's one for pausing:

<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">
   <soap:Header>
      <wsse:Security soap:mustUnderstand="1">
         <wsse:UsernameToken wsu:Id="SecurityToken-4c1eed3b-75ee-4d19-8712-731028aaad77">
            <wsse:Username>XXXXX</wsse:Username>
            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">XXXXX</wsse:Password>
         </wsse:UsernameToken>
      </wsse:Security>
   </soap:Header>
   <soap:Body>
      <ScheduleRequestMsg xmlns="http://exacttarget.com/wsdl/partnerAPI">
         <Action>pause</Action>
         <Schedule></Schedule>
         <Interactions>
            <Interaction xsi:type="Automation">
               <ObjectID>78d55eb5-0811-4638-a574-374a242426f7</ObjectID>
            </Interaction>
         </Interactions>
      </ScheduleRequestMsg>
   </soap:Body>
</soap:Envelope>

Once you get it working, please share your code. I'm sure others will find it helpful.

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.