Chilkat Online Tools

Ruby / Salesforce Platform APIs / Feed Elements Capability, Comments Items

Back to Collection Items

require 'chilkat'

# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.

http = Chilkat::CkHttp.new()

# Adds the "Authorization: Bearer <access_token>" header.
http.put_AuthToken("<access_token>")

# resp is a CkHttpResponse
resp = http.QuickRequest("POST","Comment")
if (http.get_LastMethodSuccess() == false)
    print http.lastErrorText() + "\n";
    exit
end

sbResponseBody = Chilkat::CkStringBuilder.new()
resp.GetBodySb(sbResponseBody)

jResp = Chilkat::CkJsonObject.new()
jResp.LoadSb(sbResponseBody)
jResp.put_EmitCompact(false)

print "Response Body:" + "\n";
print jResp.emit() + "\n";

respStatusCode = resp.get_StatusCode()
print "Response Status Code = " + respStatusCode.to_s() + "\n";
if (respStatusCode >= 400)
    print "Response Header:" + "\n";
    print resp.header() + "\n";
    print "Failed." + "\n";

    exit
end

# Sample JSON response:
# (Sample code for parsing the JSON response is shown below)

# {
#   "body": {
#     "isRichText": false,
#     "messageSegments": [
#       {
#         "text": "New Comment",
#         "type": "Text"
#       }
#     ],
#     "text": "New Comment"
#   },
#   "capabilities": {
#     "edit": {
#       "isEditRestricted": false,
#       "isEditableByMeUrl": "/services/data/v58.0/chatter/comments/0D7.../capabilities/edit/is-editable-by-me",
#       "lastEditedBy": null,
#       "lastEditedDate": null,
#       "latestRevision": 1,
#       "relativeLastEditedDate": null
#     },
#     "status": {
#       "feedEntityStatus": "Published",
#       "isApprovableByMe": true
#     },
#     "upDownVote": {
#       "downVoteCount": 0,
#       "myVote": "None",
#       "upVoteCount": 0
#     },
#     "verified": {
#       "isVerifiableByMe": false,
#       "isVerified": false,
#       "isVerifiedByAnonymized": null,
#       "lastVerifiedByUser": null,
#       "lastVerifiedDate": null
#     }
#   },
#   "clientInfo": {
#     "applicationName": "Postman Playground",
#     "applicationUrl": null
#   },
#   "createdDate": "2023-11-22T11:14:33.000Z",
#   "feedElement": {
#     "id": "0D5...",
#     "url": "/services/data/v58.0/chatter/feed-elements/0D5..."
#   },
#   "id": "0D7...",
#   "isDeleteRestricted": false,
#   "likes": {
#     "currentPageToken": null,
#     "currentPageUrl": "/services/data/v58.0/chatter/comments/0D7.../likes",
#     "items": [
#     ],
#     "nextPageToken": null,
#     "nextPageUrl": null,
#     "previousPageToken": null,
#     "previousPageUrl": null,
#     "total": 0
#   },
#   "likesMessage": null,
#   "moderationFlags": null,
#   "myLike": null,
#   "parent": {
#     "id": "001...",
#     "url": "/services/data/v58.0/chatter/records/001..."
#   },
#   "relativeCreatedDate": "Just now",
#   "threadLevel": 0,
#   "threadParentId": null,
#   "type": "TextComment",
#   "url": "/services/data/v58.0/chatter/comments/0D7...",
#   "user": {
#     "additionalLabel": null,
#     "communityNickname": "User1696423780773910041",
#     "companyName": "Salesforce",
#     "displayName": "Name",
#     "firstName": "Firstname",
#     "id": "005...",
#     "isActive": true,
#     "isInThisCommunity": true,
#     "lastName": "Name",
#     "motif": {
#       "color": "1B96FF",
#       "largeIconUrl": "/img/icon/profile64.png",
#       "mediumIconUrl": "/img/icon/profile32.png",
#       "smallIconUrl": "/img/icon/profile16.png",
#       "svgIconUrl": null
#     },
#     "mySubscription": null,
#     "name": "Name",
#     "outOfOffice": {
#       "message": ""
#     },
#     "photo": {
#       "fullEmailPhotoUrl": "https://<my_domain>/ncsphoto/1wsMlOd3tVC7boygqBO8wMT9KzA0D6tqzpbs-Uw0IogXzXAXaYKJnuWCNQmXymRq?fromEmail=1",
#       "largePhotoUrl": "https://<my_domain>/profilephoto/729.../F",
#       "mediumPhotoUrl": "https://<my_domain>/profilephoto/729.../M",
#       "photoVersionId": "729...",
#       "smallPhotoUrl": "https://<my_domain>/profilephoto/729.../T",
#       "standardEmailPhotoUrl": "https://<my_domain>/ncsphoto/1wsMlOd3tVC7boygqBO8wMT9KzA0D6tqzpbs-Uw0Ioi-dtynkoFWsl46as__TDFU?fromEmail=1",
#       "url": "/services/data/v58.0/connect/user-profiles/005.../photo"
#     },
#     "reputation": null,
#     "title": null,
#     "type": "User",
#     "url": "/services/data/v58.0/chatter/users/005...",
#     "userType": "Internal"
#   }
# }

