Chilkat Online Tools

TCL / Sunshine Conversations API / Join Conversation

Back to Collection Items

load ./chilkat.dll

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

set http [new_CkHttp]

CkHttp_put_BasicAuth $http 1
CkHttp_put_Login $http "username"
CkHttp_put_Password $http "password"

# Use this online tool to generate code from sample JSON: Generate Code to Create JSON

# The following JSON is sent in the request body.

# {
#   "userId": "42589ad070d43be9b00ff7e5",
#   "subscribeSDKClient": false
# }

set json [new_CkJsonObject]

CkJsonObject_UpdateString $json "userId" "42589ad070d43be9b00ff7e5"
CkJsonObject_UpdateBool $json "subscribeSDKClient" 0

CkHttp_SetRequestHeader $http "Content-Type" "application/json"

# resp is a CkHttpResponse
set resp [CkHttp_PostJson3 $http "https://domain.com/" "application/json" $json]
if {[CkHttp_get_LastMethodSuccess $http] == 0} then {
    puts [CkHttp_lastErrorText $http]
    delete_CkHttp $http
    delete_CkJsonObject $json
    exit
}

set sbResponseBody [new_CkStringBuilder]

CkHttpResponse_GetBodySb $resp $sbResponseBody

set jResp [new_CkJsonObject]

CkJsonObject_LoadSb $jResp $sbResponseBody
CkJsonObject_put_EmitCompact $jResp 0

puts "Response Body:"
puts [CkJsonObject_emit $jResp]

set respStatusCode [CkHttpResponse_get_StatusCode $resp]
puts "Response Status Code = $respStatusCode"
if {$respStatusCode >= 400} then {
    puts "Response Header:"
    puts [CkHttpResponse_header $resp]
    puts "Failed."
    delete_CkHttpResponse $resp

    delete_CkHttp $http
    delete_CkJsonObject $json
    delete_CkStringBuilder $sbResponseBody
    delete_CkJsonObject $jResp
    exit
}

delete_CkHttpResponse $resp

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

# {
#   "participant": {
#     "id": "c93bb9c14dde8ffb94564eae",
#     "userId": "42589ad070d43be9b00ff7e5",
#     "unreadCount": 0,
#     "clientAssociations": [
#       {
#         "type": "telegram",
#         "clientId": "42589ad070d43be9b00ff7e5"
#       },
#       {
#         "type": "telegram",
#         "clientId": "42589ad070d43be9b00ff7e5"
#       }
#     ],
#     "userExternalId": "your-own-id",
#     "lastRead": "2019-01-14T18:55:12.515Z"
#   }
# }

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

set Id [CkJsonObject_stringOf $jResp "participant.id"]
set UserId [CkJsonObject_stringOf $jResp "participant.userId"]
set UnreadCount [CkJsonObject_IntOf $jResp "participant.unreadCount"]
set UserExternalId [CkJsonObject_stringOf $jResp "participant.userExternalId"]
set LastRead [CkJsonObject_stringOf $jResp "participant.lastRead"]
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "participant.clientAssociations"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set v_type [CkJsonObject_stringOf $jResp "participant.clientAssociations[i].type"]
    set clientId [CkJsonObject_stringOf $jResp "participant.clientAssociations[i].clientId"]
    set i [expr $i + 1]
}

delete_CkHttp $http
delete_CkJsonObject $json
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jResp

Curl Command

curl -X POST
	-u 'username:password'
	-H "Content-Type: application/json"
	-d '{
    "userId": "42589ad070d43be9b00ff7e5",
    "subscribeSDKClient": false
}'
https://domain.com/

Postman Collection Item JSON

{
  "name": "Join Conversation",
  "_postman_id": "185b1369-9a43-41a4-a274-81fa30f2a53b",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"userId\": \"42589ad070d43be9b00ff7e5\",\n    \"subscribeSDKClient\": false\n}"
    },
    "url": "{{url}}/v2/apps/{{appId}}/conversations/{{conversationId}}/join",
    "description": "Adds a user to a conversation using either their userId or userExternalId. The endpoint only\nsupports adding a participant to a sdkGroup conversation.\n"
  },
  "response": [
    {
      "id": "019219b1-cf37-47f5-856f-f8bcace7ac4d",
      "name": "Too many participants",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "description": {
              "content": "Added as a part of security scheme: bearer",
              "type": "text/plain"
            },
            "key": "Authorization",
            "value": "Bearer <token>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"userId\": \"42589ad070d43be9b00ff7e5\",\n    \"subscribeSDKClient\": false\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/v2/apps/:appId/conversations/:conversationId/join",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "v2",
            "apps",
            ":appId",
            "conversations",
            ":conversationId",
            "join"
          ],
          "variable": [
            {
              "key": "appId"
            },
            {
              "key": "conversationId"
            }
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    },
    {
      "id": "30b353f8-bbca-47db-b21e-97218a2d50f0",
      "name": "Created",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "description": {
              "content": "Added as a part of security scheme: bearer",
              "type": "text/plain"
            },
            "key": "Authorization",
            "value": "Bearer <token>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"userId\": \"42589ad070d43be9b00ff7e5\",\n    \"subscribeSDKClient\": false\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/v2/apps/:appId/conversations/:conversationId/join",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "v2",
            "apps",
            ":appId",
            "conversations",
            ":conversationId",
            "join"
          ],
          "variable": [
            {
              "key": "appId"
            },
            {
              "key": "conversationId"
            }
          ]
        }
      },
      "status": "Created",
      "code": 201,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"participant\": {\n  \"id\": \"c93bb9c14dde8ffb94564eae\",\n  \"userId\": \"42589ad070d43be9b00ff7e5\",\n  \"unreadCount\": 0,\n  \"clientAssociations\": [\n   {\n    \"type\": \"telegram\",\n    \"clientId\": \"42589ad070d43be9b00ff7e5\"\n   },\n   {\n    \"type\": \"telegram\",\n    \"clientId\": \"42589ad070d43be9b00ff7e5\"\n   }\n  ],\n  \"userExternalId\": \"your-own-id\",\n  \"lastRead\": \"2019-01-14T18:55:12.515Z\"\n }\n}"
    },
    {
      "id": "a12e66e5-6748-4f9a-87a3-a5cefad55a7a",
      "name": "Conversation not found",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "description": {
              "content": "Added as a part of security scheme: bearer",
              "type": "text/plain"
            },
            "key": "Authorization",
            "value": "Bearer <token>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"userId\": \"42589ad070d43be9b00ff7e5\",\n    \"subscribeSDKClient\": false\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/v2/apps/:appId/conversations/:conversationId/join",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "v2",
            "apps",
            ":appId",
            "conversations",
            ":conversationId",
            "join"
          ],
          "variable": [
            {
              "key": "appId"
            },
            {
              "key": "conversationId"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}