verified
Delete an AssetLearn how to delete an asset from Content Builder in Salesforce Marketing Cloud (SFMC) with SSJS (server-side JavaScript). Code snippets include REST API methods.
Delete asset by Id
var id = "123456";
var endpoint = restInstanceUrl + "asset/v1/content/assets/" + id;
var request = new Script.Util.HttpRequest(endpoint);
request.emptyContentHandling = 0;
request.retries = 2;
request.continueOnError = true;
request.setHeader("Authorization", "Bearer " + accessToken);
request.method = "DELETE";
request.contentType = "application/json";
var results = request.send();
var result = results.statusCode;
<script runat="server">
Platform.Load("core", "1");
var api = new Script.Util.WSProxy();
var restInstanceUrl = "https://YOUR_SUBDOMAIN.rest.marketingcloudapis.com/",
accessToken = "YOUR_REST_API_TOKEN";
try {
var id = "123456";
var endpoint = restInstanceUrl + "asset/v1/content/assets/" + id;
var request = new Script.Util.HttpRequest(endpoint);
request.emptyContentHandling = 0;
request.retries = 2;
request.continueOnError = true;
request.setHeader("Authorization", "Bearer " + accessToken);
request.method = "DELETE";
request.contentType = "application/json";
var results = request.send();
var result = results.statusCode;
Write(Stringify(result));
} catch(error) {
Write(Stringify(error));
}
</script>
200
DANGER
Deleting an asset removes it permanently from the Content Builder. In order to move the asset to the Recycle Bin, please use archiving instead.
Delete category (folder) by Id
var id = "123456";
var endpoint = restInstanceUrl + "asset/v1/content/categories/" + id;
var request = new Script.Util.HttpRequest(endpoint);
request.emptyContentHandling = 0;
request.retries = 2;
request.continueOnError = true;
request.setHeader("Authorization", "Bearer " + accessToken);
request.method = "DELETE";
request.contentType = "application/json";
var results = request.send();
var result = results.statusCode;
<script runat="server">
Platform.Load("core", "1");
var api = new Script.Util.WSProxy();
var restInstanceUrl = "https://YOUR_SUBDOMAIN.rest.marketingcloudapis.com/",
accessToken = "YOUR_REST_API_TOKEN";
try {
var id = "123456";
var endpoint = restInstanceUrl + "asset/v1/content/categories/" + id;
var request = new Script.Util.HttpRequest(endpoint);
request.emptyContentHandling = 0;
request.retries = 2;
request.continueOnError = true;
request.setHeader("Authorization", "Bearer " + accessToken);
request.method = "DELETE";
request.contentType = "application/json";
var results = request.send();
var result = results.statusCode;
Write(Stringify(result));
} catch(error) {
Write(Stringify(error));
}
</script>
200
Reference
Ressources and references related to the current methods.
Official documentation