Delete a DataExtension folder verified

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

WSProxy

var api = new Script.Util.WSProxy();
	
var req = api.retrieve("DataFolder", ["Name", "ObjectID"], {
    Property: "Name",
    SimpleOperator: "equals",
    Value: "MyFolder"
});

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

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

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

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

	try {

        var req = api.retrieve("DataFolder", ["Name", "ObjectID"], {
            Property: "Name",
            SimpleOperator: "equals",
            Value: "MyFolder"
        });

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

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

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

</script>
{
    "Status": "OK",
    "RequestID": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
    "Results": [
        {
            "Object": null,
            "StatusCode": "OK",
            "StatusMessage": "Folder deleted successfully.",
            "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
List of folder types

Last Updated: