verified
Retrieve a CloudPageLearn how to retrieve a CloudPage in Salesforce Marketing Cloud (SFMC) with SSJS (server-side JavaScript). Code snippets include REST API methods.
Table of contents
Retrieve content from Content Builder
Works for the content of Landing pages built with the Content Builder editor (Prior to 2024, it was possible to choose between Content Builder and Classic editors).
var payload = {
"page": {
"pageSize": 50,
"page": 1
},
"query": {
"leftOperand": {
"property": "name",
"simpleOperator": "equals",
"value": "MyCloudPage"
},
"logicalOperator": "AND",
"rightOperand": {
"property": "assetType.id",
"simpleOperator": "equals",
"value": 205
}
},
"fields": [
"id",
"customerKey",
"objectID",
"assetType",
"name",
"owner",
"content",
"createdDate",
"createdBy",
"modifiedDate",
"modifiedBy",
"thumbnail",
"category",
"views"
],
"sort": [
{
"property": "modifiedDate",
"direction": "DESC"
}
]
}
var endpoint = restInstanceUrl + "asset/v1/content/assets/query";
var request = HTTP.Post(endpoint, "application/json", Stringify(payload), ["Authorization"], ["Bearer " + accessToken]);
var result = Platform.Function.ParseJSON(String(request.Response));
<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 payload = {
"page": {
"pageSize": 50,
"page": 1
},
"query": {
"leftOperand": {
"property": "name",
"simpleOperator": "equals",
"value": "MyCloudPage"
},
"logicalOperator": "AND",
"rightOperand": {
"property": "assetType.id",
"simpleOperator": "equals",
"value": 205
}
},
"fields": [
"id",
"customerKey",
"objectID",
"assetType",
"name",
"owner",
"content",
"createdDate",
"createdBy",
"modifiedDate",
"modifiedBy",
"thumbnail",
"category",
"views"
],
"sort": [
{
"property": "modifiedDate",
"direction": "DESC"
}
]
}
var endpoint = restInstanceUrl + "asset/v1/content/assets/query";
var request = new Script.Util.HttpRequest(endpoint);
request.emptyContentHandling = 0;
request.retries = 2;
request.continueOnError = true;
request.setHeader("Authorization", "Bearer " + accessToken);
request.method = "POST";
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>
{
"count": 1,
"page": 1,
"pageSize": 50,
"links": {},
"items": [
{
"id": 1234567,
"customerKey": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
"objectID": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
"assetType": {
"id": 205,
"name": "webpage",
"displayName": "Web Page"
},
"name": "MyCloudPage",
"owner": {
"id": 123,
"email": "example@mail.com",
"name": "John Doe",
"userId": "123"
},
"createdDate": "2024-03-22T01:24:50.567-06:00",
"createdBy": {
"id": 123,
"email": "example@mail.com",
"name": "John Doe",
"userId": "123"
},
"modifiedDate": "2024-03-28T00:11:30.06-06:00",
"modifiedBy": {
"id": 123,
"email": "example@mail.com",
"name": "John Doe",
"userId": "123"
},
"thumbnail": {
"thumbnailUrl": "/v1/assets/1234567/thumbnail"
},
"category": {
"id": 3134,
"name": "Content Builder",
"parentId": 0
},
"views": {
"html": {
"thumbnail": {},
"content": "<!DOCTYPE html><html><head></head><body></body></html>",
"meta": {},
"slots": {
"col1": {
"design": "<p style=\"font-family:arial;color:#ccc;font-size:11px;text-align:center;vertical-align:middle;font-weight:bold;padding:10px;margin:0;border:#ccc dashed 1px;\">Drop blocks or content here</p>",
"modelVersion": 2
}
},
"modelVersion": 2
}
},
"modelVersion": 2
}
]
}
Retrieve content and meta data from Web Studio
As of Spring 2024, it's possible to retrieve the category, URL and publish date for all CloudPages. Unfortunately, retrieving content works only for Resource pages.
var payload = {
"page": {
"pageSize": 50,
"page": 1
},
"query": {
"leftOperand": {
"property": "name",
"simpleOperator": "equals",
"value": "MyCloudPage"
},
"logicalOperator": "AND",
"rightOperand": {
"property": "assetType.id",
"simpleOperator": "in",
"values": [240, 241, 242, 243, 244, 245, 247, 248, 249]
}
},
"fields": [
"id",
"customerKey",
"objectID",
"assetType",
"name",
"owner",
"content",
"createdDate",
"createdBy",
"modifiedDate",
"modifiedBy",
"thumbnail",
"category",
"meta"
],
"sort": [
{
"property": "modifiedDate",
"direction": "DESC"
}
]
}
var endpoint = restInstanceUrl + "asset/v1/content/assets/query";
var request = HTTP.Post(endpoint, "application/json", Stringify(payload), ["Authorization"], ["Bearer " + accessToken]);
var result = Platform.Function.ParseJSON(String(request.Response));
<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 payload = {
"page": {
"pageSize": 50,
"page": 1
},
"query": {
"leftOperand": {
"property": "name",
"simpleOperator": "equals",
"value": "MyCloudPage"
},
"logicalOperator": "AND",
"rightOperand": {
"property": "assetType.id",
"simpleOperator": "in",
"values": [240, 241, 242, 243, 244, 245, 247, 248, 249]
}
},
"fields": [
"id",
"customerKey",
"objectID",
"assetType",
"name",
"owner",
"content",
"createdDate",
"createdBy",
"modifiedDate",
"modifiedBy",
"thumbnail",
"category",
"meta"
],
"sort": [
{
"property": "modifiedDate",
"direction": "DESC"
}
]
}
var endpoint = restInstanceUrl + "asset/v1/content/assets/query";
var request = new Script.Util.HttpRequest(endpoint);
request.emptyContentHandling = 0;
request.retries = 2;
request.continueOnError = true;
request.setHeader("Authorization", "Bearer " + accessToken);
request.method = "POST";
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>
{
"count": 1,
"page": 1,
"pageSize": 50,
"links": {},
"items": [
{
"id": 1234567,
"customerKey": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
"objectID": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
"assetType": {
"id": 247,
"name": "landingpage",
"displayName": "Landing Page"
},
"name": "MyCloudPage",
"owner": {
"id": 123,
"email": "example@mail.com",
"name": "John Doe",
"userId": "123"
},
"createdDate": "2024-06-15 12:15:00.000",
"createdBy": {
"id": 123,
"email": "example@mail.com",
"name": "John Doe",
"userId": "123"
},
"modifiedDate": "2024-06-15 12:15:00.000",
"modifiedBy": {
"id": 123,
"email": "example@mail.com",
"name": "John Doe",
"userId": "123"
},
"enterpriseId": 100000000,
"memberId": 100000000,
"status": {
"id": 1,
"name": "Draft"
},
"thumbnail": {
"thumbnailUrl": "/v1/assets/56789/thumbnail"
},
"category": {
"id": 123456,
"name": "MyCollection",
"parentId": 7890
},
"content": "{\"url\":\"https://mydomain.com/mycloudpage\"}",
"meta": {
"cloudPages": {
"publishDate": "2024-06-15 12:15:00.000"
}
},
"modelVersion": 2
}
]
}
WARNING
In order to retrieve the URL from the content field, please republish the CloudPages that were created before the Spring 2024 release.
Asset types
AssetTypeID | Name | Description |
---|---|---|
205 | webpage | Web page |
239 | coderesource | Code Resource |
240 | jscoderesource | Javascript Code Resource |
241 | csscoderesource | CSS Code Resource |
242 | jsoncoderesource | JSON Code Resource |
243 | rsscoderesource | RSS Code Resource |
244 | textcoderesource | Text Code Resource |
245 | xmlcoderesource | XML Code Resource |
246 | cloudpages | CloudPages |
247 | landingpage | Landing Page |
248 | microsite | Microsite |
249 | interactivecontent | Interactive Email Page |