In the business unit in which you need to stop Journeys and delete them, create a DE with the following specifications:
Name: journeytodelete
External Key: journeytodelete
| Field Name | Data Type | Length | Primary Key | Nullable | Default Value |
| journeyname | Text | 254 | No | No | Not Applicable |
| isstopped | Boolean | Not Applicable | No | No | False |
| isdeleted | Boolean | Not Applicable | No | No | False |
After the DE has been created, populate the DE with journeyname for Journeys that need to be stopped and deleted.
You will need to create two SSJS activities - one to stop the Journeys and another to delete them. These activities will need to be run sequentially - as only Journeys where all versions are currently stopped are eligible for deletion.
1. Stop all Journey Versions of supplied Journeys:
NOTE: Please ensure that the clientId, clientSecret, and your account's authEndpoint values are supplied. This process leverages REST API - so you will need to reference an appropriate Installed Package within your account.
<script runat="server">
Platform.Load("Core", "1.1.1");
var clientId = 'YOUR CLIENT ID HERE';
var clientSecret = 'YOUR CLIENT SECRET HERE';
var authEndpoint = 'https://YOUR_SUBDOMAIN.auth.marketingcloudapis.com/v2/token';
var contentType = 'application/json';
var payload = {
client_id: clientId,
client_secret: clientSecret,
grant_type: 'client_credentials'
};
var accessTokenRequest = HTTP.Post(authEndpoint, contentType, Stringify(payload));
var accessTokenResponse = Platform.Function.ParseJSON(accessTokenRequest.Response[0]);
var accessToken = accessTokenResponse.access_token;
var resturl = accessTokenResponse.rest_instance_url
var api = new Script.Util.WSProxy();
var rowstoprocess = DataExtension.Init("journeytodelete").Rows.Lookup(["isstopped"],[0])
for(p=0; p < rowstoprocess.length; p ++ )
{
var journeyName = rowstoprocess[p].journeyname;
var getendpoint = resturl + "interaction/v1/interactions/?nameOrDescription=" + journeyName +"&mostRecentVersionOnly=false";
var headerNames = ["Authorization"];
var headerValues = ["Bearer " + accessToken];
var contentType = 'application/json';
var payload = '';
var response = HTTP.Get(getendpoint, headerNames, headerValues);
var responseBody = Platform.Function.ParseJSON(response.Content);
var journeyid = responseBody.items[0].id
for(j=0; j < responseBody.length; j ++ )
{
var versionnum = responseBody.items[j].version
var status = responseBody.items[j].status
var stopendpoint = resturl + "/interaction/v1/interactions/stop/" + journeyid + "?versionNumber=" + responseBody.items[j].version
if (typeof versionnum === 'undefined') {
} else {
if (status == "Unpublished" || status === "Published"){ var response2 = HTTP.Post(stopendpoint, contentType, payload, headerNames, headerValues);
}
else {}}
}
DataExtension.Init('journeytodelete').Rows.Update({"isstopped": "1"}, ["journeyname"], [journeyName]);
}
</script>
2. Delete Stopped Journeys
<script runat="server">
Platform.Load("Core", "1.1.1");
var clientId = 'YOUR CLIENT ID HERE';
var clientSecret = 'YOUR CLIENT SECRET HERE';
var authEndpoint = 'https://YOUR_SUBDOMAIN.auth.marketingcloudapis.com/v2/token';
var contentType = 'application/json';
var payload = {
client_id: clientId,
client_secret: clientSecret,
grant_type: 'client_credentials'
};
var accessTokenRequest = HTTP.Post(authEndpoint, contentType, Stringify(payload));
var accessTokenResponse = Platform.Function.ParseJSON(accessTokenRequest.Response[0]);
var accessToken = accessTokenResponse.access_token;
var resturl = accessTokenResponse.rest_instance_url
var api = new Script.Util.WSProxy();
var rowstoprocess = DataExtension.Init("journeytodelete").Rows.Lookup(["isdeleted"],[0])
for(p=0; p < rowstoprocess.length; p ++ )
{
var journeyName = rowstoprocess[p].journeyname;
var getendpoint = resturl + "interaction/v1/interactions/?nameOrDescription=" + journeyName;
var headerNames = ["Authorization"];
var headerValues = ["Bearer " + accessToken];
var response = HTTP.Get(getendpoint, headerNames, headerValues);
var responseBody = Platform.Function.ParseJSON(response.Content);
var journeyid = responseBody.items[0].id
var deleteendpoint = resturl + "interaction/v1/interactions/" + journeyid;
var auth = 'Bearer ' + accessToken;
var req = new Script.Util.HttpRequest(deleteendpoint);
req.setHeader("Authorization", auth);
req.method = "DELETE";
var resp = req.send();
DataExtension.Init('journeytodelete').Rows.Update({"isdeleted": "1"}, ["journeyname"], [journeyName]);
}
</script>000395782

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.