This SDK app provides a way to select a Salesforce CMS image, take additional input from the block, and render the image in the email.
This Content Block SDK app provides a way to select a Salesforce CMS content based on image, news, or document content types via a channel, take additional input from the block, and render the image in the email.
- The application is written in Node.js. Express is used as the framework with EJS as the view engine. Leveraged Salesforce Lightning Design System for the User Interface, and Salesforce Marketing Cloud Block SDK for interacting with Content Builder.
- 3 Total Routes - 1 View
- index - home page for app that provides the interface the user will engage with.
- getCMSDocuments - retrieves cms documents based on the standard cms_document content type for the specified channelId.
- getCMSImages - retrieves cms images based on the standard cms_image content type for the specified channelId.
- getCMSNews - retrieves cms news based on the standard news content type for the specified channelId.
- Salesforce org with CMS enabled
- Salesforce CMS Workspace
- Marketing Cloud Account
- GitHub Account
- Heroku Account
- Step 1: Create a headless Marketing Cloud channel in Salesforce CMS for integration with Marketing Cloud
- Step 2: Author content in Salesforce CMS Workspace
- Step 3: Create a Private Key and Self-Signed Digital Certificate
- Step 4: Create a user account
- Step 5: Create a Connected App
- Step 6: Deploy the GitHub Repo to Heroku
- Step 7: Create a Package in Marketing Cloud
- Step 8: Create an email message in Marketing Cloud Content Builder and use CMS content
- From the Salesforce App Launcher, open Salesforce CMS
- From the CMS Home tab, select CMS Channels
- Click Add Channel | Create Channel
- Name the channel: Marketing Channel
- Select the connection type: Public
- Click Create
- From CMS Workspaces, select the workspace where you want to add the Marketing Channel created in the previous step
- Click Add Channel to share content created in this workspace
- Select the Marketing Channel. Then click Add
- Login to Workbench to retrieve the Marketing Channel Id
- From Workbench go to Utilities | Rest Explorer
- Choose the GET http method with this service URI: /services/data/v51.0/connect/cms/delivery/channels
- Click on Execute
- Click on Expand All and copy the channelId for the channelName: Marketing Channel
- We will use the copied channelId later
You can use the content in a public channel for emails, websites, custom apps, and more. To share your Salesforce CMS content with your endpoints, Add a Channel to a CMS Workspace.
- In the Salesforce CMS app, open the workspace associated with the public channel: Marketing Channel. Click Add Content
- Select the content type: Document, Image, or News. Then click Create
- Fill in the fields. Click Save Draft when finished
- Click Publish
Here’s how your new content in Salesforce CMS should look. Your content is now ready for sending in an email marketing campaign.
📖 Create a Private Key and Self-Signed Digital Certificate
We will use the OAuth 2.0 JWT bearer flow for server to server integration between Salesforce CMS and Marketing Cloud. The OAuth 2.0 JWT bearer authorization flow requires a digital certificate and the private key used to sign the certificate. You upload the digital certificate to the custom connected app that is also required for the JWT bearer authorization flow. You can use your own private key and certificate issued by a certification authority. Alternatively, you can use OpenSSL to create a key and a self-signed digital certificate.
If necessary, install OpenSSL on your computer.
- To check whether OpenSSL is installed on your computer, In Terminal or a Windows command prompt, run this command.
which openssl
- Create a directory to store the generated files, and change to the directory.
cd ..
mkdir certificates
cd certificates
- From within the certificates folder, generate an RSA private key
openssl genrsa -des3 -passout pass:SomePassword -out server.pass.key 2048
- Create a key file from the server.pass.key file
openssl rsa -passin pass:SomePassword -in server.pass.key -out server.key
- Delete the server.pass.key
rm server.pass.key
- Request and generate the certificate
openssl req -new -key server.key -out server.csr
-
Enter all requested information. Enter a period (.) to skip entering an optional company name.
-
Generate the SSL certificate
openssl x509 -req -sha256 -days 365 -in server.csr -signkey server.key -out server.crt
You should now have the server.crt, server.csr, and server.key files created. The self-signed SSL certificate server.crt is generated from the server.key private key and server.csr files. The server.crt file is your site certificate, suitable for use with the connected app along with the server.key private key. We’ll use these files soon.
- Create a new Salesforce User called CMS User | Assign the Standard User Profile | Save
- Open Salesforce CMS from the App Launcher and select the workspace associated with the Marketing Channel
- Select Contributors and click Add Contributors.
- Search for and select the CMS User | Next | Assign the Content Admin role | Finish
To access the content created in Salesforce CMS via API for a seamless integration, Create a connected App, which allows invocation of the Salesforce API via OAuth from a NodeJS App hosted on Heroku.
-
From Setup, enter App Manager in the Quick Find box, then select App Manager
-
Click New Connected App
-
Enter the connected app name and email address:
- Connected App Name: CMS for Marketing Cloud
- Contact Email: Enter the email address associated with the CMS User
-
Select Enable OAuth Settings.
-
Enter the callback URL: http://localhost (we will not use the callback URL, however this is a required field and needs a url)
-
Select Use digital signatures
-
To upload your server.crt file, click Choose File
-
For OAuth scopes, add:
- Access and manage your data (api)
- Perform requests on your behalf at any time (refresh_token, offline_access)
- Provide access to your data via the Web (web)
-
Click Save
Note: Be sure to copy the consumer key shown below (blurred), you’ll use it later.
After you’ve saved your connected app, Edit Policies to enable the connected app to circumvent the manual login process.
- Click the Manage button.
- Click Edit Policies button.
- In the OAuth policies section, for Permitted Users select Admin approved users are pre-authorized, then click OK.
- Click Save.
Lastly, create a permission set and assign pre-authorized users for this connected app.
- From Setup, enter Permission in the Quick Find box, then select Permission Sets.
- Click New.
- For the Label, enter: CMS Connected App Permission Set
- Click Save.
- Click Manage Assignments | Add Assignments.
- Select the checkbox next to CMS User. Assign the CMS Connected App Permission Set, then click Assign | Done
- Go back to your permission set, under the Apps Section click Assign Connected Apps | Edit | Select CMS for Marketing Cloud | Save
This sample Node.js app demonstrates how to pull Salesforce CMS data into Marketing Cloud Content Builder using the Block SDK and is not an official tool. This approach allows for seamless integration.
- Click the Deploy to Heroku button to deploy to your Heroku account.
During setup configure the following environment values:
- channelID: Enter the Salesforce CMS channelID copied earlier
- clientID: Enter the Consumer Key from your Connected App
- cmsUser: Enter the Salesforce CMS Username
- instanceURL: Enter the Salesforce login URL - https://login.salesforce.com or https://test.salesforce.com
- limit: Enter the number of CMS records to display (default is 25, max 100)
- privateKey: Copy the contents of the server.key file
Marketing Cloud Content Builder is a cross-channel content building system for creating, managing, and editing content. It's designed to work in the way your team works — whether in code or via plug-n-play HTML.
- In Marketing Cloud setup, create a new package by going to Setup | Installed Packages | New
- Enter a Name, Description and Save
- Click Add Component | Select Custom Content Block | Next
- Enter the component Name, Description, and Endpoint URL (URL of your Heroku app) then Save
Start creating the Email from the content builder. Select a template of your choice and then click on the content type icon (Images, Docs, or News) to see the Salesforce CMS content. Add content into the Email template suitable for the campaign by clicking on the CMS resource.