Example: Create and Schedule Custom Recommendations with Audiences

This example creates and schedules a custom recommendation with audiences.

Community managers can access, create, and delete audiences, definitions, and schedules for custom recommendations. (Community managers are users with the Create and Set Up Experiences or Manage Experiences permission.) Users with the Modify All Data permission can also access, create, and delete custom recommendation audiences, custom recommendation definitions, and scheduled custom recommendations.

These recommendations appear by default on the Customer Service template. They appear on the home and question detail pages and in the feed in Salesforce mobile web. They also appear anywhere community managers add recommendations using Experience Builder in the Customer Service template.

So that users don’t see the same recommendations all the time, Salesforce periodically removes and brings back custom recommendations that haven’t been accepted or dismissed.

Step 1: Define the Custom Recommendation 

Resource 

/connect/communities/{communityId}/recommendation-definitions

HTTP method 

POST

Request body 

Custom Recommendation Definition Input

Request body example 

1{
2   "name":"Corporate Training Project",
3   "title":"Want to learn more about the Corporate Training Project?",
4   "explanation":"Click this link to learn more!",
5   "actionUrl":"https://www.example.com",
6   "actionUrlName":"Launch"
7}

Response body 

Custom Recommendation Definition

Step 2: Add an Image to the Custom Recommendation 

This example adds an image file that has been uploaded to Salesforce. To upload a new image file, see Uploading Binary Files.

Resource 

/connect/recommendation-definitions/{recommendationDefinitionId}/photo

Use the recommendationDefinitionId returned in the Recommendation Definition response body in Step 1.

HTTP method 

PUT

Request body 

Photo Input

Request body example 

1{
2   "cropSize" : "120",
3   "cropX" : "0",
4   "cropY" : "0",
5   "fileId" : "069D00000001IOh"
6}

Response body 

Photo

Step 3: Create a Recommendation Audience 

Resource 

/connect/communities/{communityId}/recommendation-audiences

HTTP method 

POST

Request body 

Custom Recommendation Audience Input

Request body example 

1{
2   "name" : "Custom App Users"
3}

Response body 

Custom Recommendation Audience

Step 4: Add Members to the Recommendation Audience 

Resource 

/connect/communities/{communityId}/recommendation-audiences/{recommendationAudienceId}

Use the recommendationAudienceId returned in the Recommendation Audience response body in Step 3.

HTTP method 

PATCH

Request body 

Custom Recommendation Audience Input

In this example, this Recommendation Audience Input request body includes a criteria property that is a Custom List Audience Criteria Input request body. The Custom List Audience Criteria Input request body includes a members property that is a User ID Collection Input request body.

Request body example 

1{
2   "criteria" : {
3      "memberOperationType" : "Add",
4      "members" : {
5         "userIds" : [
6            "005B0000000Ge16",
7            "005D0000001GpHp"
8            ]
9         },
10      "type" : "CustomList"
11   }
12}

Response body 

Custom Recommendation Audience

Step 5: Schedule the Custom Recommendation with the Audience 

Resource 

/connect/communities/{communityId}/scheduled-recommendations

HTTP method 

POST

Request body 

Scheduled Custom Recommendation Input

Request body example 

1{
2   "recommendationDefinitionId" : "0RDD00000004CEhOAM",
3   "recommendationAudienceId":"02JD00000008SfdMAE"
4}

Response body 

Scheduled Custom Recommendation