Chilkat Online Tools

C++ / Salesforce Platform APIs / User Messages, General

Back to Collection Items

#include <CkHttp.h>
#include <CkHttpResponse.h>
#include <CkStringBuilder.h>
#include <CkJsonObject.h>

void ChilkatSample(void)
    {
    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkHttp http;
    bool success;

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

    CkHttpResponse *resp = http.QuickRequest("POST","message&recipients=<USER1_ID>,<USER2_ID>");
    if (http.get_LastMethodSuccess() == false) {
        std::cout << http.lastErrorText() << "\r\n";
        return;
    }

    CkStringBuilder sbResponseBody;
    resp->GetBodySb(sbResponseBody);

    CkJsonObject jResp;
    jResp.LoadSb(sbResponseBody);
    jResp.put_EmitCompact(false);

    std::cout << "Response Body:" << "\r\n";
    std::cout << jResp.emit() << "\r\n";

    int respStatusCode = resp->get_StatusCode();
    std::cout << "Response Status Code = " << respStatusCode << "\r\n";
    if (respStatusCode >= 400) {
        std::cout << "Response Header:" << "\r\n";
        std::cout << resp->header() << "\r\n";
        std::cout << "Failed." << "\r\n";
        delete resp;
        return;
    }

    delete resp;

    // 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

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.

    const char *additionalLabel = 0;
    const char *communityNickname = 0;
    const char *companyName = 0;
    const char *displayName = 0;
    const char *firstName = 0;
    bool isActive;
    bool isInThisCommunity;
    const char *lastName = 0;
    const char *motifColor = 0;
    const char *motifLargeIconUrl = 0;
    const char *motifMediumIconUrl = 0;
    const char *motifSmallIconUrl = 0;
    const char *motifSvgIconUrl = 0;
    const char *mySubscription = 0;
    const char *name = 0;
    const char *outOfOfficeMessage = 0;
    const char *photoFullEmailPhotoUrl = 0;
    const char *photoLargePhotoUrl = 0;
    const char *photoMediumPhotoUrl = 0;
    const char *photoPhotoVersionId = 0;
    const char *photoSmallPhotoUrl = 0;
    const char *photoStandardEmailPhotoUrl = 0;
    const char *photoUrl = 0;
    const char *reputation = 0;
    const char *title = 0;
    const char *v_type = 0;
    const char *userType = 0;

    const char *IsRichText = jResp.stringOf("body.isRichText");
    const char *Text = jResp.stringOf("body.text");
    const char *conversationId = jResp.stringOf("conversationId");
    const char *conversationUrl = jResp.stringOf("conversationUrl");
    const char *id = jResp.stringOf("id");
    const char *AdditionalLabel = jResp.stringOf("sender.additionalLabel");
    const char *CommunityNickname = jResp.stringOf("sender.communityNickname");
    const char *CompanyName = jResp.stringOf("sender.companyName");
    const char *DisplayName = jResp.stringOf("sender.displayName");
    const char *FirstName = jResp.stringOf("sender.firstName");
    const char *Id = jResp.stringOf("sender.id");
    bool IsActive = jResp.BoolOf("sender.isActive");
    bool IsInThisCommunity = jResp.BoolOf("sender.isInThisCommunity");
    const char *LastName = jResp.stringOf("sender.lastName");
    const char *Color = jResp.stringOf("sender.motif.color");
    const char *LargeIconUrl = jResp.stringOf("sender.motif.largeIconUrl");
    const char *MediumIconUrl = jResp.stringOf("sender.motif.mediumIconUrl");
    const char *SmallIconUrl = jResp.stringOf("sender.motif.smallIconUrl");
    const char *SvgIconUrl = jResp.stringOf("sender.motif.svgIconUrl");
    const char *MySubscription = jResp.stringOf("sender.mySubscription");
    const char *Name = jResp.stringOf("sender.name");
    const char *Message = jResp.stringOf("sender.outOfOffice.message");
    const char *FullEmailPhotoUrl = jResp.stringOf("sender.photo.fullEmailPhotoUrl");
    const char *LargePhotoUrl = jResp.stringOf("sender.photo.largePhotoUrl");
    const char *MediumPhotoUrl = jResp.stringOf("sender.photo.mediumPhotoUrl");
    const char *PhotoVersionId = jResp.stringOf("sender.photo.photoVersionId");
    const char *SmallPhotoUrl = jResp.stringOf("sender.photo.smallPhotoUrl");
    const char *StandardEmailPhotoUrl = jResp.stringOf("sender.photo.standardEmailPhotoUrl");
    const char *v_Url = jResp.stringOf("sender.photo.url");
    const char *Reputation = jResp.stringOf("sender.reputation");
    const char *Title = jResp.stringOf("sender.title");
    const char *v_Type = jResp.stringOf("sender.type");
    const char *senderUrl = jResp.stringOf("sender.url");
    const char *UserType = jResp.stringOf("sender.userType");
    const char *sendingCommunity = jResp.stringOf("sendingCommunity");
    const char *sentDate = jResp.stringOf("sentDate");
    const char *url = jResp.stringOf("url");
    int i = 0;
    int count_i = jResp.SizeOfArray("body.messageSegments");
    while (i < count_i) {
        jResp.put_I(i);
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray("recipients");
    while (i < count_i) {
        jResp.put_I(i);
        additionalLabel = jResp.stringOf("recipients[i].additionalLabel");
        communityNickname = jResp.stringOf("recipients[i].communityNickname");
        companyName = jResp.stringOf("recipients[i].companyName");
        displayName = jResp.stringOf("recipients[i].displayName");
        firstName = jResp.stringOf("recipients[i].firstName");
        id = jResp.stringOf("recipients[i].id");
        isActive = jResp.BoolOf("recipients[i].isActive");
        isInThisCommunity = jResp.BoolOf("recipients[i].isInThisCommunity");
        lastName = jResp.stringOf("recipients[i].lastName");
        motifColor = jResp.stringOf("recipients[i].motif.color");
        motifLargeIconUrl = jResp.stringOf("recipients[i].motif.largeIconUrl");
        motifMediumIconUrl = jResp.stringOf("recipients[i].motif.mediumIconUrl");
        motifSmallIconUrl = jResp.stringOf("recipients[i].motif.smallIconUrl");
        motifSvgIconUrl = jResp.stringOf("recipients[i].motif.svgIconUrl");
        mySubscription = jResp.stringOf("recipients[i].mySubscription");
        name = jResp.stringOf("recipients[i].name");
        outOfOfficeMessage = jResp.stringOf("recipients[i].outOfOffice.message");
        photoFullEmailPhotoUrl = jResp.stringOf("recipients[i].photo.fullEmailPhotoUrl");
        photoLargePhotoUrl = jResp.stringOf("recipients[i].photo.largePhotoUrl");
        photoMediumPhotoUrl = jResp.stringOf("recipients[i].photo.mediumPhotoUrl");
        photoPhotoVersionId = jResp.stringOf("recipients[i].photo.photoVersionId");
        photoSmallPhotoUrl = jResp.stringOf("recipients[i].photo.smallPhotoUrl");
        photoStandardEmailPhotoUrl = jResp.stringOf("recipients[i].photo.standardEmailPhotoUrl");
        photoUrl = jResp.stringOf("recipients[i].photo.url");
        reputation = jResp.stringOf("recipients[i].reputation");
        title = jResp.stringOf("recipients[i].title");
        v_type = jResp.stringOf("recipients[i].type");
        url = jResp.stringOf("recipients[i].url");
        userType = jResp.stringOf("recipients[i].userType");
        i = i + 1;
    }
    }

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}"
    }
  ]
}