I am trying to add an existing Query Activity to an existing Automation using a SSJS script. This is my code. I have referred the doc
<script runat="server">
Platform.Load("core", "1");
var api = new Script.Util.WSProxy();
var restInstanceUrl = "https://SUBDOMAIN.rest.marketingcloudapis.com";
var accessToken = "--------";
try
{
var myActivity = {
"name": "myquery",
"objectTypeId": 300,
"displayOrder": 1,
"activityObjectId": "d3771ef8-1be9-4bd7-9539-c0e4b445f019"
};
var automationObjectId = "c3e1111e-6777-408b-b4f9-556d76539281";
var endpoint = restInstanceUrl + "automation/v1/automations/" + automationObjectId;
var request = new Script.Util.HttpRequest(endpoint);
request.emptyContentHandling = 0;
request.retries = 2;
request.continueOnError = true;
request.setHeader("Authorization", "Bearer " + accessToken);
request.method = "GET";
request.contentType = "application/json";
var results = request.send();
var result = Platform.Function.ParseJSON(String(results.content));
var activities = result.steps[result.steps.length - 1].activities;
activities.push(myActivity);
var payload = {
steps: result.steps
};
var request = new Script.Util.HttpRequest(endpoint);
request.emptyContentHandling = 0;
request.retries = 2;
request.continueOnError = true;
request.setHeader("Authorization", "Bearer " + accessToken);
request.method = "PATCH";
request.contentType = "application/json";
request.encoding = "UTF-8";
request.postData = Stringify(payload);
var results = request.send();
var result = Platform.Function.ParseJSON(String(results.content));
Write(Stringify(result));
}
catch(error) {
Write(Stringify(error));
}
</script>
But I am getting error :
{"message":"Object expected: push","jintException":"Jint.Native.JsException: Exception of type 'Jint.Native.JsException' was thrown.\r\n at Jint.ExecutionVisitor.Visit(MethodCall methodCall)\r\n at Jint.Expressions.MethodCall.Accept(IJintVisitor visitor)\r\n at Jint.ExecutionVisitor.Visit(MemberExpression expression)\r\n at Jint.Expressions.MemberExpression.Accept(IJintVisitor visitor)\r\n at Jint.ExecutionVisitor.Visit(ExpressionStatement statement)\r\n at Jint.Expressions.ExpressionStatement.Accept(IJintVisitor visitor)\r\n at Jint.ExecutionVisitor.Visit(BlockStatement statement)\r\n at Jint.Expressions.BlockStatement.Accept(IJintVisitor visitor)\r\n at Jint.ExecutionVisitor.Visit(TryStatement statement)","description":"Jint.Native.JsException: Object expected: push\r\nException of type 'Jint.Native.JsException' was thrown. - from Jint\r\n\r\n"}
Could please someone help me, point out what is wrong in the code?