Retrieve an Automation verified

Learn how to retrieve an Automation in Salesforce Marketing Cloud (SFMC) with SSJS (server-side JavaScript). Code snippets include Platform, WSProxy and REST API methods.

Platform

var name = "MyAutomation";

var cols = [
    "Name",
    "Description",
    "CustomerKey",
    "IsActive",
    "CreatedDate",
    "ModifiedDate",
    "Status",
    "ProgramID",
    "CategoryID",
    "LastRunTime",
    "ScheduledTime",
    "LastSaveDate",
    "ModifiedBy",
    "LastSavedBy",
    "CreatedBy",
    "AutomationType",
    "RecurrenceID"
];

var request = Platform.Function.CreateObject("RetrieveRequest");

for(var i = 0; i < cols.length; i++) {
    Platform.Function.AddObjectArrayItem(request, "Properties", cols[i]);
}

Platform.Function.SetObjectProperty(request, "ObjectType", "Automation");

var filter =  Platform.Function.CreateObject("SimpleFilterPart");

Platform.Function.SetObjectProperty(filter, "Property", "Name");
Platform.Function.SetObjectProperty(filter, "SimpleOperator", "equals");
Platform.Function.AddObjectArrayItem(filter, "Value", name);

Platform.Function.SetObjectProperty(request, "Filter", filter);

var status = [0, 0, 0];

var result = Platform.Function.InvokeRetrieve(request, status);
<script runat="server">

    Platform.Load("core", "1");

	try {

        var name = "MyAutomation";

        var cols = [
            "Name",
            "Description",
            "CustomerKey",
            "IsActive",
            "CreatedDate",
            "ModifiedDate",
            "Status",
            "ProgramID",
            "CategoryID",
            "LastRunTime",
            "ScheduledTime",
            "LastSaveDate",
            "ModifiedBy",
            "LastSavedBy",
            "CreatedBy",
            "AutomationType",
            "RecurrenceID"
        ];

        var request = Platform.Function.CreateObject("RetrieveRequest");

        for(var i = 0; i < cols.length; i++) {
            Platform.Function.AddObjectArrayItem(request, "Properties", cols[i]);
        }

        Platform.Function.SetObjectProperty(request, "ObjectType", "Automation");

        var filter =  Platform.Function.CreateObject("SimpleFilterPart");

        Platform.Function.SetObjectProperty(filter, "Property", "Name");
        Platform.Function.SetObjectProperty(filter, "SimpleOperator", "equals");
        Platform.Function.AddObjectArrayItem(filter, "Value", name);

        Platform.Function.SetObjectProperty(request, "Filter", filter);

        var status = [0, 0, 0];

        var result = Platform.Function.InvokeRetrieve(request, status);

        Platform.Response.Write(Platform.Function.Stringify(result));
		
	} catch(error) {

        Platform.Response.Write(Platform.Function.Stringify(error));

    }	

</script>
[
    {
        "Schedule": null,
        "AutomationTasks": null,
        "IsActive": true,
        "IsActiveSpecified": true,
        "AutomationSource": null,
        "Status": 2,
        "StatusSpecified": true,
        "Notifications": null,
        "ScheduledTime": "0001-01-01T00:00:00.000",
        "ScheduledTimeSpecified": false,
        "AutomationType": "scheduled",
        "UpdateModified": false,
        "UpdateModifiedSpecified": false,
        "LastRunInstanceID": null,
        "CreatedBy": 0,
        "CreatedBySpecified": true,
        "CategoryID": "12345",
        "LastRunTime": "0001-01-01T00:00:00.000",
        "LastRunTimeSpecified": false,
        "LastSaveDate": "2022-12-13T12:04:44.313",
        "LastSaveDateSpecified": true,
        "ModifiedBy": 0,
        "ModifiedBySpecified": true,
        "RecurrenceID": "00000000-0000-0000-0000-000000000000",
        "LastSavedBy": 715074318,
        "LastSavedBySpecified": true,
        "InteractionObjectID": null,
        "Name": "MyAutomation",
        "Description": "",
        "Keyword": null,
        "Client": null,
        "PartnerKey": null,
        "PartnerProperties": null,
        "CreatedDate": "2022-12-13T10:16:59.390",
        "CreatedDateSpecified": true,
        "ModifiedDate": "2022-12-13T12:04:44.527",
        "ModifiedDateSpecified": true,
        "ID": 0,
        "IDSpecified": false,
        "ObjectID": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
        "CustomerKey": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
        "Owner": null,
        "CorrelationID": null,
        "ObjectState": null,
        "IsPlatformObject": false,
        "IsPlatformObjectSpecified": false
    }
]

WSProxy

var api = new Script.Util.WSProxy();

var name = "MyAutomation";

var cols = [
    "Name",
    "Description",
    "CustomerKey",
    "IsActive",
    "CreatedDate",
    "ModifiedDate",
    "Status",
    "ProgramID",
    "CategoryID",
    "LastRunTime",
    "ScheduledTime",
    "LastSaveDate",
    "ModifiedBy",
    "LastSavedBy",
    "CreatedBy",
    "AutomationType",
    "RecurrenceID"
];

var result = api.retrieve("Automation", cols, {
    Property: "Name",
    SimpleOperator: "equals",
    Value: name
});
<script runat="server">

    Platform.Load("core", "1");

    var api = new Script.Util.WSProxy();
	
	try {

        var name = "MyAutomation";

        var cols = [
            "Name",
            "Description",
            "CustomerKey",
            "IsActive",
            "CreatedDate",
            "ModifiedDate",
            "Status",
            "ProgramID",
            "CategoryID",
            "LastRunTime",
            "ScheduledTime",
            "LastSaveDate",
            "ModifiedBy",
            "LastSavedBy",
            "CreatedBy",
            "AutomationType",
            "RecurrenceID"
        ];

        var result = api.retrieve("Automation", cols, {
            Property: "Name",
            SimpleOperator: "equals",
            Value: name
        });

        Write(Stringify(result));
		
	} catch(error) {
        Write(Stringify(error));
    }	

</script>
{
    "Status": "OK",
    "RequestID": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
    "Results": [
        {
            "Schedule": null,
            "AutomationTasks": null,
            "IsActive": true,
            "AutomationSource": null,
            "Status": 2,
            "Notifications": null,
            "ScheduledTime": "0001-01-01T00:00:00.000",
            "AutomationType": "scheduled",
            "UpdateModified": false,
            "LastRunInstanceID": null,
            "CreatedBy": 0,
            "CategoryID": "3267",
            "LastRunTime": "2022-10-25T08:01:49.677",
            "LastSaveDate": "2022-10-25T07:56:39.946",
            "ModifiedBy": -1000,
            "RecurrenceID": "00000000-0000-0000-0000-000000000000",
            "LastSavedBy": 100122390,
            "InteractionObjectID": null,
            "Name": "MyAutomation",
            "Description": "Updated",
            "Keyword": null,
            "Client": null,
            "PartnerKey": null,
            "PartnerProperties": null,
            "CreatedDate": "2022-10-25T07:50:30.197",
            "ModifiedDate": "2022-10-25T08:21:50.663",
            "ID": 0,
            "ObjectID": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
            "CustomerKey": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
            "Owner": null,
            "CorrelationID": null,
            "ObjectState": null,
            "IsPlatformObject": false
        }
    ],
    "HasMoreRows": false
}

REST API

var id = "123456";

var endpoint = restInstanceUrl + "automation/v1/automations/" + id;

var request = HTTP.Get(endpoint, ["Authorization"], ["Bearer " + accessToken]);

var result = Platform.Function.ParseJSON(String(request.Content));

<script runat="server">

    Platform.Load("core", "1");

    var api = new Script.Util.WSProxy();

    var restInstanceUrl = "https://YOUR_SUBDOMAIN.rest.marketingcloudapis.com/",
        accessToken     = "YOUR_REST_API_TOKEN";
	
	try {

        var id = "123456";

        var endpoint = restInstanceUrl + "automation/v1/automations/" + id;

        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));

        Write(Stringify(result));
		
	} catch(error) {

        Write(Stringify(error));
        
    }	

</script>
{
    "id": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
    "name": "MyAutomation",
    "description": "",
    "key": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
    "typeId": 1,
    "type": "scheduled",
    "statusId": 4,
    "status": "PausedSchedule",
    "categoryId": 45678,
    "lastRunTime": "2024-12-01T12:00:00Z",
    "lastRunInstanceId": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
    "schedule": {
        "id": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
        "typeId": 3,
        "startDate": "2024-12-01T12:00:00Z",
        "endDate": "2024-12-01T12:00:00Z",
        "scheduledTime": "0001-01-01T07:00:00Z",
        "rangeTypeId": 0,
        "occurrences": 1,
        "pattern": "<Pattern><PatternType>0</PatternType><DayInterval>1</DayInterval></Pattern>",
        "icalRecur": "FREQ=DAILY;COUNT=1;INTERVAL=1",
        "timezoneName": "Eastern Standard Time",
        "scheduleStatus": "paused",
        "timezoneId": 76
    },
    "steps": [
        {
            "id": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
            "name": "Step 1",
            "step": 1,
            "activities": [
                {
                    "id": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
                    "name": "1 Seconds Wait",
                    "activityObjectId": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
                    "objectTypeId": 467,
                    "displayOrder": 1
                }
            ]
        },
        {
            "id": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
            "name": "Step 2",
            "step": 2,
            "activities": [
                {
                    "id": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
                    "name": "1 Seconds Wait",
                    "activityObjectId": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
                    "objectTypeId": 467,
                    "displayOrder": 1
                }
            ]
        }
    ]
}

Reference

Ressources and references related to the current methods.

REST documentation
SOAP documentation
SOAP object

Last Updated: