Chilkat Online Tools

PureBasic / Salesforce Platform APIs / List of Groups - POST

Back to Collection Items

IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkHttpResponse.pb"

Procedure ChilkatExample()

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

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    ; Adds the "Authorization: Bearer <access_token>" header.
    CkHttp::setCkAuthToken(http, "<access_token>")

    resp.i = CkHttp::ckQuickRequest(http,"POST","=true")
    If CkHttp::ckLastMethodSuccess(http) = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        ProcedureReturn
    EndIf

    sbResponseBody.i = CkStringBuilder::ckCreate()
    If sbResponseBody.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkHttpResponse::ckGetBodySb(resp,sbResponseBody)

    jResp.i = CkJsonObject::ckCreate()
    If jResp.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckLoadSb(jResp,sbResponseBody)
    CkJsonObject::setCkEmitCompact(jResp, 0)

    Debug "Response Body:"
    Debug CkJsonObject::ckEmit(jResp)

    respStatusCode.i = CkHttpResponse::ckStatusCode(resp)
    Debug "Response Status Code = " + Str(respStatusCode)
    If respStatusCode >= 400
        Debug "Response Header:"
        Debug CkHttpResponse::ckHeader(resp)
        Debug "Failed."
        CkHttpResponse::ckDispose(resp)

        CkHttp::ckDispose(http)
        CkStringBuilder::ckDispose(sbResponseBody)
        CkJsonObject::ckDispose(jResp)
        ProcedureReturn
    EndIf

    CkHttpResponse::ckDispose(resp)

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

    ; {
    ;   "additionalLabel": "Private With Customers",
    ;   "announcement": null,
    ;   "bannerPhoto": {
    ;     "bannerPhotoUrl": "https://<my_domain>/profilephoto/0F9/B",
    ;     "bannerPhotoVersionId": null,
    ;     "url": "/services/data/v58.0/chatter/groups/0F9.../banner-photo"
    ;   },
    ;   "canHaveChatterGuests": true,
    ;   "community": null,
    ;   "description": "Created via API",
    ;   "emailToChatterAddress": "0F9...@post.2o-i6mbeaq.eu25.chatter.salesforce.com",
    ;   "fileCount": 0,
    ;   "id": "0F9...",
    ;   "information": {
    ;     "text": null,
    ;     "title": null
    ;   },
    ;   "isArchived": false,
    ;   "isAutoArchiveDisabled": false,
    ;   "isBroadcast": false,
    ;   "lastFeedElementPostDate": "2023-11-22T11:29:05.000Z",
    ;   "memberCount": 1,
    ;   "motif": {
    ;     "color": "1B96FF",
    ;     "largeIconUrl": "/img/icon/groups64.png",
    ;     "mediumIconUrl": "/img/icon/groups32.png",
    ;     "smallIconUrl": "/img/icon/groups16.png",
    ;     "svgIconUrl": null
    ;   },
    ;   "myRole": "GroupOwner",
    ;   "mySubscription": {
    ;     "id": "0FB...",
    ;     "url": "/services/data/v58.0/chatter/group-memberships/0FB..."
    ;   },
    ;   "name": "New Chatter Group  (Private Access)",
    ;   "owner": {
    ;     "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"
    ;   },
    ;   "pendingRequests": 0,
    ;   "photo": {
    ;     "fullEmailPhotoUrl": "https://<my_domain>/img/userprofile/default_group_profile_200_v2.png?fromEmail=1",
    ;     "largePhotoUrl": "https://<my_domain>/profilephoto/0F9/F",
    ;     "mediumPhotoUrl": "https://<my_domain>/profilephoto/0F9/M",
    ;     "photoVersionId": null,
    ;     "smallPhotoUrl": "https://<my_domain>/profilephoto/0F9/T",
    ;     "standardEmailPhotoUrl": "https://<my_domain>/img/userprofile/default_group_profile_45_v2.png?fromEmail=1",
    ;     "url": "/services/data/v58.0/chatter/groups/0F9.../photo"
    ;   },
    ;   "type": "CollaborationGroup",
    ;   "url": "/services/data/v58.0/chatter/groups/0F9...",
    ;   "visibility": "PrivateAccess"
    ; }

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

    additionalLabel.s = CkJsonObject::ckStringOf(jResp,"additionalLabel")
    announcement.s = CkJsonObject::ckStringOf(jResp,"announcement")
    BannerPhotoUrl.s = CkJsonObject::ckStringOf(jResp,"bannerPhoto.bannerPhotoUrl")
    BannerPhotoVersionId.s = CkJsonObject::ckStringOf(jResp,"bannerPhoto.bannerPhotoVersionId")
    v_Url.s = CkJsonObject::ckStringOf(jResp,"bannerPhoto.url")
    canHaveChatterGuests.i = CkJsonObject::ckBoolOf(jResp,"canHaveChatterGuests")
    community.s = CkJsonObject::ckStringOf(jResp,"community")
    description.s = CkJsonObject::ckStringOf(jResp,"description")
    emailToChatterAddress.s = CkJsonObject::ckStringOf(jResp,"emailToChatterAddress")
    fileCount.i = CkJsonObject::ckIntOf(jResp,"fileCount")
    id.s = CkJsonObject::ckStringOf(jResp,"id")
    Text.s = CkJsonObject::ckStringOf(jResp,"information.text")
    Title.s = CkJsonObject::ckStringOf(jResp,"information.title")
    isArchived.i = CkJsonObject::ckBoolOf(jResp,"isArchived")
    isAutoArchiveDisabled.i = CkJsonObject::ckBoolOf(jResp,"isAutoArchiveDisabled")
    isBroadcast.i = CkJsonObject::ckBoolOf(jResp,"isBroadcast")
    lastFeedElementPostDate.s = CkJsonObject::ckStringOf(jResp,"lastFeedElementPostDate")
    memberCount.i = CkJsonObject::ckIntOf(jResp,"memberCount")
    Color.s = CkJsonObject::ckStringOf(jResp,"motif.color")
    LargeIconUrl.s = CkJsonObject::ckStringOf(jResp,"motif.largeIconUrl")
    MediumIconUrl.s = CkJsonObject::ckStringOf(jResp,"motif.mediumIconUrl")
    SmallIconUrl.s = CkJsonObject::ckStringOf(jResp,"motif.smallIconUrl")
    SvgIconUrl.s = CkJsonObject::ckStringOf(jResp,"motif.svgIconUrl")
    myRole.s = CkJsonObject::ckStringOf(jResp,"myRole")
    Id.s = CkJsonObject::ckStringOf(jResp,"mySubscription.id")
    mySubscriptionUrl.s = CkJsonObject::ckStringOf(jResp,"mySubscription.url")
    name.s = CkJsonObject::ckStringOf(jResp,"name")
    AdditionalLabel.s = CkJsonObject::ckStringOf(jResp,"owner.additionalLabel")
    CommunityNickname.s = CkJsonObject::ckStringOf(jResp,"owner.communityNickname")
    CompanyName.s = CkJsonObject::ckStringOf(jResp,"owner.companyName")
    DisplayName.s = CkJsonObject::ckStringOf(jResp,"owner.displayName")
    FirstName.s = CkJsonObject::ckStringOf(jResp,"owner.firstName")
    ownerId.s = CkJsonObject::ckStringOf(jResp,"owner.id")
    IsActive.i = CkJsonObject::ckBoolOf(jResp,"owner.isActive")
    IsInThisCommunity.i = CkJsonObject::ckBoolOf(jResp,"owner.isInThisCommunity")
    LastName.s = CkJsonObject::ckStringOf(jResp,"owner.lastName")
    MotifColor.s = CkJsonObject::ckStringOf(jResp,"owner.motif.color")
    MotifLargeIconUrl.s = CkJsonObject::ckStringOf(jResp,"owner.motif.largeIconUrl")
    MotifMediumIconUrl.s = CkJsonObject::ckStringOf(jResp,"owner.motif.mediumIconUrl")
    MotifSmallIconUrl.s = CkJsonObject::ckStringOf(jResp,"owner.motif.smallIconUrl")
    MotifSvgIconUrl.s = CkJsonObject::ckStringOf(jResp,"owner.motif.svgIconUrl")
    MySubscription.s = CkJsonObject::ckStringOf(jResp,"owner.mySubscription")
    Name.s = CkJsonObject::ckStringOf(jResp,"owner.name")
    Message.s = CkJsonObject::ckStringOf(jResp,"owner.outOfOffice.message")
    FullEmailPhotoUrl.s = CkJsonObject::ckStringOf(jResp,"owner.photo.fullEmailPhotoUrl")
    LargePhotoUrl.s = CkJsonObject::ckStringOf(jResp,"owner.photo.largePhotoUrl")
    MediumPhotoUrl.s = CkJsonObject::ckStringOf(jResp,"owner.photo.mediumPhotoUrl")
    PhotoVersionId.s = CkJsonObject::ckStringOf(jResp,"owner.photo.photoVersionId")
    SmallPhotoUrl.s = CkJsonObject::ckStringOf(jResp,"owner.photo.smallPhotoUrl")
    StandardEmailPhotoUrl.s = CkJsonObject::ckStringOf(jResp,"owner.photo.standardEmailPhotoUrl")
    PhotoUrl.s = CkJsonObject::ckStringOf(jResp,"owner.photo.url")
    Reputation.s = CkJsonObject::ckStringOf(jResp,"owner.reputation")
    ownerTitle.s = CkJsonObject::ckStringOf(jResp,"owner.title")
    v_Type.s = CkJsonObject::ckStringOf(jResp,"owner.type")
    ownerUrl.s = CkJsonObject::ckStringOf(jResp,"owner.url")
    UserType.s = CkJsonObject::ckStringOf(jResp,"owner.userType")
    pendingRequests.i = CkJsonObject::ckIntOf(jResp,"pendingRequests")
    photoFullEmailPhotoUrl.s = CkJsonObject::ckStringOf(jResp,"photo.fullEmailPhotoUrl")
    photoLargePhotoUrl.s = CkJsonObject::ckStringOf(jResp,"photo.largePhotoUrl")
    photoMediumPhotoUrl.s = CkJsonObject::ckStringOf(jResp,"photo.mediumPhotoUrl")
    photoPhotoVersionId.s = CkJsonObject::ckStringOf(jResp,"photo.photoVersionId")
    photoSmallPhotoUrl.s = CkJsonObject::ckStringOf(jResp,"photo.smallPhotoUrl")
    photoStandardEmailPhotoUrl.s = CkJsonObject::ckStringOf(jResp,"photo.standardEmailPhotoUrl")
    photoUrl.s = CkJsonObject::ckStringOf(jResp,"photo.url")
    v_type.s = CkJsonObject::ckStringOf(jResp,"type")
    url.s = CkJsonObject::ckStringOf(jResp,"url")
    visibility.s = CkJsonObject::ckStringOf(jResp,"visibility")


    CkHttp::ckDispose(http)
    CkStringBuilder::ckDispose(sbResponseBody)
    CkJsonObject::ckDispose(jResp)


    ProcedureReturn
