verified
Update an AssetLearn how to update an asset from Content Builder in Salesforce Marketing Cloud (SFMC) with SSJS (server-side JavaScript). Code snippets include REST API methods.
Asset update
var id = "123456"
var payload = {
name: "My HTML Email",
channels: {
email: true,
web: false
},
views: {
html: {
content: "<h1>Updated World</h1>"
},
text: {},
subjectline: {
content: "Hello, this is my updated subject line"
},
preheader: {
content: "and this is my updated preheader"
}
},
assetType: {
name: "htmlemail",
id: 208
}
};
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 = "PATCH";
request.contentType = "application/json";
request.postData = Stringify(payload);
var results = request.send();
var result = Platform.Function.ParseJSON(String(results.content));
<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 payload = {
name: "My HTML Email",
channels: {
email: true,
web: false
},
views: {
html: {
content: "<h1>Updated World</h1>"
},
text: {},
subjectline: {
content: "Hello, this is my updated subject line"
},
preheader: {
content: "and this is my updated preheader"
}
},
assetType: {
name: "htmlemail",
id: 208
}
};
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 = "PATCH";
request.contentType = "application/json";
request.postData = Stringify(payload);
var results = request.send();
var result = Platform.Function.ParseJSON(String(results.content));
Write(Stringify(result));
} catch(error) {
Write(Stringify(error));
}
</script>
{
"id": 123456,
"customerKey": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
"objectID": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
"contentType": "application/vnd.etmc.email.Message; kind=paste",
"assetType": {
"id": 208,
"name": "htmlemail",
"displayName": "HTML Email"
},
"name": "My HTML Email",
"owner": {
"id": 987654321,
"email": "",
"name": "Integration app user",
"userId": "987654321"
},
"createdDate": "2023-09-01T09:05:20.937-06:00",
"createdBy": {
"id": 987654321,
"email": "",
"name": "Integration app user",
"userId": "987654321"
},
"modifiedDate": "2023-09-01T10:21:12.027-06:00",
"modifiedBy": {
"id": 987654321,
"name": "Integration app user",
"userId": "987654321"
},
"enterpriseId": 987654321,
"memberId": 987654321,
"status": {
"id": 1,
"name": "Draft"
},
"thumbnail": {},
"category": {
"id": 112233,
"name": "Content Builder",
"parentId": 0
},
"views": {
"html": {
"thumbnail": {},
"content": "<h1>Updated World</h1>",
"availableViews": [],
"data": {
"email": {
"options": {
"generateFrom": null
}
}
},
"modelVersion": 2
},
"text": {
"thumbnail": {},
"availableViews": [],
"data": {
"email": {
"options": {
"generateFrom": null
}
}
},
"modelVersion": 2
},
"subjectline": {
"thumbnail": {},
"content": "Hello, this is my updated subject line",
"availableViews": [],
"data": {
"email": {
"options": {
"generateFrom": null
}
}
},
"modelVersion": 2
},
"preheader": {
"thumbnail": {},
"content": "and this is my updated preheader",
"availableViews": [],
"data": {
"email": {
"options": {
"generateFrom": null
}
}
},
"modelVersion": 2
}
},
"availableViews": [
"html",
"text",
"subjectline",
"preheader"
],
"channels": {
"email": true,
"web": false
},
"data": {
"email": {
"options": {
"characterEncoding": "us-ascii"
},
"legacy": {
"legacyId": 1234567,
"legacyKey": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
"legacyType": "email",
"legacyCategoryId": 3136
}
}
},
"legacyData": {
"legacyId": 1234567,
"legacyKey": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
"legacyType": "email",
"legacyCategoryId": 3136
},
"modelVersion": 2
}
Category update
var id = 123456;
var payload = {
Id: 123456,
Name: "Updated Folder Name",
ParentId: 78912345,
CategoryType: "asset"
};
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 = "PUT";
request.contentType = "application/json";
request.postData = Stringify(payload);
var results = request.send();
var result = Platform.Function.ParseJSON(String(results.content));
<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 payload = {
Id: 123456,
Name: "Updated Folder Name",
ParentId: 78912345,
CategoryType: "asset"
};
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 = "PUT";
request.contentType = "application/json";
request.postData = Stringify(payload);
var results = request.send();
var result = Platform.Function.ParseJSON(String(results.content));
Write(Stringify(result));
} catch(error) {
Write(Stringify(error));
}
</script>
{
"id": 123456,
"description": "",
"enterpriseId": 987654321,
"memberId": 987654321,
"name": "Updated Folder Name",
"parentId": 78912345,
"categoryType": "asset"
}
WARNING
Please use PUT instead of PATCH for updating a category (folder).
Reference
Ressources and references related to the current methods.
Official documentation