1

I've written a script to remove a batch of contacts from a Journey since we've revised our criteria of who should enter. After testing it on a sample set of subscriberkeys, I searched for them in Journey Health, and the button to remove them from the journey is still active. My first question is, is there a better way to tell if a contact has been successfully removed from the journey?

When I test the script in CloudPages, I get a 202 status with no errors, so my second question is, how long does the process of removing contacts from a journey take?

I'm working on a larger project involving API calls in a script activity, so it's important that I debug anything that might be going wrong with my code.

<script type="javascript" runat="server">
    Platform.Load("core","1.1.5");
    
    var url = 'https://xxxxxxx.auth.marketingcloudapis.com/v2/token';
    
    var contentType = 'application/json';
    
    var payload = {
        "grant_type":"client_credentials",
        "client_id":"xxxxxxx",
        "client_secret":"xxxxxxx"
    };
    
    var authRequest = HTTP.Post(url, contentType, Stringify(payload));
    var statusCode = authRequest["StatusCode"];
    var response = authRequest["Response"][0];
    var accessToken = Platform.Function.ParseJSON(response).access_token;
    
    var result = HTTP.Post(url, contentType, Stringify(payload), headerNames, headerValues);
    
    result = Stringify(result).replace(/[\n\r]/g, '');
    
    var DE = DataExtension.Init('DE Key');
    
    var data = DE.Rows.Retrieve();

    for (var i = 0; i < data.length; i++) {
       var subkey = data[i].SubscriberKey;
     
       url = "https://xxxxxxx.rest.marketingcloudapis.com";
       url += "/interaction/v1/interactions/contactexit";
       var headerNames = ["Authorization"];
       var headerValues = ["Bearer " + accessToken];
     
       var payload = [{
         "ContactKey": subkey,
         "DefinitionKey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
       }];

       var result = HTTP.Post(url, contentType, Stringify(payload), headerNames, headerValues);
       result = Stringify(result).replace(/[\n\r]/g, '');
    }  
</script>

1 Answer 1

2

After a few attempts, I can tell you some things what I have experienced:

  • The button "Remove from journey" in Journey Health does the same thing with the API call Remove Contact from a Journey

  • Even a contact was removed from the journey, the button above was still able to show up and was clickable from the UI.

How to tell if a contact has been successfully removed from the journey?

You can use this API Get Contact's Exit Status from a Journey. Basically it will return a response so you can determine if the contact is still existed in the journey or not.

Message:

  • Exit request Not Found: the contact hasn't been requested to be removed
  • Exit request received for processing: processing stage
  • Exit request Cancelled - Contact not in this Interaction: the contact was successfully removed.

How long does the process of removing contacts from a journey take?

I guess it will depend on the number of contacts being removed. A few seconds for a single contact, from what I tried.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .