Hi All,
I wants stop active journey using SSJS. I have a code and when I tried to run the code am getting below error message. Unable to find out the error.
Error Message: "Exception has been thrown by the target of an invocation."
Description: "System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. - from mscorlib --> --- inner exception 1--- ExactTarget.OMM.FunctionExecutionException: WSProxy object is not valid in sendable content. This function is only allowed in non-sendable content. Object: Script.Util.WSProxy() Error Code: OMM_FUNC_CONTEXT_ERR - from OMMCommon "
Here is my code :-
<script runat="server">
Platform.Load("Core", "1.1.1");
var clientId = 'jiwwb8ejoy0ey1afk6jf9xlq';
var clientSecret = 'FlQ7QbB5U6msQqgM2LpTzg3x';
var authEndpoint = 'https://mc2z1g5d3ftf0z0tbm3hx5rcmnxq.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>