Create via WSProxy

To create a single item or several items of the same type in a single call, use the createItem() and createBatch() methods.

  • For the first parameter, specify the object type to perform the action on, such as Email or DataExtension.
  • The second parameter is an object that represents the fields and values to set on the object. For batch operations, the second parameter is an Array of objects rather than a single object.
  • The third parameter is optional and includes any properties to set using the CreateOptions object.

Create a Single DataExtension Object 

This example creates a simple DataExtension object that contains an ID and a Name field.

1var prox = new Script.Util.WSProxy();
2
3var guid = Platform.Function.GUID();
4var name = "my test de - " + guid;
5
6var de = {
7    Name: name,
8    CustomerKey: guid,
9    Description: "Another DE added via SSJS",
10    Fields: [{
11        FieldType: "Text",
12        Name: "ID",
13        MaxLength: 36,
14        IsPrimaryKey: true,
15        IsNillable: false,
16        IsRequired: true
17    },
18    {
19        FieldType: "Text",
20        Name: "Name",
21        MaxLength: 200
22    }],
23    CategoryID: 101377
24}
25
26var res = prox.createItem("DataExtension", de);

Create Multiple DataExtension Objects 

This example creates two similar data extensions using the createBatch function.

1var prox = new Script.Util.WSProxy();
2var guid = Platform.Function.GUID();
3var name = "my test de - 1 - " + guid;
4
5var de1 = {
6    Name: name,
7    CustomerKey: guid,
8    Description: "Another DE added via SSJS",
9    Fields: [{
10        FieldType: "Text",
11        Name: "ID",
12        MaxLength: 36,
13        IsPrimaryKey: true,
14        IsNillable: false,
15        IsRequired: true
16    },
17    {
18        FieldType: "Text",
19        Name: "Name",
20        MaxLength: 200
21    }],
22    CategoryID: 101377
23}
24guid = Platform.Function.GUID();
25name = "my test de - 2 - " + guid;
26
27var de2 = {
28    Name: name,
29    CustomerKey: guid,
30    Description: "Another DE added via SSJS",
31    Fields: [{
32        FieldType: "Text",
33        Name: "ID",
34        MaxLength: 36,
35        IsPrimaryKey: true,
36        IsNillable: false,
37        IsRequired: true
38    },
39    {
40        FieldType: "Text",
41        Name: "Name",
42        MaxLength: 200
43    }],
44    CategoryID: 101377
45}
46var res = prox.createBatch("DataExtension", [ de1, de2 ]);

In both single and batch operations, the results contain three properties: Status, RequestID, and Results. The createItem() method returns one item, and the createBatch() method returns the same number of items that were passed into the method.

1{
2    "Status": "OK",
3    "RequestID": "fb768ddc-6670-4183-8b9d-4f0d5518bb2e",
4    "Results": [...]
5}

Example: Create an Automation Activity 

This example creates an automation activity and includes the Raw SOAP Wrapper which corresponds with the WSProxy call.

1<script runat="server">
2  try {
3    /* Initialize the WSProxy Object */
4    var api = new Script.Util.WSProxy();
5
6    /* Set ClientID */
7    api.setClientId({
8      "ID": Platform.Function.AuthenticatedMemberID(),
9      "UserID": Platform.Function.AuthenticatedEmployeeID()
10    });
11
12    /* Build Query Object */
13    var automation = {
14      "Name": "Example Automation",
15      "CustomerKey": "ExampleAutomation",
16      "Description": "My Automation Example",
17      "AutomationTasks": [
18        {
19          "Name": "Task 1",
20          "Activities": [
21            {
22              "ObjectID": "a582746c-4e38-4552-b810-d6eaeb76ed2d",
23              "Name": "Query 1",
24              "ActivityObject": {
25                "__Type__": "QueryDefinition",
26                "ObjectID": "a582746c-4e38-4552-b810-d6eaeb76ed2d",
27                "Name": "Example Query Activity",
28                "CustomerKey": "ExampleQueryActivity"
29              }
30            }
31          ]
32        }
33      ],
34      "AutomationType": "Scheduled"
35    };
36
37    /* Create via API */
38    var result = api.createItem('Automation', automation);
39    Platform.Response.Write(Platform.Function.Stringify(result));
40  } catch(e) {
41    Platform.Response.Write(Platform.Function.Stringify(e));
42  };
43</script>

The response includes information about the Automation Activity.

1{
2  "Status": "OK",
3  "RequestID": "eb0dccf7-ce17-4f9b-9427-fffc8c4cf034",
4  "Results": [
5    {
6      "NewID": 0,
7      "NewObjectID": "9c825220-6f2f-40f2-95c2-e44909afed87",
8      "PartnerKey": null,
9      "Object": {
10        "Schedule": null,
11        "AutomationTasks": [
12          {
13            "AutomationTaskType": null,
14            "Name": null,
15            "Description": null,
16            "Automation": null,
17            "Sequence": 0,
18            "Activities": [null],
19            "Client": null,
20            "PartnerKey": null,
21            "PartnerProperties": null,
22            "CreatedDate": "0001-01-01T00:00:00.000",
23            "ModifiedDate": null,
24            "ID": 0,
25            "ObjectID": null,
26            "CustomerKey": null,
27            "Owner": null,
28            "CorrelationID": null,
29            "ObjectState": null,
30            "IsPlatformObject": false
31          }
32        ],
33        "IsActive": true,
34        "AutomationSource": null,
35        "Status": 0,
36        "Notifications": null,
37        "ScheduledTime": "0001-01-01T00:00:00.000",
38        "AutomationType": "Scheduled",
39        "UpdateModified": false,
40        "LastRunInstanceID": null,
41        "CreatedBy": 0,
42        "CategoryID": null,
43        "LastRunTime": "0001-01-01T00:00:00.000",
44        "LastSaveDate": "0001-01-01T00:00:00.000",
45        "ModifiedBy": 0,
46        "RecurrenceID": null,
47        "LastSavedBy": 0,
48        "InteractionObjectID": null,
49        "Name": "Example Automation",
50        "Description": "My Automation Example",
51        "Keyword": null,
52        "Client": {
53          "ID": 987654,
54          "ClientID1": 0,
55          "PartnerClientKey": null,
56          "UserID": 998877665,
57          "PartnerUserKey": null,
58          "CreatedBy": 0,
59          "ModifiedBy": 0,
60          "EnterpriseID": 0,
61          "CustomerKey": null,
62          "CustomerID": null
63        },
64        "PartnerKey": null,
65        "PartnerProperties": [{ "Name": "AutomationType", "Value": "Scheduled" }],
66        "CreatedDate": "0001-01-01T00:00:00.000",
67        "ModifiedDate": null,
68        "ID": 0,
69        "ObjectID": "9c825220-6f2f-40f2-95c2-e44909afed87",
70        "CustomerKey": "ExampleAutomation",
71        "Owner": null,
72        "CorrelationID": null,
73        "ObjectState": null,
74        "IsPlatformObject": false
75      },
76      "CreateResults": null,
77      "ParentPropertyName": null,
78      "StatusCode": "OK",
79      "StatusMessage": null,
80      "OrdinalID": 0,
81      "ErrorCode": 0,
82      "RequestID": null,
83      "ConversationID": null,
84      "OverallStatusCode": null,
85      "RequestType": "Synchronous",
86      "ResultType": null,
87      "ResultDetailXML": null
88    }
89  ]
90}