EndProcedure

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
https://domain.com/services/data/v{{version}}/chatter/groups?name=New Chatter Group  (Private Access)&visibility=PrivateAccess&description=Created via API&information=Private Information&isArchived=false&isAutoArchiveDisabled=false&isBroadcast=false&canHaveChatterGuests	=true

Postman Collection Item JSON

{
  "name": "List of Groups - POST",
  "event": [
    {
      "listen": "prerequest",
      "script": {
        "exec": [
          ""
        ],
        "type": "text/javascript"
      }
    },
    {
      "listen": "test",
      "script": {
        "exec": [
          ""
        ],
        "type": "text/javascript"
      }
    }
  ],
  "protocolProfileBehavior": {
    "disabledSystemHeaders": {}
  },
  "request": {
    "method": "POST",
    "header": [
    ],
    "url": {
      "raw": "{{_endpoint}}/services/data/v{{version}}/chatter/groups?name=New Chatter Group  (Private Access)&visibility=PrivateAccess&description=Created via API&information=Private Information&isArchived=false&isAutoArchiveDisabled=false&isBroadcast=false&canHaveChatterGuests\t=true",
      "host": [
        "{{_endpoint}}"
      ],
      "path": [
        "services",
        "data",
        "v{{version}}",
        "chatter",
        "groups"
      ],
      "query": [
        {
          "key": "name",
          "value": "New Chatter Group  (Private Access)"
        },
        {
          "key": "visibility",
          "value": "PrivateAccess",
          "description": "PrivateAccess—Only members of the group can see posts to this group.\nPublicAccess—All users within the community can see posts to this group.\nUnlisted—Reserved for future use."
        },
        {
          "key": "description",
          "value": "Created via API"
        },
        {
          "key": "information",
          "value": "Private Information",
          "description": "If the group is private, the “Information” section is visible only to members."
        },
        {
          "key": "isArchived",
          "value": "false"
        },
        {
          "key": "isAutoArchiveDisabled",
          "value": "false",
          "description": "true if automatic archiving is turned off for the group, false otherwise. Defaults to false. If true, if there are no posts or comments for 90 days the group is archived."
        },
        {
          "key": "isBroadcast",
          "value": "false",
          "description": "true if only group owners and managers can create posts in the group, false otherwise."
        },
        {
          "key": "canHaveChatterGuests\t",
          "value": "true",
          "description": "true if this group allows Chatter customers, false otherwise. After this property is set to true, it cannot be set to false."
        }
      ]
    },
    "description": "A list of all the groups in the organization. Get information about groups or create a group.\n\nhttps://developer.salesforce.com/docs/atlas.en-us.chatterapi.meta/chatterapi/connect_resources_groups_ListOfGroups.htm"
  },
  "response": [
    {
      "name": "Successful List of Groups - POST",
      "originalRequest": {
        "method": "POST",
        "header": [
        ],
        "url": {
          "raw": "{{_endpoint}}/services/data/v{{version}}/chatter/groups?name=New Chatter Group  (Private Access)&visibility=PrivateAccess&description=Created via API&information=Private Information&isArchived=false&isAutoArchiveDisabled=false&isBroadcast=false&canHaveChatterGuests\t=true",
          "host": [
            "{{_endpoint}}"
          ],
          "path": [
            "services",
            "data",
            "v{{version}}",
            "chatter",
            "groups"
          ],
          "query": [
            {
              "key": "name",
              "value": "New Chatter Group  (Private Access)"
            },
            {
              "key": "visibility",
              "value": "PrivateAccess",
              "description": "PrivateAccess—Only members of the group can see posts to this group.\nPublicAccess—All users within the community can see posts to this group.\nUnlisted—Reserved for future use."
            },
            {
              "key": "description",
              "value": "Created via API"
            },
            {
              "key": "information",
              "value": "Private Information",
              "description": "If the group is private, the “Information” section is visible only to members."
            },
            {
              "key": "isArchived",
              "value": "false"
            },
            {
              "key": "isAutoArchiveDisabled",
              "value": "false",
              "description": "true if automatic archiving is turned off for the group, false otherwise. Defaults to false. If true, if there are no posts or comments for 90 days the group is archived."
            },
            {
              "key": "isBroadcast",
              "value": "false",
              "description": "true if only group owners and managers can create posts in the group, false otherwise."
            },
            {
              "key": "canHaveChatterGuests\t",
              "value": "true",
              "description": "true if this group allows Chatter customers, false otherwise. After this property is set to true, it cannot be set to false."
            }
          ]
        }
      },
      "status": "Created",
      "code": 201,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Date",
          "value": "Wed, 22 Nov 2023 11:29:04 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    \"additionalLabel\": \"Private With Customers\",\n    \"announcement\": null,\n    \"bannerPhoto\": {\n        \"bannerPhotoUrl\": \"https://<my_domain>/profilephoto/0F9/B\",\n        \"bannerPhotoVersionId\": null,\n        \"url\": \"/services/data/v58.0/chatter/groups/0F9.../banner-photo\"\n    },\n    \"canHaveChatterGuests\": true,\n    \"community\": null,\n    \"description\": \"Created via API\",\n    \"emailToChatterAddress\": \"0F9...@post.2o-i6mbeaq.eu25.chatter.salesforce.com\",\n    \"fileCount\": 0,\n    \"id\": \"0F9...\",\n    \"information\": {\n        \"text\": null,\n        \"title\": null\n    },\n    \"isArchived\": false,\n    \"isAutoArchiveDisabled\": false,\n    \"isBroadcast\": false,\n    \"lastFeedElementPostDate\": \"2023-11-22T11:29:05.000Z\",\n    \"memberCount\": 1,\n    \"motif\": {\n        \"color\": \"1B96FF\",\n        \"largeIconUrl\": \"/img/icon/groups64.png\",\n        \"mediumIconUrl\": \"/img/icon/groups32.png\",\n        \"smallIconUrl\": \"/img/icon/groups16.png\",\n        \"svgIconUrl\": null\n    },\n    \"myRole\": \"GroupOwner\",\n    \"mySubscription\": {\n        \"id\": \"0FB...\",\n        \"url\": \"/services/data/v58.0/chatter/group-memberships/0FB...\"\n    },\n    \"name\": \"New Chatter Group  (Private Access)\",\n    \"owner\": {\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    \"pendingRequests\": 0,\n    \"photo\": {\n        \"fullEmailPhotoUrl\": \"https://<my_domain>/img/userprofile/default_group_profile_200_v2.png?fromEmail=1\",\n        \"largePhotoUrl\": \"https://<my_domain>/profilephoto/0F9/F\",\n        \"mediumPhotoUrl\": \"https://<my_domain>/profilephoto/0F9/M\",\n        \"photoVersionId\": null,\n        \"smallPhotoUrl\": \"https://<my_domain>/profilephoto/0F9/T\",\n        \"standardEmailPhotoUrl\": \"https://<my_domain>/img/userprofile/default_group_profile_45_v2.png?fromEmail=1\",\n        \"url\": \"/services/data/v58.0/chatter/groups/0F9.../photo\"\n    },\n    \"type\": \"CollaborationGroup\",\n    \"url\": \"/services/data/v58.0/chatter/groups/0F9...\",\n    \"visibility\": \"PrivateAccess\"\n}"
    }
  ]
}