Use the Connect REST API’s CMS delivery search resource to retrieve CMS content that matches a text search with a connected app. If the request is successful, the response contains a JSON object with the selected content.
Before You Begin
To form the API request, you need these items.
- A CMS access token
- A CMS channel ID that has access to the content
API Request Details
To send an API call to get CMS content, make an HTTP GET request to the /services/data/v{XX.X}/connect/cms/delivery/channels/{channelId}/contents/search resource. Append the queryTerm request parameter, and set its value to the term you want to search for.
For example, this sample URL selects content with the term “fish” from the channel with an ID of 0ap5w000000kcaiAAA.
https://{MyDomainLoginUrl}/services/data/v{XX.X}/connect/cms/delivery/channels/0ap5w000000kcaiAAA/contents
/search?queryTerm=fish
Headers
Include 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.
Sample Request
This Node.js sample requests CMS content from the channel ID stored in the config.channelId variable and limits the results to content that contains the text stored in the searchTerm variable.
```javascript
const auth = require("./sf-crm-auth");
const fetch = require("node-fetch");
const config = require("./sf-crm-config")();
module.exports = async function (searchTerm) {
if (searchTerm) {
const content = await searchContent(searchTerm);
return content.items;
}
};
async function searchContent(searchTerm) {
if (searchTerm) {
return new Promise((resolve, reject) => {
auth().then((token) => {
const meta = {
"Content-Type": "application/json",
Authorization: `Bearer ${token.access_token}`,
};
const urlToUse = `${token.instance_url}/services/data/v54.0/connect/cms/delivery/channels/${config.channelId}/contents
/search?queryTerm=${searchTerm}`;
fetch(urlToUse, {
method: "GET",
headers: meta,
})
.then((res) => res.json())
.then((json) => resolve(json))
.catch((err) => {
console.log({ err });
reject(err);
});
});
});
}
}
```
API Response
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 from the previous sample request to retrieve content that contains the word “fish”.
{
"count": 1,
"currentPageUri": "/services/data/v54.0/connect/cms/delivery/channels/0ap5w000000kcaiAAA/contents
/search?page=0&pageSize=25&queryTerm=fish&scope=All",
"items": [
{
"contentType": {
"developerName": "externalVideo",
"label": "Video (External)"
},
"id": "20Y5w000000cEWOEA2",
"publishDate": "2020-05-22T17:48:53.000Z",
"title": "Lakeside Fishing - It's Totally Worth It!",
"urlName": "lakeside-fishing-video"
}
],
"nextPageUri": null
}