Back to Collection Items
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loHttp = createobject("CkHttp")
// Adds the "Authorization: Bearer <access_token>" header.
loHttp.AuthToken = "<access_token>"
loResp = loHttp.QuickRequest("POST","message&recipients=<USER1_ID>,<USER2_ID>")
if (loHttp.LastMethodSuccess = .F.) then
? loHttp.LastErrorText
release loHttp
return
endif
loSbResponseBody = createobject("CkStringBuilder")
loResp.GetBodySb(loSbResponseBody)
loJResp = createobject("CkJsonObject")
loJResp.LoadSb(loSbResponseBody)
loJResp.EmitCompact = .F.
? "Response Body:"
? loJResp.Emit()
lnRespStatusCode = loResp.StatusCode
? "Response Status Code = " + str(lnRespStatusCode)
if (lnRespStatusCode >= 400) then
? "Response Header:"
? loResp.Header
? "Failed."
release loResp
release loHttp
release loSbResponseBody
release loJResp
return
endif
release loResp
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "body": {
// "isRichText": null,
// "messageSegments": [
// ],
// "text": "This is a private message"
// },
// "conversationId": "03M...",
// "conversationUrl": "/services/data/v58.0/chatter/users/me/conversations/03M...",
// "id": "03J...",
// "recipients": [
// {
// "additionalLabel": null,
// "communityNickname": "automatedprocess",
// "companyName": "Salesforce",
// "displayName": "Automated Process",
// "firstName": "Automated",
// "id": "005...",
// "isActive": true,
// "isInThisCommunity": true,
// "lastName": "Process",
// "motif": {
// "color": "1B96FF",
// "largeIconUrl": "/img/icon/profile64.png",
// "mediumIconUrl": "/img/icon/profile32.png",
// "smallIconUrl": "/img/icon/profile16.png",
// "svgIconUrl": null
// },
// "mySubscription": null,
// "name": "Automated Process",
// "outOfOffice": {
// "message": ""
// },
// "photo": {
// "fullEmailPhotoUrl": "https://<my_domain>/img/userprofile/default_profile_200_v2.png?fromEmail=1",
// "largePhotoUrl": "https://<my_domain>/profilephoto/005/F",
// "mediumPhotoUrl": "https://<my_domain>/profilephoto/005/M",
// "photoVersionId": null,
// "smallPhotoUrl": "https://<my_domain>/profilephoto/005/T",
// "standardEmailPhotoUrl": "https://<my_domain>/img/userprofile/default_profile_45_v2.png?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": "System"
// },
// {
// "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"
// }
// ],
// "sender": {
// "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"
// },
// "sendingCommunity": null,
// "sentDate": "<datetime>",
// "url": "/services/data/v58.0/chatter/users/me/messages/03J..."
// }
// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
lcIsRichText = loJResp.StringOf("body.isRichText")
lcText = loJResp.StringOf("body.text")
lcConversationId = loJResp.StringOf("conversationId")
lcConversationUrl = loJResp.StringOf("conversationUrl")
lcId = loJResp.StringOf("id")
lcAdditionalLabel = loJResp.StringOf("sender.additionalLabel")
lcCommunityNickname = loJResp.StringOf("sender.communityNickname")
lcCompanyName = loJResp.StringOf("sender.companyName")
lcDisplayName = loJResp.StringOf("sender.displayName")
lcFirstName = loJResp.StringOf("sender.firstName")
lcId = loJResp.StringOf("sender.id")
llIsActive = loJResp.BoolOf("sender.isActive")
llIsInThisCommunity = loJResp.BoolOf("sender.isInThisCommunity")
lcLastName = loJResp.StringOf("sender.lastName")
lcColor = loJResp.StringOf("sender.motif.color")
lcLargeIconUrl = loJResp.StringOf("sender.motif.largeIconUrl")
lcMediumIconUrl = loJResp.StringOf("sender.motif.mediumIconUrl")
lcSmallIconUrl = loJResp.StringOf("sender.motif.smallIconUrl")
lcSvgIconUrl = loJResp.StringOf("sender.motif.svgIconUrl")
lcMySubscription = loJResp.StringOf("sender.mySubscription")
lcName = loJResp.StringOf("sender.name")
lcMessage = loJResp.StringOf("sender.outOfOffice.message")
lcFullEmailPhotoUrl = loJResp.StringOf("sender.photo.fullEmailPhotoUrl")
lcLargePhotoUrl = loJResp.StringOf("sender.photo.largePhotoUrl")
lcMediumPhotoUrl = loJResp.StringOf("sender.photo.mediumPhotoUrl")
lcPhotoVersionId = loJResp.StringOf("sender.photo.photoVersionId")
lcSmallPhotoUrl = loJResp.StringOf("sender.photo.smallPhotoUrl")
lcStandardEmailPhotoUrl = loJResp.StringOf("sender.photo.standardEmailPhotoUrl")
lcV_Url = loJResp.StringOf("sender.photo.url")
lcReputation = loJResp.StringOf("sender.reputation")
lcTitle = loJResp.StringOf("sender.title")
lcV_Type = loJResp.StringOf("sender.type")
lcSenderUrl = loJResp.StringOf("sender.url")
lcUserType = loJResp.StringOf("sender.userType")
lcSendingCommunity = loJResp.StringOf("sendingCommunity")
lcSentDate = loJResp.StringOf("sentDate")
lcUrl = loJResp.StringOf("url")
i = 0
lnCount_i = loJResp.SizeOfArray("body.messageSegments")
do while i < lnCount_i
loJResp.I = i
i = i + 1
enddo
i = 0
lnCount_i = loJResp.SizeOfArray("recipients")
do while i < lnCount_i
loJResp.I = i
lcAdditionalLabel = loJResp.StringOf("recipients[i].additionalLabel")
lcCommunityNickname = loJResp.StringOf("recipients[i].communityNickname")
lcCompanyName = loJResp.StringOf("recipients[i].companyName")
lcDisplayName = loJResp.StringOf("recipients[i].displayName")
lcFirstName = loJResp.StringOf("recipients[i].firstName")
lcId = loJResp.StringOf("recipients[i].id")
llIsActive = loJResp.BoolOf("recipients[i].isActive")
llIsInThisCommunity = loJResp.BoolOf("recipients[i].isInThisCommunity")
lcLastName = loJResp.StringOf("recipients[i].lastName")
lcMotifColor = loJResp.StringOf("recipients[i].motif.color")
lcMotifLargeIconUrl = loJResp.StringOf("recipients[i].motif.largeIconUrl")
lcMotifMediumIconUrl = loJResp.StringOf("recipients[i].motif.mediumIconUrl")
lcMotifSmallIconUrl = loJResp.StringOf("recipients[i].motif.smallIconUrl")
lcMotifSvgIconUrl = loJResp.StringOf("recipients[i].motif.svgIconUrl")
lcMySubscription = loJResp.StringOf("recipients[i].mySubscription")
lcName = loJResp.StringOf("recipients[i].name")
lcOutOfOfficeMessage = loJResp.StringOf("recipients[i].outOfOffice.message")
lcPhotoFullEmailPhotoUrl = loJResp.StringOf("recipients[i].photo.fullEmailPhotoUrl")
lcPhotoLargePhotoUrl = loJResp.StringOf("recipients[i].photo.largePhotoUrl")
lcPhotoMediumPhotoUrl = loJResp.StringOf("recipients[i].photo.mediumPhotoUrl")
lcPhotoPhotoVersionId = loJResp.StringOf("recipients[i].photo.photoVersionId")
lcPhotoSmallPhotoUrl = loJResp.StringOf("recipients[i].photo.smallPhotoUrl")
lcPhotoStandardEmailPhotoUrl = loJResp.StringOf("recipients[i].photo.standardEmailPhotoUrl")
lcPhotoUrl = loJResp.StringOf("recipients[i].photo.url")
lcReputation = loJResp.StringOf("recipients[i].reputation")
lcTitle = loJResp.StringOf("recipients[i].title")
lcV_type = loJResp.StringOf("recipients[i].type")
lcUrl = loJResp.StringOf("recipients[i].url")
lcUserType = loJResp.StringOf("recipients[i].userType")
i = i + 1
enddo
release loHttp
release loSbResponseBody
release loJResp
Curl Command
curl -X POST
-H "Authorization: Bearer <access_token>"
https://domain.com/services/data/v{{version}}/chatter/users/me/messages?text=This is a private message&recipients=<USER1_ID>,<USER2_ID>
Postman Collection Item JSON
{
"name": "User Messages, General",
"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/users/me/messages?text=This is a private message&recipients=<USER1_ID>,<USER2_ID>",
"host": [
"{{_endpoint}}"
],
"path": [
"services",
"data",
"v{{version}}",
"chatter",
"users",
"me",
"messages"
],
"query": [
{
"key": "text",
"value": "This is a private message"
},
{
"key": "inReplyTo",
"value": "<MESSAGE_ID>",
"description": "ID of an existing message that identifies which conversation this message is part of. Specify either recipients or inReplyTo. Specify one or the other, not both.",
"disabled": true
},
{
"key": "recipients",
"value": "<USER1_ID>,<USER2_ID>",
"description": "Comma-separated list of User IDs"
}
]
},
"description": "Returns all the messages for all the private conversations for the context user. Also used to search across all messages and post a message.\nTo return all private conversations for the context user, see User Conversations, General.\n\nhttps://developer.salesforce.com/docs/atlas.en-us.chatterapi.meta/chatterapi/connect_resources_users_messages_general.htm"
},
"response": [
{
"name": "Successful User Messages, General",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "{{_endpoint}}/services/data/v{{version}}/chatter/users/me/messages?text=This is a private message&recipients=0052o00000DKQasAAH",
"host": [
"{{_endpoint}}"
],
"path": [
"services",
"data",
"v{{version}}",
"chatter",
"users",
"me",
"messages"
],
"query": [
{
"key": "text",
"value": "This is a private message"
},
{
"key": "inReplyTo",
"value": "<MESSAGE_ID>",
"description": "ID of an existing message that identifies which conversation this message is part of. Specify either recipients or inReplyTo. Specify one or the other, not both.",
"disabled": true
},
{
"key": "recipients",
"value": "0052o00000DKQasAAH",
"description": "Comma-separated list of User IDs"
}
]
}
},
"status": "Created",
"code": 201,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Date",
"value": "Mon, 20 Nov 2023 16:22:22 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\": null,\n \"messageSegments\": [],\n \"text\": \"This is a private message\"\n },\n \"conversationId\": \"03M...\",\n \"conversationUrl\": \"/services/data/v58.0/chatter/users/me/conversations/03M...\",\n \"id\": \"03J...\",\n \"recipients\": [\n {\n \"additionalLabel\": null,\n \"communityNickname\": \"automatedprocess\",\n \"companyName\": \"Salesforce\",\n \"displayName\": \"Automated Process\",\n \"firstName\": \"Automated\",\n \"id\": \"005...\",\n \"isActive\": true,\n \"isInThisCommunity\": true,\n \"lastName\": \"Process\",\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\": \"Automated Process\",\n \"outOfOffice\": {\n \"message\": \"\"\n },\n \"photo\": {\n \"fullEmailPhotoUrl\": \"https://<my_domain>/img/userprofile/default_profile_200_v2.png?fromEmail=1\",\n \"largePhotoUrl\": \"https://<my_domain>/profilephoto/005/F\",\n \"mediumPhotoUrl\": \"https://<my_domain>/profilephoto/005/M\",\n \"photoVersionId\": null,\n \"smallPhotoUrl\": \"https://<my_domain>/profilephoto/005/T\",\n \"standardEmailPhotoUrl\": \"https://<my_domain>/img/userprofile/default_profile_45_v2.png?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\": \"System\"\n },\n {\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 ],\n \"sender\": {\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 \"sendingCommunity\": null,\n \"sentDate\": \"<datetime>\",\n \"url\": \"/services/data/v58.0/chatter/users/me/messages/03J...\"\n}"
}
]
}