Define Action Links in a Template and Post with a Feed Element
Step 1: Create the Action Link Templates
Just like radio buttons, action links must be nested in a group. Action links within a group share the properties of the group and are mutually exclusive (you can click only one action link within a group). Even if you define only one action link, it must be part of an action link group. The same is true for action link templates and action link group templates.
This example uses one action link in an action link group. When a user clicks the action link, an HTTP POST request is made to a Connect REST API resource, which posts a feed item to Chatter. The HTTP Request Body field holds the request body for the Action URL resource, including the text of the new feed item. In this example, the new feed item includes only text, but it could include other capabilities such as a file attachment, a poll, or even action links.
- From Setup, enter Action Link Templates in the Quick Find box, then select Action Link Templates.
- Use these values in a new Action Link Group Template:
Field Value Name Doc Example Developer Name Doc_Example Category Primary action Executions Allowed Once per User - Use these values in a new Action Link Template:
Field Value Action Link Group Template Doc Example Action Type Api Action URL /services/data/{!Bindings.ApiVersion}/chatter/feed-elements User Visibility Everyone can see HTTP Request Body {"subjectId": "{!Bindings.SubjectId}","feedElementType": "FeedItem","body": {"messageSegments": [{"type": "Text","text": "{!Bindings.Text}"}]}} HTTP Headers Content-Type: application/json Position 0 Label Key Post HTTP Method POST - Go back to the Action Link Group Template and select Published.
Click Save.
Make a note of the Action Link Group Template ID and skip to Step 3.
Step 2: Get the Action Link Group Template ID
If you have access to the action link group template in Setup, you can get the Action Link Group Template ID and skip to Step 3.
- Resource
-
/services/data/v33.0/query
- HTTP method
- GET
- Request parameters
- q—A SOQL query string.
- Request parameters example
-
GET /services/data/v64.0/query?q=SELECT+id+FROM+ActionLinkGroupTemplate+WHERE+DeveloperName='Doc_Example'
- cURL example
-
curl https://instance_name/services/data/v64.0/query?q=SELECT+id+FROM+ActionLinkGroupTemplate+ WHERE+DeveloperName='Doc_Example' -H "Authorization: Bearer token"
- Response body
- An array of query result records.
-
{ "totalSize":1, "done":true, "records":[ { "attributes":{ "type":"ActionLinkGroupTemplate", "url":"/services/data/v64.0/sobjects/ActionLinkGroupTemplate/07gD00000004CEhIAM" }, "Id":"07gD00000004CEhIAM" } ] }
Step 3: Instantiate the Action Link Group
- Resource
- /connect/action-link-group-definitions
- HTTP method
- POST
- Request body
-
Action Link Group Definition Input
This Action Link Group Definition Input request body includes a templateBindings property that is a collection of Action Link Template Binding Input request bodies. In this example, the Action Link Template Binding Input request body includes three template bindings.
- Request body example
-
POST /services/data/v64.0/connect/action-link-group-definitions { "templateId":"07gD00000004CEhIAM", "templateBindings" : [ { "key":"ApiVersion", "value":"v33.0" }, { "key":"Text", "value":"This post was created by an API Action Link!" }, { "key":"SubjectId", "value":"me" } ] }
- Request example using cURL
- To use cURL to make the request, enter the following and
substitute your Developer Edition instance name, and OAuth
information.
curl -H "X-PrettyPrint: 1" -H "Content-Type: application/json" -d '{ "templateId":"07gD00000004CEhIAM", "templateBindings" : [ { "key":"ApiVersion", "value":"v64.0" }, { "key":"Text", "value":"This post was created by an API Action Link!" }, { "key":"SubjectId", "value":"me" } ] }' -X POST "https://instance_name/services/data/v64.0/connect/action-link-group-definitions" -H 'Authorization: OAuth 00DRR0000000N0g!RWaPj94O6yOD.lfjB9LqMk' --insecure
- Response body
- Action Link Group Definition
Step 4: Associate the Action Link Group with a Feed Element and Post It
- Resource
- /chatter/feed-elements
- HTTP method
- POST
- Request body
-
Feed Item Input
This Feed Item Input request body includes a body property that is a Message Body Input request body. In this example, the Message Body Input request body includes a messageSegments property that has one Message Segment Input: Text request body.
This Feed Item Input request body also includes a capabilities property that is a Feed Element Capabilities Input request body. In this example, the Feed Element Capabilities Input includes an associatedActions property that is a Associated Actions Capability Input request body.
- Request body example
-
Grab the action link group ID from the id property of the Action Link Group Definition response from step 3.
POST /services/data/v64.0/chatter/feed-elements { "body": { "messageSegments": [ { "type": "Text", "text": "Click to post a feed item." } ] }, "subjectId": "me", "feedElementType": "feedItem", "capabilities": { "associatedActions": { "actionLinkGroupIds": ["0AgRR0000004CTr0AM"] } } }
- Request example using cURL
- To use cURL to make the request, enter the following and
substitute the action link group ID returned in step 2, your Developer Edition instance
name, and your OAuth
information.
curl -H "X-PrettyPrint: 1" -H "Content-Type: application/json" -d '{ "body": { "messageSegments": [ { "type": "Text", "text": "Click to post a feed item." } ] }, "subjectId": "me", "feedElementType": "feedItem", "capabilities": { "associatedActions": { "actionLinkGroupIds": ["0AgRR0000004CTr0AM"] } } }' -X POST "https://instance_name/services/data/v64.0/chatter/feed-elements" -H 'Authorization: OAuth OOARoAQETAKEIddnMWXh462dprYAgRWaPj94O6yOD' --insecure
- Response body
- Feed Item