Newer Version Available

This content describes an older version of this product. View Latest

Define Action Links and Post with a Feed Element

Define actions links and post with a feed element.

Step 1: Define the Action Link Group

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.

Think of an action link as a button on a feed item. Like a button, an action link includes a label (labelKey). An action link definition also includes other properties like a URL (actionUrl), an HTTP method (method), and an optional request body (requestBody) and HTTP headers (headers).

When a user clicks this action link, an HTTP POST request is made to a Connect REST API resource, which posts a feed item to Chatter. The requestBody property holds the request body for the actionUrl 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.

Resource
/connect/action-link-group-definitions
HTTP method
POST
Request body
Action Link Group Definition Input

This request body includes an actionLinks property that holds a collection of Action Link Definition Input request bodies. This example has one action link.

Request body example
1POST /services/data/v65.0/connect/action-link-group-definitions
2{
3   "executionsAllowed":"OncePerUser",
4   "expirationDate":"2015-05-20T19:32:10+0000",
5   "category":"Primary",
6   "actionLinks":[
7      {
8         "actionType":"Api",
9         "actionUrl":"/services/data/v65.0/chatter/feed-elements",
10         "labelKey":"Post",
11         "method":"HttpPost",
12         "requiresConfirmation":"false",
13         "requestBody":"{\"subjectId\": \"me\",\"feedElementType\": \"FeedItem\",\"body\": 
14{\"messageSegments\": [{\"type\": \"Text\",\"text\": \"This post was created via an API action link.\"}]}}",
15         "headers":[
16            {
17               "name":"Content-Type",
18               "value":"application/json"
19            },
20            {
21               "name":"Authorization",
22               "value":"OAuth 00DD00000007WNP!ARsAQHhIdgwbihG7e8ga"
23            }
24         ]
25      }
26   ]
27}
Request example using cURL
To use cURL to make the request, enter the following and substitute your Developer Edition instance name, and OAuth information.
1curl -H "X-PrettyPrint: 1" -H "Content-Type: application/json" 
2-d '{ "executionsAllowed":"OncePerUser", "expirationDate":"2015-09-20T19:32:10+0000", "category":"Primary", 
3"actionLinks":[ { "actionType":"Api", "actionUrl":"/services/data/v65.0/chatter/feed-elements", 
4"groupDefault":"true", "labelKey":"Post", "method":"HttpPost", "requiresConfirmation":"true", 
5"requestBody":"{\"subjectId\": \"me\",\"feedElementType\": \"FeedItem\",\"body\": 
6{\"messageSegments\": [{\"type\": \"Text\",\"text\": \"This is a test post created via an API action link.\"}]}}", 
7"headers":[ { "name":"Content-Type", "value":"application/json" }, { "name":"Authorization", "value":"OAuth 00DD00000007WNP!ARsAQHhIdgwbihG7e8ga" }] }] }' 
8-X POST "https://instance_name/services/data/v65.0/connect/action-link-group-definitions" 
9-H 'Authorization: OAuth 00DRR0000000N0g!RWaPj94O6yOD.lfjB9LqMk' --insecure
Response body
Action Link Group Definition

Step 2: Associate the Action Link Group with a Feed Item and Post It

You can associate up to 10 action link groups with a feed element.
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 1.

1POST /services/data/v65.0/chatter/feed-elements
2
3{
4  "body": {
5    "messageSegments": [
6      {
7        "type": "Text",
8        "text": "Click to post a feed item."
9       }
10    ]
11    },
12  "subjectId": "me",
13  "feedElementType": "feedItem",
14  "capabilities": {
15    "associatedActions": {
16      "actionLinkGroupIds": ["0AgRR0000004CTr0AM"]
17    }
18  }
19}
Request example using cURL
To use cURL to make the request, enter the following and substitute the action link group ID returned in step 1, your Developer Edition instance name, and your OAuth information.
1curl -H "X-PrettyPrint: 1" -H "Content-Type: application/json" -d '{ "body": { "messageSegments": 
2[ { "type": "Text", "text": "Click to post a feed item." } ] }, "subjectId": "me", "feedElementType": "feedItem", "capabilities": 
3{ "associatedActions": { "actionLinkGroupIds": ["0AgRR0000004CTr0AM"] } } }' 
4-X POST "https://instance_name/services/data/v65.0/chatter/feed-elements" 
5-H 'Authorization: OAuth OOARoAQETAKEIddnMWXh462dprYAgRWaPj94O6yOD' --insecure
Response body
Feed Item