Display Salesforce CMS Content
Display CMS Content in Experience Builder Sites
Authenticate a Connected App with CMS
Retrieve CMS Channels with a Connected App
Retrieve CMS Content with a Connected App
Search CMS Content with a Connected App
Use the Connect REST API’s CMS delivery query resource to get CMS content with a connected app. If the request is successful, the response contains a JSON object with the selected content.
To form the API request, you need these items.
To send an API call to retrieve CMS content, make an HTTP GET request to the /services/data/v{XX.X}/connect/cms/delivery/channels/{channelId}/contents/query resource. Append the managedContentType request parameter, and set its value to the CMS content type.
For example, this sample URL selects content with the content type named “Promotion” from the channel with an ID of 0ap5w000000kcaiAAA.
1https://{MyDomainLoginUrl}/services/data/v{XX.X}/connect/cms/delivery/channels/0ap5w000000kcaiAAA/contents
2/query?managedContentType=PromotionInclude an Authorization header with the value Bearer {access_token}, where access_token is your CMS access token. Optionally, specify the response format with a Content-Type header.
This Node.js sample requests CMS content from the channel ID stored in the config.channelId variable, of the content type from the variable type.
1```javascript
2const auth = require("../sf-crm-auth");
3
4const fetch = require("node-fetch");
5
6const config = require("../sf-crm-config")();
7
8module.exports = async function (type) {
9 if (type) {
10 const content = await getContentList(type);
11
12 return content;
13 }
14};
15
16async function getContentList(type) {
17 return new Promise((resolve, reject) => {
18 auth().then((token) => {
19 const meta = {
20 "Content-Type": "application/json",
21 Authorization: `Bearer ${token.access_token}`,
22 };
23
24 const urlToUse = `${token.instance_url}/services/data/v54.0/connect/cms/delivery/channels/${config.channelId}/contents
25/query?managedContentType=${type}&pageSize=250`;
26
27 fetch(urlToUse, {
28 method: "GET",
29 headers: meta,
30 })
31 .then((res) => res.json())
32 .then((json) => resolve(json))
33 .catch((err) => {
34 console.log({ err });
35 reject(err);
36 });
37 });
38 });
39}
40```In response to the API request, the API returns an HTTP response code and a JSON body with an object containing all the selected content and pagination details.
This sample shows the response body from the previous sample request to retrieve content.
1{
2 "currentPageUrl": "/services/data/v54.0/connect/cms/delivery/channels/0ap5w000000kcai/contents
3/query?managedContentType=Promotion&page=0&pageSize=25",
4 "items": [
5 {
6 "contentNodes": {
7 "Banner Alternative Text": {
8 "nodeType": "Text",
9 "value": "Sign up for a free pair of shoes."
10 },
11 "Second Image Alternative Text": {
12 "nodeType": "Text",
13 "value": "Footwear to get you running."
14 },
15 "callToActionUrl": {
16 "nodeType": "Url",
17 "value": "https://salesforcecms.herokuapp.com/promotions/"
18 },
19 "Start Date": {
20 "nodeType": "Date",
21 "value": "2020-05-08T00:00:00.000Z"
22 },
23 "detailText": {
24 "nodeType": "RichText",
25 "value": "<p>Our mission is to see our world in motion. Let's get up and moving together. Northern Trail Outfitters will be giving out a free pair of our extraordinary shoes. Sign up to be eligible!</p>"
26 },
27 "End Date": {
28 "nodeType": "Date",
29 "value": "2020-06-26T00:00:00.000Z"
30 },
31 "Second Image": {
32 "altText": "Footwear Promotion Image 2",
33 "altUrl": null,
34 "fileName": "Footwear_Promotion_Image_2.png",
35 "mediaType": "Image",
36 "mimeType": "PNG",
37 "nodeType": "Media",
38 "resourceUrl": "/services/data/v54.0/connect/file-assets/Footwear_Promotion_Image_2/content",
39 "title": null,
40 "unauthenticatedUrl": null,
41 "url": "/file-asset/Footwear_Promotion_Image_2"
42 },
43 "callToActionText": {
44 "nodeType": "Text",
45 "value": "Get My Free Shoes!"
46 },
47 "Title": {
48 "nodeType": "NameField",
49 "value": "NTO Footwear Promotion - Free Shoes"
50 },
51 "Banner Image": {
52 "altText": "FootwearPromotionMainImage",
53 "altUrl": null,
54 "fileName": "FootwearPromotionMainImage.png",
55 "mediaType": "Image",
56 "mimeType": "PNG",
57 "nodeType": "Media",
58 "resourceUrl": "/services/data/v54.0/connect/file-assets/FootwearPromotionMainImage/content",
59 "title": null,
60 "unauthenticatedUrl": null,
61 "url": "/file-asset/FootwearPromotionMainImage"
62 }
63 },
64 "contentUrlName": "nto-footwear-promotion-free-shoes",
65 "language": "en_US",
66 "managedContentId": "20Y5w000000Li8wEAC",
67 "publishedDate": "2020-05-22T14:39:32.000Z",
68 "title": "NTO Footwear Promotion - Free Shoes",
69 "type": "Promotion",
70 "typeLabel": "Promotion"
71 }
72 ],
73 "total": 1
74}