Create using Batches verified

Learn how to create using batches (createBatch) in Salesforce Marketing Cloud (SFMC) with SSJS (server-side JavaScript). Code snippets include WSProxy methods.

Create DataExtension records

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

var batches = [
    {
        CustomerKey: "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
        Properties: [
            {
                Name: "SubscriberKey",
                Value: GUID()
            },
            {
                Name: "EmailAddress",
                Value: "example@mail.com"
            }
        ]
    }
]

var result = api.createBatch("DataExtensionObject", batches);
<script runat="server">

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

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

	try {

        var batches = [
            {
                CustomerKey: "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
                Properties: [
                    {
                        Name: "SubscriberKey",
                        Value: GUID()
                    },
                    {
                        Name: "EmailAddress",
                        Value: "example1@mail.com"
                    }
                ]
            },
            {
                CustomerKey: "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
                Properties: [
                    {
                        Name: "SubscriberKey",
                        Value: GUID()
                    },
                    {
                        Name: "EmailAddress",
                        Value: "example2@mail.com"
                    }
                ]
            }
        ]

        var result = api.createBatch("DataExtensionObject", batches);

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

</script>
{
    "Status": "OK",
    "RequestID": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
    "Results": [
        {
            "ErrorMessage": null,
            "KeyErrors": null,
            "ValueErrors": null,
            "NewID": 0,
            "NewObjectID": null,
            "PartnerKey": null,
            "Object": {
                "Name": null,
                "Keys": null,
                "Type": null,
                "Properties": [
                    {
                        "Name": "SubscriberKey",
                        "Value": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3"
                    },
                    {
                        "Name": "EmailAddress",
                        "Value": "example1@mail.com"
                    }
                ],
                "Client": null,
                "PartnerKey": null,
                "PartnerProperties": null,
                "CreatedDate": "0001-01-01T00:00:00.000",
                "ModifiedDate": null,
                "ID": 0,
                "ObjectID": null,
                "CustomerKey": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
                "Owner": null,
                "CorrelationID": null,
                "ObjectState": null,
                "IsPlatformObject": false
            },
            "CreateResults": null,
            "ParentPropertyName": null,
            "StatusCode": "OK",
            "StatusMessage": "Created DataExtensionObject",
            "OrdinalID": 0,
            "ErrorCode": 0,
            "RequestID": null,
            "ConversationID": null,
            "OverallStatusCode": null,
            "RequestType": "Synchronous",
            "ResultType": null,
            "ResultDetailXML": null
        },
        {
            "ErrorMessage": null,
            "KeyErrors": null,
            "ValueErrors": null,
            "NewID": 0,
            "NewObjectID": null,
            "PartnerKey": null,
            "Object": {
                "CustomerKey": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
                "Properties": [
                    {
                        "Name": "SubscriberKey",
                        "Value": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3"
                    },
                    {
                        "Name": "EmailAddress",
                        "Value": "example2@mail.com"
                    }
                ],
                "Name": null,
                "Keys": null,
                "Type": null,
                "Client": null,
                "PartnerKey": null,
                "PartnerProperties": null,
                "CreatedDate": "0001-01-01T00:00:00.000",
                "ModifiedDate": null,
                "ID": 0,
                "ObjectID": null,
                "Owner": null,
                "CorrelationID": null,
                "ObjectState": null,
                "IsPlatformObject": false
            },
            "CreateResults": null,
            "ParentPropertyName": null,
            "StatusCode": "OK",
            "StatusMessage": "Created DataExtensionObject",
            "OrdinalID": 1,
            "ErrorCode": 0,
            "RequestID": null,
            "ConversationID": null,
            "OverallStatusCode": null,
            "RequestType": "Synchronous",
            "ResultType": null,
            "ResultDetailXML": null
        }
    ]
}
{
    "Status": "Has Errors",
    "RequestID": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
    "Results": [
        {
            "ErrorMessage": null,
            "KeyErrors": null,
            "ValueErrors": null,
            "NewID": 0,
            "NewObjectID": null,
            "PartnerKey": null,
            "Object": {
                "Name": null,
                "Keys": null,
                "Type": null,
                "Properties": [
                    {
                        "Name": "SubscriberKey",
                        "Value": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3"
                    },
                    {
                        "Name": "EmailAddress",
                        "Value": "example1@mail.com"
                    }
                ],
                "Client": null,
                "PartnerKey": null,
                "PartnerProperties": null,
                "CreatedDate": "0001-01-01T00:00:00.000",
                "ModifiedDate": null,
                "ID": 0,
                "ObjectID": null,
                "CustomerKey": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
                "Owner": null,
                "CorrelationID": null,
                "ObjectState": null,
                "IsPlatformObject": false
            },
            "CreateResults": null,
            "ParentPropertyName": null,
            "StatusCode": "OK",
            "StatusMessage": "Created DataExtensionObject",
            "OrdinalID": 0,
            "ErrorCode": 0,
            "RequestID": null,
            "ConversationID": null,
            "OverallStatusCode": null,
            "RequestType": "Synchronous",
            "ResultType": null,
            "ResultDetailXML": null
        },
        {
            "ErrorMessage": "",
            "KeyErrors": null,
            "ValueErrors": [
                null
            ],
            "NewID": 0,
            "NewObjectID": null,
            "PartnerKey": null,
            "Object": {
                "CustomerKey": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
                "Properties": [
                    {
                        "Name": "SubscriberKey",
                        "Value": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3"
                    },
                    {
                        "Name": "EmailAddress",
                        "Value": "example2"
                    }
                ],
                "Name": null,
                "Keys": null,
                "Type": null,
                "Client": null,
                "PartnerKey": null,
                "PartnerProperties": null,
                "CreatedDate": "0001-01-01T00:00:00.000",
                "ModifiedDate": null,
                "ID": 0,
                "ObjectID": null,
                "Owner": null,
                "CorrelationID": null,
                "ObjectState": null,
                "IsPlatformObject": false
            },
            "CreateResults": null,
            "ParentPropertyName": null,
            "StatusCode": "Error",
            "StatusMessage": "Errors occurred",
            "OrdinalID": 1,
            "ErrorCode": 2,
            "RequestID": null,
            "ConversationID": null,
            "OverallStatusCode": null,
            "RequestType": "Synchronous",
            "ResultType": null,
            "ResultDetailXML": null
        }
    ]
}

Last Updated: