Delete a Data Extension verified

Learn how to delete a Data Extension in Salesforce Marketing Cloud (SFMC) with SSJS (server-side JavaScript). Code snippets include the WSProxy method.

WSProxy

var customerKey = "S0M3-GU1D-K3Y-G03SR1G4T-H3R3";

var req = api.retrieve("DataExtension", ["ObjectID"], {
    Property: "DataExtension.CustomerKey",
    SimpleOperator: "equals",
    Value: customerKey
});

var objectId = req.Results[0].ObjectID;

var result = api.deleteItem("DataExtension", { 
    "ObjectID": objectId 
});
<script runat="server">

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

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

	try {

        var customerKey = "S0M3-GU1D-K3Y-G03SR1G4T-H3R3";

        var req = api.retrieve("DataExtension", ["ObjectID"], {
            Property: "DataExtension.CustomerKey",
            SimpleOperator: "equals",
            Value: customerKey
        });

        var objectId = req.Results[0].ObjectID;

        var result = api.deleteItem("DataExtension", { 
            "ObjectID": objectId 
        });

        Write(Stringify(result));

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

</script>
{
    "Status": "OK",
    "RequestID": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
    "Results": [
        {
            "Object": {
                "CustomerKey": null,
                "Name": null,
                "Description": null,
                "IsSendable": false,
                "IsTestable": false,
                "SendableDataExtensionField": null,
                "SendableSubscriberField": null,
                "Template": null,
                "DataRetentionPeriodLength": 0,
                "DataRetentionPeriodUnitOfMeasure": 0,
                "RowBasedRetention": false,
                "ResetRetentionPeriodOnImport": false,
                "DeleteAtEndOfRetentionPeriod": false,
                "RetainUntil": null,
                "Fields": null,
                "DataRetentionPeriod": "Days",
                "CategoryID": 0,
                "Status": null,
                "Client": null,
                "PartnerKey": null,
                "PartnerProperties": null,
                "CreatedDate": "0001-01-01T00:00:00.000",
                "ModifiedDate": null,
                "ID": 0,
                "ObjectID": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
                "Owner": null,
                "CorrelationID": null,
                "ObjectState": null,
                "IsPlatformObject": false
            },
            "StatusCode": "OK",
            "StatusMessage": "Data Extension deleted.",
            "OrdinalID": 0,
            "ErrorCode": 0,
            "RequestID": null,
            "ConversationID": null,
            "OverallStatusCode": null,
            "RequestType": "Synchronous",
            "ResultType": null,
            "ResultDetailXML": null
        }
    ]
}

WARNING

ObjectID is required in order to delete a Data Extension.

Reference

Ressources and references related to the current methods.

Official documentation
SOAP object

Last Updated: