Creating a Data Extension Folder via API

The AMPscript code below allows you to use the InvokeCreate function and the CreateObject function to create a data extension folder.

Use Case: A lot what can be performed in the front end of the user interface in Salesforce Marketing Cloud, can also be performed via API. In the case where you will need to create multiple folders quickly or being able to have consistency across different business units, the API call can be made to create these folders so that they are identical across instances.

Example:



%%[
/* create folder using CreateObject */

Set @df = CreateObject(“DataFolder”)
SetObjectProperty(@df,”Name”,”AMPscript_dot_com”)
SetObjectProperty(@df,”Description”,”Files associated with test”)
SetObjectProperty(@df,”ContentType”,”DataExtension”)
SetObjectProperty(@df,”IsActive”,1)
SetObjectProperty(@df,”IsEditable”,1)
SetObjectProperty(@df,”AllowChildren”,1)

Set @pf = CreateObject(“DataFolder”)
SetObjectProperty(@pf,”ID”, 375217)

SetObjectProperty(@df,”ParentFolder”,@pf)
Set @StatCode = InvokeCreate(@df, @statusMsg, @errorCode)
]%%


statusCode: %%=v(@statusCode)=%%
statusMsg: %%=v(@statusMsg)=%%
errorCode: %%=v(@errorCode)=%%

Output:

statusCode:
statusMsg: Folder created sucessfully
errorCode: 0

Explanation:

Note that you will need to define the parent folder for where this folder is to be created. That is designated in the@pf variable ID of “375217” in this example. To get the ID of a folder, you can hover over the folder in the Salesforce Marketing Cloud user interface and it will show this:

javascript:getTopWindow().launchContent({ content: 'de-grid', object: 'dataextension', categoryID: '375217'});

The categoryID is the value you’ll need to use to define the Parent Folder.

Leave a Reply

Your email address will not be published. Required fields are marked *