verified
Create an AutomationLearn how to create an Automation in Salesforce Marketing Cloud (SFMC) with SSJS (server-side JavaScript). Code snippets include the WSProxy method.
WSProxy
var api = new Script.Util.WSProxy();
api.setClientId({
"ID": Platform.Function.AuthenticatedMemberID(),
"UserID": Platform.Function.AuthenticatedEmployeeID()
});
var config = {
Name: "MyAutomation",
CustomerKey: GUID(),
Description: "",
AutomationType: "Scheduled",
CategoryID: null
};
var result = api.createItem('Automation', config);
<script runat="server">
Platform.Load("core", "1");
var api = new Script.Util.WSProxy();
api.setClientId({
"ID": Platform.Function.AuthenticatedMemberID(),
"UserID": Platform.Function.AuthenticatedEmployeeID()
});
try {
var config = {
Name: "MyAutomation",
CustomerKey: GUID(),
Description: "",
AutomationType: "Scheduled",
CategoryID: null
};
var result = api.createItem('Automation', config);
Write(Stringify(result));
} catch(error) {
Write(Stringify(error));
}
</script>
{
"Status": "OK",
"RequestID": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
"Results": [
{
"NewID": 0,
"NewObjectID": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
"PartnerKey": null,
"Object": {
"Schedule": null,
"AutomationTasks": null,
"IsActive": true,
"AutomationSource": null,
"Status": 0,
"Notifications": null,
"ScheduledTime": "0001-01-01T00:00:00.000",
"AutomationType": "Scheduled",
"UpdateModified": false,
"LastRunInstanceID": null,
"CreatedBy": 0,
"CategoryID": null,
"LastRunTime": "0001-01-01T00:00:00.000",
"LastSaveDate": "0001-01-01T00:00:00.000",
"ModifiedBy": 0,
"RecurrenceID": null,
"LastSavedBy": 0,
"InteractionObjectID": null,
"Name": "MyAutomation",
"Description": "",
"Keyword": null,
"Client": {
"ID": 100000000,
"ClientID1": 0,
"PartnerClientKey": null,
"UserID": 100000000,
"PartnerUserKey": null,
"CreatedBy": 0,
"ModifiedBy": 0,
"EnterpriseID": 0,
"CustomerKey": null,
"CustomerID": null
},
"PartnerKey": null,
"PartnerProperties": [
{
"Name": "AutomationType",
"Value": "Scheduled"
}
],
"CreatedDate": "0001-01-01T00:00:00.000",
"ModifiedDate": null,
"ID": 0,
"ObjectID": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
"CustomerKey": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
"Owner": null,
"CorrelationID": null,
"ObjectState": null,
"IsPlatformObject": false
},
"CreateResults": null,
"ParentPropertyName": null,
"StatusCode": "OK",
"StatusMessage": null,
"OrdinalID": 0,
"ErrorCode": 0,
"RequestID": null,
"ConversationID": null,
"OverallStatusCode": null,
"RequestType": "Synchronous",
"ResultType": null,
"ResultDetailXML": null
}
]
}
WARNING
setClientId is required to avoid the "Create Access is denied!" error.
Reference
Ressources and references related to the current methods.
Official documentation
SOAP object