Delete using Batches verified

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

Delete DataExtension records

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

var batches = [
    {
        CustomerKey: "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
        Keys: [
            {
                Name: "SubscriberKey",
                Value: "S0M3-GU1D-K3Y-G03SR1G4T-H3R3"
            }
        ] 
    }
];

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

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

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

	try {

        var batches = [
            {
                CustomerKey: "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
                Keys: [
                    {
                        Name: "SubscriberKey",
                        Value: "S0M3-GU1D-K3Y-G03SR1G4T-H3R3"
                    }
                ] 
            },
            {
                CustomerKey: "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
                Keys: [
                    {
                        Name: "SubscriberKey",
                        Value: "S0M3-GU1D-K3Y-G03SR1G4T-H3R3"
                    }
                ] 
            }
        ];

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

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

</script>
{
    "Status": "OK",
    "RequestID": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
    "Results": [
        {
            "ErrorMessage": null,
            "KeyErrors": null,
            "Object": {
                "CustomerKey": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
                "Properties": null,
                "Name": null,
                "Keys": [
                    {
                        "Name": "SubscriberKey",
                        "Value": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3"
                    }
                ],
                "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
            },
            "StatusCode": "OK",
            "StatusMessage": "Deleted DataExtensionObject",
            "OrdinalID": 0,
            "ErrorCode": 0,
            "RequestID": null,
            "ConversationID": null,
            "OverallStatusCode": null,
            "RequestType": "Synchronous",
            "ResultType": null,
            "ResultDetailXML": null
        },
        {
            "ErrorMessage": null,
            "KeyErrors": null,
            "Object": {
                "CustomerKey": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
                "Properties": null,
                "Name": null,
                "Keys": [
                    {
                        "Name": "SubscriberKey",
                        "Value": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3"
                    }
                ],
                "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
            },
            "StatusCode": "OK",
            "StatusMessage": "Deleted DataExtensionObject",
            "OrdinalID": 1,
            "ErrorCode": 0,
            "RequestID": null,
            "ConversationID": null,
            "OverallStatusCode": null,
            "RequestType": "Synchronous",
            "ResultType": null,
            "ResultDetailXML": null
        }
    ]
}

Help me turn coffee into code

This website is provided to you free of charge. However, a lot of time and effort are spent to write, test and mainain the code. Please consider supporting my work by buying me a cup of coffee.

Last Updated: