Chilkat Online Tools

C / Sunshine Conversations API / List Clients

Back to Collection Items

#include <C_CkHttp.h>
#include <C_CkJsonObject.h>
#include <C_CkHttpResponse.h>
#include <C_CkStringBuilder.h>

void ChilkatSample(void)
    {
    HCkHttp http;
    BOOL success;
    HCkJsonObject queryParams;
    HCkHttpResponse resp;
    HCkStringBuilder sbResponseBody;
    HCkJsonObject jResp;
    int respStatusCode;
    const char *id;
    const char *v_type;
    const char *status;
    const char *integrationId;
    const char *externalId;
    const char *lastSeen;
    const char *linkedAt;
    const char *displayName;
    const char *avatarUrl;
    BOOL HasMore;
    const char *AfterCursor;
    const char *BeforeCursor;
    const char *Prev;
    const char *v_Next;
    int i;
    int count_i;

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

    http = CkHttp_Create();

    CkHttp_putBasicAuth(http,TRUE);
    CkHttp_putLogin(http,"username");
    CkHttp_putPassword(http,"password");

    queryParams = CkJsonObject_Create();
    CkJsonObject_UpdateString(queryParams,"page[after]","5e1606762556d93e9c176f69");
    CkJsonObject_UpdateString(queryParams,"page[before]","5e1606762556d93e9c176f69");
    CkJsonObject_UpdateInt(queryParams,"page[size]",10);

    resp = CkHttp_QuickRequestParams(http,"GET","https://domain.com/v2/apps/{{appId}}/users/:userIdOrExternalId/clients",queryParams);
    if (CkHttp_getLastMethodSuccess(http) == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkJsonObject_Dispose(queryParams);
        return;
    }

    sbResponseBody = CkStringBuilder_Create();
    CkHttpResponse_GetBodySb(resp,sbResponseBody);

    jResp = CkJsonObject_Create();
    CkJsonObject_LoadSb(jResp,sbResponseBody);
    CkJsonObject_putEmitCompact(jResp,FALSE);

    printf("Response Body:\n");
    printf("%s\n",CkJsonObject_emit(jResp));

    respStatusCode = CkHttpResponse_getStatusCode(resp);
    printf("Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        printf("Response Header:\n");
        printf("%s\n",CkHttpResponse_header(resp));
        printf("Failed.\n");
        CkHttpResponse_Dispose(resp);
        CkHttp_Dispose(http);
        CkJsonObject_Dispose(queryParams);
        CkStringBuilder_Dispose(sbResponseBody);
        CkJsonObject_Dispose(jResp);
        return;
    }

    CkHttpResponse_Dispose(resp);

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

    // {
    //   "clients": [
    //     {
    //       "id": "5c9a34160c89726709136733",
    //       "type": "telegram",
    //       "status": "active",
    //       "integrationId": "582dedf230e788746891281a",
    //       "externalId": "your-own-id",
    //       "lastSeen": "2020-08-20T16:13:07.462Z",
    //       "linkedAt": "2020-06-23T14:33:47.492Z",
    //       "displayName": "Steve",
    //       "avatarUrl": "http://FyCxWeGPlJnZUcHsnFgIcfwVDdHd.dpueX8iJUlDIHClHNkd2I20OTKQLPVs8bVOVUBbGvT1n-",
    //       "info": {},
    //       "raw": {}
    //     },
    //     {
    //       "id": "5c9a34160c89726709136733",
    //       "type": "telegram",
    //       "status": "active",
    //       "integrationId": "582dedf230e788746891281a",
    //       "externalId": "your-own-id",
    //       "lastSeen": "2020-08-20T16:13:07.462Z",
    //       "linkedAt": "2020-06-23T14:33:47.492Z",
    //       "displayName": "Steve",
    //       "avatarUrl": "http://TcKCiyuxrvZpuRTjBbrogTxoG.vjdxDLAN2iji7OauGJ5ui0l5aJDsCm+s5jxv+ORX6ILS-AiyUv,EWcEBviIVSpM1a05HdCgBkl22X",
    //       "info": {},
    //       "raw": {}
    //     }
    //   ],
    //   "meta": {
    //     "hasMore": false,
    //     "afterCursor": "55c8d9758590aa1900b9b9f6",
    //     "beforeCursor": "55c8d9758590aa1900b9b9f6"
    //   },
    //   "links": {
    //     "prev": "https://api.smooch.io/v2/apps?page[before]=fcafad804c39a39648004af9",
    //     "next": "https://api.smooch.io/v2/apps?page[after]=5ea868f862cdd24abf010b38"
    //   }
    // }

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

    HasMore = CkJsonObject_BoolOf(jResp,"meta.hasMore");
    AfterCursor = CkJsonObject_stringOf(jResp,"meta.afterCursor");
    BeforeCursor = CkJsonObject_stringOf(jResp,"meta.beforeCursor");
    Prev = CkJsonObject_stringOf(jResp,"links.prev");
    v_Next = CkJsonObject_stringOf(jResp,"links.next");
    i = 0;
    count_i = CkJsonObject_SizeOfArray(jResp,"clients");
    while (i < count_i) {
        CkJsonObject_putI(jResp,i);
        id = CkJsonObject_stringOf(jResp,"clients[i].id");
        v_type = CkJsonObject_stringOf(jResp,"clients[i].type");
        status = CkJsonObject_stringOf(jResp,"clients[i].status");
        integrationId = CkJsonObject_stringOf(jResp,"clients[i].integrationId");
        externalId = CkJsonObject_stringOf(jResp,"clients[i].externalId");
        lastSeen = CkJsonObject_stringOf(jResp,"clients[i].lastSeen");
        linkedAt = CkJsonObject_stringOf(jResp,"clients[i].linkedAt");
        displayName = CkJsonObject_stringOf(jResp,"clients[i].displayName");
        avatarUrl = CkJsonObject_stringOf(jResp,"clients[i].avatarUrl");
        i = i + 1;
    }



    CkHttp_Dispose(http);
    CkJsonObject_Dispose(queryParams);
    CkStringBuilder_Dispose(sbResponseBody);
    CkJsonObject_Dispose(jResp);

    }

Curl Command

curl -G -d "page[after]=5e1606762556d93e9c176f69"
	-d "page[before]=5e1606762556d93e9c176f69"
	-d "page[size]=10"
	-u 'username:password'
https://domain.com/v2/apps/{{appId}}/users/:userIdOrExternalId/clients

Postman Collection Item JSON

{
  "name": "List Clients",
  "_postman_id": "6302f027-d4a1-4272-a03c-276ea7ac4ac6",
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "{{url}}/v2/apps/{{appId}}/users/:userIdOrExternalId/clients?page[after]=5e1606762556d93e9c176f69&page[before]=5e1606762556d93e9c176f69&page[size]=10",
      "host": [
        "{{url}}"
      ],
      "path": [
        "v2",
        "apps",
        "{{appId}}",
        "users",
        ":userIdOrExternalId",
        "clients"
      ],
      "query": [
        {
          "key": "page[after]",
          "value": "5e1606762556d93e9c176f69",
          "description": "Contains parameters for applying cursor pagination."
        },
        {
          "key": "page[before]",
          "value": "5e1606762556d93e9c176f69",
          "description": "Contains parameters for applying cursor pagination."
        },
        {
          "key": "page[size]",
          "value": "10",
          "description": "Contains parameters for applying cursor pagination."
        }
      ],
      "variable": [
        {
          "key": "userIdOrExternalId"
        }
      ]
    },
    "description": "Get all the clients for a particular user, including both linked clients and pending clients.\nThis API is paginated through [cursor pagination](#section/Introduction/API-pagination-and-records-limits).\n\n```shell\n/v2/apps/:appId/users/:userId/clients?page[after]=5ebee0975ac5304b664a12fa\n```\n"
  },
  "response": [
    {
      "id": "2ec3b760-42a8-44d5-af25-526c4149390b",
      "name": "Ok",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": {
              "content": "Added as a part of security scheme: bearer",
              "type": "text/plain"
            },
            "key": "Authorization",
            "value": "Bearer <token>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/v2/apps/:appId/users/:userIdOrExternalId/clients?page[after]=5e1606762556d93e9c176f69&page[before]=5e1606762556d93e9c176f69&page[size]=10",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "v2",
            "apps",
            ":appId",
            "users",
            ":userIdOrExternalId",
            "clients"
          ],
          "query": [
            {
              "key": "page[after]",
              "value": "5e1606762556d93e9c176f69"
            },
            {
              "key": "page[before]",
              "value": "5e1606762556d93e9c176f69"
            },
            {
              "key": "page[size]",
              "value": "10"
            }
          ],
          "variable": [
            {
              "key": "appId"
            },
            {
              "key": "userIdOrExternalId"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"clients\": [\n  {\n   \"id\": \"5c9a34160c89726709136733\",\n   \"type\": \"telegram\",\n   \"status\": \"active\",\n   \"integrationId\": \"582dedf230e788746891281a\",\n   \"externalId\": \"your-own-id\",\n   \"lastSeen\": \"2020-08-20T16:13:07.462Z\",\n   \"linkedAt\": \"2020-06-23T14:33:47.492Z\",\n   \"displayName\": \"Steve\",\n   \"avatarUrl\": \"http://FyCxWeGPlJnZUcHsnFgIcfwVDdHd.dpueX8iJUlDIHClHNkd2I20OTKQLPVs8bVOVUBbGvT1n-\",\n   \"info\": {},\n   \"raw\": {}\n  },\n  {\n   \"id\": \"5c9a34160c89726709136733\",\n   \"type\": \"telegram\",\n   \"status\": \"active\",\n   \"integrationId\": \"582dedf230e788746891281a\",\n   \"externalId\": \"your-own-id\",\n   \"lastSeen\": \"2020-08-20T16:13:07.462Z\",\n   \"linkedAt\": \"2020-06-23T14:33:47.492Z\",\n   \"displayName\": \"Steve\",\n   \"avatarUrl\": \"http://TcKCiyuxrvZpuRTjBbrogTxoG.vjdxDLAN2iji7OauGJ5ui0l5aJDsCm+s5jxv+ORX6ILS-AiyUv,EWcEBviIVSpM1a05HdCgBkl22X\",\n   \"info\": {},\n   \"raw\": {}\n  }\n ],\n \"meta\": {\n  \"hasMore\": false,\n  \"afterCursor\": \"55c8d9758590aa1900b9b9f6\",\n  \"beforeCursor\": \"55c8d9758590aa1900b9b9f6\"\n },\n \"links\": {\n  \"prev\": \"https://api.smooch.io/v2/apps?page[before]=fcafad804c39a39648004af9\",\n  \"next\": \"https://api.smooch.io/v2/apps?page[after]=5ea868f862cdd24abf010b38\"\n }\n}"
    }
  ]
}