Create a Data Extension folder verified

Learn how to create a Folder in Salesforce Marketing Cloud (SFMC) with SSJS (server-side JavaScript). Code snippets include WSProxy and Core methods.

Core

var de = Folder.Retrieve({
    Property: "ContentType",
    SimpleOperator: "equals",
    Value: "dataextension"
});

var parentFolderID = de[0].ID;

var config = {
    Name: "MyNewFolder",
    CustomerKey: GUID(),
    Description: "API Created Folder",
    ContentType: "dataextension",
    IsActive: "true",
    IsEditable: "true",
    AllowChildren: "true",
    ParentFolderID: parentFolderID
}

var result = Folder.Add(config);
<script runat="server">

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

	try {

        var de = Folder.Retrieve({
            Property: "ContentType",
            SimpleOperator: "equals",
            Value: "dataextension"
        });

        var parentFolderID = de[0].ID;

        var config = {
            Name: "MyNewFolder",
            CustomerKey: GUID(),
            Description: "API Created Folder",
            ContentType: "dataextension",
            IsActive: "true",
            IsEditable: "true",
            AllowChildren: "true",
            ParentFolderID: parentFolderID
        }

        var result = Folder.Add(config);

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

</script>
"OK"

WSProxy

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

var parentFolderId = req.Results[0].ID;

var config = {
    "Name": "MyNewFolder",
    "Description": "API Created Folder",
    "ParentFolder": {
        ID : parentFolderId,
        IDSpecified: true
    },
    "IsActive": true,
    "IsEditable": true,
    "AllowChildren": true,
    "ContentType": "dataextension"
};

var result = api.createItem("DataFolder", config); 
<script runat="server">

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

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

	try {

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

        var parentFolderId = req.Results[0].ID;

        var config = {
            "Name": "MyNewFolder",
            "Description": "API Created Folder",
            "ParentFolder": {
                ID : parentFolderId,
                IDSpecified: true
            },
            "IsActive": true,
            "IsEditable": true,
            "AllowChildren": true,
            "ContentType": "dataextension"
        };

        var result = api.createItem("DataFolder", config); 

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

</script>
{
    "Status": "OK",
    "RequestID": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
    "Results": [
        {
            "NewID": 390808,
            "NewObjectID": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
            "PartnerKey": null,
            "Object": null,
            "CreateResults": null,
            "ParentPropertyName": null,
            "StatusCode": "OK",
            "StatusMessage": "Folder created successfully.",
            "OrdinalID": 0,
            "ErrorCode": 0,
            "RequestID": null,
            "ConversationID": null,
            "OverallStatusCode": null,
            "RequestType": "Synchronous",
            "ResultType": null,
            "ResultDetailXML": null
        }
    ]
}

Reference

Ressources and references related to the current methods.

Official documentation
SOAP object

Last Updated: