Display Salesforce CMS Content
Display CMS Content in Experience Builder Sites
Add Text CMS Content to Marketing Cloud
Add Image CMS Content to Marketing Cloud
Use the Marketing Cloud API’s content assets resource to add text CMS content to Marketing Cloud in a connected app. If the request is successful, the content is then available in Content Builder.
To form the API request, you need these items.
To send an API call to add text CMS content to Marketing Cloud, make an HTTP POST request to the /asset/v1/content/assets resource.
Include an Authorization header with the value Bearer {access_token}, where access_token is your CMS access token.
In the request body, create a JSON object with these fields.
name—A string that contains the name of the content.
assetType—An object containing the id field with a numeric value of 196. 196 is the asset type for text blocks.
content—The JSON object for the text CMS content.
category—An object that contains the id field with a string value. Set the value to the category ID of the Content Builder folder where you want Marketing Cloud to save the content.
For more information on the request and response format for this resource, see Marketing Cloud API: REST API v1 Reference.
This Node.js sample adds text CMS content to Marketing Cloud. The currentNode variable contains the JSON object of the CMS content.
1async function moveTextToMC(name, currentNode, mcAuthResults) {
2 let text = currentNode;
3
4 if (typeof currentNode === "object") {
5 text = currentNode.value;
6 }
7 console.log(`Uploading text to MC: ${name} - ${text}`);
8
9 let textAssetBody = {
10 name: name,
11 assetType: {
12 id: 196,
13 },
14 content: text,
15 category: {
16 id: "1099065",
17 },
18 };
19 // Create MC Asset
20 await createMCAsset(mcAuthResults.access_token, textAssetBody);
21}
22
23async function createMCAsset(access_token, assetBody) {
24 return new Promise((resolve, reject) => {
25 request.post(
26 mc_host + mc_assets_api_path,
27 {
28 headers: {
29 Authorization: "Bearer " + access_token,
30 },
31 json: assetBody,
32 },
33 (error, res, body) => {
34 if (error) {
35 console.error(error);
36 console.log({ assetBody });
37 reject({ error });
38 } else {
39 console.log(`statusCode: ${res.statusCode}`);
40 console.log(body);
41 resolve();
42 }
43 },
44 );
45 });
46}In response to the API request, the API returns an HTTP response code and a JSON body with an object representing the newly created asset in Marketing Cloud. For details on the response object and possible HTTP response codes, see Marketing Cloud API: REST API v1 Reference.