# Sample code for parsing the JSON response...
# Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

IsRichText = jResp.BoolOf("body.isRichText")
Text = jResp.stringOf("body.text")
IsEditRestricted = jResp.BoolOf("capabilities.edit.isEditRestricted")
IsEditableByMeUrl = jResp.stringOf("capabilities.edit.isEditableByMeUrl")
LastEditedBy = jResp.stringOf("capabilities.edit.lastEditedBy")
LastEditedDate = jResp.stringOf("capabilities.edit.lastEditedDate")
LatestRevision = jResp.IntOf("capabilities.edit.latestRevision")
RelativeLastEditedDate = jResp.stringOf("capabilities.edit.relativeLastEditedDate")
FeedEntityStatus = jResp.stringOf("capabilities.status.feedEntityStatus")
IsApprovableByMe = jResp.BoolOf("capabilities.status.isApprovableByMe")
DownVoteCount = jResp.IntOf("capabilities.upDownVote.downVoteCount")
MyVote = jResp.stringOf("capabilities.upDownVote.myVote")
UpVoteCount = jResp.IntOf("capabilities.upDownVote.upVoteCount")
IsVerifiableByMe = jResp.BoolOf("capabilities.verified.isVerifiableByMe")
IsVerified = jResp.BoolOf("capabilities.verified.isVerified")
IsVerifiedByAnonymized = jResp.stringOf("capabilities.verified.isVerifiedByAnonymized")
LastVerifiedByUser = jResp.stringOf("capabilities.verified.lastVerifiedByUser")
LastVerifiedDate = jResp.stringOf("capabilities.verified.lastVerifiedDate")
ApplicationName = jResp.stringOf("clientInfo.applicationName")
ApplicationUrl = jResp.stringOf("clientInfo.applicationUrl")
createdDate = jResp.stringOf("createdDate")
Id = jResp.stringOf("feedElement.id")
v_Url = jResp.stringOf("feedElement.url")
id = jResp.stringOf("id")
isDeleteRestricted = jResp.BoolOf("isDeleteRestricted")
CurrentPageToken = jResp.stringOf("likes.currentPageToken")
CurrentPageUrl = jResp.stringOf("likes.currentPageUrl")
NextPageToken = jResp.stringOf("likes.nextPageToken")
NextPageUrl = jResp.stringOf("likes.nextPageUrl")
PreviousPageToken = jResp.stringOf("likes.previousPageToken")
PreviousPageUrl = jResp.stringOf("likes.previousPageUrl")
Total = jResp.IntOf("likes.total")
likesMessage = jResp.stringOf("likesMessage")
moderationFlags = jResp.stringOf("moderationFlags")
myLike = jResp.stringOf("myLike")
parentId = jResp.stringOf("parent.id")
parentUrl = jResp.stringOf("parent.url")
relativeCreatedDate = jResp.stringOf("relativeCreatedDate")
threadLevel = jResp.IntOf("threadLevel")
threadParentId = jResp.stringOf("threadParentId")
v_type = jResp.stringOf("type")
url = jResp.stringOf("url")
AdditionalLabel = jResp.stringOf("user.additionalLabel")
CommunityNickname = jResp.stringOf("user.communityNickname")
CompanyName = jResp.stringOf("user.companyName")
DisplayName = jResp.stringOf("user.displayName")
FirstName = jResp.stringOf("user.firstName")
userId = jResp.stringOf("user.id")
IsActive = jResp.BoolOf("user.isActive")
IsInThisCommunity = jResp.BoolOf("user.isInThisCommunity")
LastName = jResp.stringOf("user.lastName")
Color = jResp.stringOf("user.motif.color")
LargeIconUrl = jResp.stringOf("user.motif.largeIconUrl")
MediumIconUrl = jResp.stringOf("user.motif.mediumIconUrl")
SmallIconUrl = jResp.stringOf("user.motif.smallIconUrl")
SvgIconUrl = jResp.stringOf("user.motif.svgIconUrl")
MySubscription = jResp.stringOf("user.mySubscription")
Name = jResp.stringOf("user.name")
Message = jResp.stringOf("user.outOfOffice.message")
FullEmailPhotoUrl = jResp.stringOf("user.photo.fullEmailPhotoUrl")
LargePhotoUrl = jResp.stringOf("user.photo.largePhotoUrl")
MediumPhotoUrl = jResp.stringOf("user.photo.mediumPhotoUrl")
PhotoVersionId = jResp.stringOf("user.photo.photoVersionId")
SmallPhotoUrl = jResp.stringOf("user.photo.smallPhotoUrl")
StandardEmailPhotoUrl = jResp.stringOf("user.photo.standardEmailPhotoUrl")
PhotoUrl = jResp.stringOf("user.photo.url")
Reputation = jResp.stringOf("user.reputation")
Title = jResp.stringOf("user.title")
v_Type = jResp.stringOf("user.type")
userUrl = jResp.stringOf("user.url")
UserType = jResp.stringOf("user.userType")
i = 0
count_i = jResp.SizeOfArray("body.messageSegments")
while i < count_i
    jResp.put_I(i)
    text = jResp.stringOf("body.messageSegments[i].text")
    v_type = jResp.stringOf("body.messageSegments[i].type")
    i = i + 1
end
i = 0
count_i = jResp.SizeOfArray("likes.items")
while i < count_i
    jResp.put_I(i)
    i = i + 1
end

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
https://domain.com/services/data/v{{version}}/chatter/feed-elements/:FEED_ELEMENT_ID/capabilities/comments/items?text=New Comment

Postman Collection Item JSON

{
  "name": "Feed Elements Capability, Comments Items",
  "event": [
    {
      "listen": "prerequest",
      "script": {
        "exec": [
          ""
        ],
        "type": "text/javascript"
      }
    },
    {
      "listen": "test",
      "script": {
        "exec": [
          ""
        ],
        "type": "text/javascript"
      }
    }
  ],
  "request": {
    "method": "POST",
    "header": [
    ],
    "url": {
      "raw": "{{_endpoint}}/services/data/v{{version}}/chatter/feed-elements/:FEED_ELEMENT_ID/capabilities/comments/items?text=New Comment",
      "host": [
        "{{_endpoint}}"
      ],
      "path": [
        "services",
        "data",
        "v{{version}}",
        "chatter",
        "feed-elements",
        ":FEED_ELEMENT_ID",
        "capabilities",
        "comments",
        "items"
      ],
      "query": [
        {
          "key": "text",
          "value": "New Comment"
        }
      ],
      "variable": [
        {
          "key": "FEED_ELEMENT_ID",
          "value": ""
        }
      ]
    },
    "description": "Access comments for a feed element, or add a comment to a feed element.\nTo upload a binary file to attach to a comment, you must send it in a multipart/form-data request. To send the text of the comment, you can choose to include a JSON or XML rich input body part in the multipart/form-data request. Alternately, you can choose to pass the information in request parameter parts. For information about how to create the multipart/form-data message, see Uploading Binary Files.\n\nhttps://developer.salesforce.com/docs/atlas.en-us.chatterapi.meta/chatterapi/connect_resources_feed_element_capability_comments_items.htm#connect_resources_feed_element_capability_comments_items"
  },
  "response": [
    {
      "name": "Feed Elements Capability, Comments Items",
      "originalRequest": {
        "method": "POST",
        "header": [
        ],
        "url": {
          "raw": "{{_endpoint}}/services/data/v{{version}}/chatter/feed-elements/:FEED_ELEMENT_ID/capabilities/comments/items?text=New Comment",
          "host": [
            "{{_endpoint}}"
          ],
          "path": [
            "services",
            "data",
            "v{{version}}",
            "chatter",
            "feed-elements",
            ":FEED_ELEMENT_ID",
            "capabilities",
            "comments",
            "items"
          ],
          "query": [
            {
              "key": "text",
              "value": "New Comment"
            }
          ],
          "variable": [
            {
              "key": "FEED_ELEMENT_ID",
              "value": "0D5..."
            }
          ]
        }
      },
      "status": "Created",
      "code": 201,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Date",
          "value": "Wed, 22 Nov 2023 11:14:33 GMT"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=63072000; includeSubDomains"
        },
        {
          "key": "X-Content-Type-Options",
          "value": "nosniff"
        },
        {
          "key": "X-XSS-Protection",
          "value": "1; mode=block"
        },
        {
          "key": "X-Robots-Tag",
          "value": "none"
        },
        {
          "key": "Cache-Control",
          "value": "no-cache,must-revalidate,max-age=0,no-store,private"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=UTF-8"
        },
        {
          "key": "Vary",
          "value": "Accept-Encoding"
        },
        {
          "key": "Content-Encoding",
          "value": "gzip"
        },
        {
          "key": "Transfer-Encoding",
          "value": "chunked"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"body\": {\n        \"isRichText\": false,\n        \"messageSegments\": [\n            {\n                \"text\": \"New Comment\",\n                \"type\": \"Text\"\n            }\n        ],\n        \"text\": \"New Comment\"\n    },\n    \"capabilities\": {\n        \"edit\": {\n            \"isEditRestricted\": false,\n            \"isEditableByMeUrl\": \"/services/data/v58.0/chatter/comments/0D7.../capabilities/edit/is-editable-by-me\",\n            \"lastEditedBy\": null,\n            \"lastEditedDate\": null,\n            \"latestRevision\": 1,\n            \"relativeLastEditedDate\": null\n        },\n        \"status\": {\n            \"feedEntityStatus\": \"Published\",\n            \"isApprovableByMe\": true\n        },\n        \"upDownVote\": {\n            \"downVoteCount\": 0,\n            \"myVote\": \"None\",\n            \"upVoteCount\": 0\n        },\n        \"verified\": {\n            \"isVerifiableByMe\": false,\n            \"isVerified\": false,\n            \"isVerifiedByAnonymized\": null,\n            \"lastVerifiedByUser\": null,\n            \"lastVerifiedDate\": null\n        }\n    },\n    \"clientInfo\": {\n        \"applicationName\": \"Postman Playground\",\n        \"applicationUrl\": null\n    },\n    \"createdDate\": \"2023-11-22T11:14:33.000Z\",\n    \"feedElement\": {\n        \"id\": \"0D5...\",\n        \"url\": \"/services/data/v58.0/chatter/feed-elements/0D5...\"\n    },\n    \"id\": \"0D7...\",\n    \"isDeleteRestricted\": false,\n    \"likes\": {\n        \"currentPageToken\": null,\n        \"currentPageUrl\": \"/services/data/v58.0/chatter/comments/0D7.../likes\",\n        \"items\": [],\n        \"nextPageToken\": null,\n        \"nextPageUrl\": null,\n        \"previousPageToken\": null,\n        \"previousPageUrl\": null,\n        \"total\": 0\n    },\n    \"likesMessage\": null,\n    \"moderationFlags\": null,\n    \"myLike\": null,\n    \"parent\": {\n        \"id\": \"001...\",\n        \"url\": \"/services/data/v58.0/chatter/records/001...\"\n    },\n    \"relativeCreatedDate\": \"Just now\",\n    \"threadLevel\": 0,\n    \"threadParentId\": null,\n    \"type\": \"TextComment\",\n    \"url\": \"/services/data/v58.0/chatter/comments/0D7...\",\n    \"user\": {\n        \"additionalLabel\": null,\n        \"communityNickname\": \"User1696423780773910041\",\n        \"companyName\": \"Salesforce\",\n        \"displayName\": \"Name\",\n        \"firstName\": \"Firstname\",\n        \"id\": \"005...\",\n        \"isActive\": true,\n        \"isInThisCommunity\": true,\n        \"lastName\": \"Name\",\n        \"motif\": {\n            \"color\": \"1B96FF\",\n            \"largeIconUrl\": \"/img/icon/profile64.png\",\n            \"mediumIconUrl\": \"/img/icon/profile32.png\",\n            \"smallIconUrl\": \"/img/icon/profile16.png\",\n            \"svgIconUrl\": null\n        },\n        \"mySubscription\": null,\n        \"name\": \"Name\",\n        \"outOfOffice\": {\n            \"message\": \"\"\n        },\n        \"photo\": {\n            \"fullEmailPhotoUrl\": \"https://<my_domain>/ncsphoto/1wsMlOd3tVC7boygqBO8wMT9KzA0D6tqzpbs-Uw0IogXzXAXaYKJnuWCNQmXymRq?fromEmail=1\",\n            \"largePhotoUrl\": \"https://<my_domain>/profilephoto/729.../F\",\n            \"mediumPhotoUrl\": \"https://<my_domain>/profilephoto/729.../M\",\n            \"photoVersionId\": \"729...\",\n            \"smallPhotoUrl\": \"https://<my_domain>/profilephoto/729.../T\",\n            \"standardEmailPhotoUrl\": \"https://<my_domain>/ncsphoto/1wsMlOd3tVC7boygqBO8wMT9KzA0D6tqzpbs-Uw0Ioi-dtynkoFWsl46as__TDFU?fromEmail=1\",\n            \"url\": \"/services/data/v58.0/connect/user-profiles/005.../photo\"\n        },\n        \"reputation\": null,\n        \"title\": null,\n        \"type\": \"User\",\n        \"url\": \"/services/data/v58.0/chatter/users/005...\",\n        \"userType\": \"Internal\"\n    }\n}"
    }
  ]
}