Search CMS Content with a Connected App

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.

1https://{MyDomainLoginUrl}/services/data/v{XX.X}/connect/cms/delivery/channels/0ap5w000000kcaiAAA/contents
2/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.

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 (searchTerm) {
9  if (searchTerm) {
10    const content = await searchContent(searchTerm);
11
12    return content.items;
13  }
14};
15
16async function searchContent(searchTerm) {
17  if (searchTerm) {
18    return new Promise((resolve, reject) => {
19      auth().then((token) => {
20        const meta = {
21          "Content-Type": "application/json",
22          Authorization: `Bearer ${token.access_token}`,
23        };
24
25        const urlToUse = `${token.instance_url}/services/data/v54.0/connect/cms/delivery/channels/${config.channelId}/contents
26/search?queryTerm=${searchTerm}`;
27
28        fetch(urlToUse, {
29          method: "GET",
30          headers: meta,
31        })
32          .then((res) => res.json())
33          .then((json) => resolve(json))
34          .catch((err) => {
35            console.log({ err });
36            reject(err);
37          });
38      });
39    });
40  }
41}
42```

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”.

1{
2    "count": 1,
3    "currentPageUri": "/services/data/v54.0/connect/cms/delivery/channels/0ap5w000000kcaiAAA/contents
4/search?page=0&pageSize=25&queryTerm=fish&scope=All",
5    "items": [
6        {
7            "contentType": {
8                "developerName": "externalVideo",
9                "label": "Video (External)"
10            },
11            "id": "20Y5w000000cEWOEA2",
12            "publishDate": "2020-05-22T17:48:53.000Z",
13            "title": "Lakeside Fishing - It's Totally Worth It!",
14            "urlName": "lakeside-fishing-video"
15        }
16    ],
17    "nextPageUri": null
18}

See Also