Chilkat Online Tools

C / Atlassian Confluence Cloud / Get space watchers

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 *v_type;
    const char *v_Type;
    const char *Path;
    int Width;
    int Height;
    BOOL IsDefault;
    const char *DisplayName;
    const char *AccountId;
    const char *AccountType;
    const char *v_Email;
    const char *PublicName;
    const char *Username;
    const char *UserKey;
    const char *Value;
    const char *PersonalValue;
    const char *spaceKey;
    const char *contentId;
    int j;
    int count_j;
    const char *operation;
    const char *targetType;
    int start;
    int limit;
    int size;
    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();

    queryParams = CkJsonObject_Create();
    CkJsonObject_UpdateString(queryParams,"start","<string>");
    CkJsonObject_UpdateString(queryParams,"limit","<string>");

    resp = CkHttp_QuickRequestParams(http,"GET","https://your-domain.atlassian.net/wiki/rest/api/space/:spaceKey/watch",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)

    // {
    //   "results": [
    //     {
    //       "type": "proident nisi dolo",
    //       "watcher": {
    //         "type": "veniam enim exercitation ",
    //         "profilePicture": {
    //           "path": "Duis velit",
    //           "width": -59620755,
    //           "height": 31433400,
    //           "isDefault": true
    //         },
    //         "displayName": "reprehenderit dolor ea magna",
    //         "accountId": "sint enim volupta",
    //         "accountType": "do ea ipsum ullamco",
    //         "email": "dolor",
    //         "publicName": "do aliqua",
    //         "username": "nisi officia",
    //         "userKey": "sint a",
    //         "operations": [
    //           {
    //             "operation": "move",
    //             "targetType": "attachment"
    //           },
    //           {
    //             "operation": "move",
    //             "targetType": "attachment"
    //           }
    //         ],
    //         "details": {
    //           "business": {
    //             "value": "<Error: Too many levels of nesting to fake this schema>"
    //           },
    //           "personal": {
    //             "value": "<Error: Too many levels of nesting to fake this schema>"
    //           }
    //         }
    //       },
    //       "spaceKey": "minim ex",
    //       "contentId": "do"
    //     },
    //     {
    //       "type": "ut in Duis ad",
    //       "watcher": {
    //         "type": "dolor id",
    //         "profilePicture": {
    //           "path": "dolore Ut",
    //           "width": -91859267,
    //           "height": 76867520,
    //           "isDefault": false
    //         },
    //         "displayName": "magna in veniam aliqua dolor",
    //         "accountId": "ut incididunt",
    //         "accountType": "sint Lorem",
    //         "email": "voluptate id",
    //         "publicName": "Duis mi",
    //         "username": "dolor consectetur venia",
    //         "userKey": "reprehenderit eius",
    //         "operations": [
    //           {
    //             "operation": "administer",
    //             "targetType": "page"
    //           },
    //           {
    //             "operation": "purge_version",
    //             "targetType": "comment"
    //           }
    //         ],
    //         "details": {
    //           "business": {
    //             "value": "<Error: Too many levels of nesting to fake this schema>"
    //           },
    //           "personal": {
    //             "value": "<Error: Too many levels of nesting to fake this schema>"
    //           }
    //         }
    //       },
    //       "spaceKey": "Duis minim",
    //       "contentId": "est irure dolore"
    //     }
    //   ],
    //   "start": 36796637,
    //   "limit": -14900038,
    //   "size": -90406538,
    //   "_links": {}
    // }

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

    start = CkJsonObject_IntOf(jResp,"start");
    limit = CkJsonObject_IntOf(jResp,"limit");
    size = CkJsonObject_IntOf(jResp,"size");
    i = 0;
    count_i = CkJsonObject_SizeOfArray(jResp,"results");
    while (i < count_i) {
        CkJsonObject_putI(jResp,i);
        v_type = CkJsonObject_stringOf(jResp,"results[i].type");
        v_Type = CkJsonObject_stringOf(jResp,"results[i].watcher.type");
        Path = CkJsonObject_stringOf(jResp,"results[i].watcher.profilePicture.path");
        Width = CkJsonObject_IntOf(jResp,"results[i].watcher.profilePicture.width");
        Height = CkJsonObject_IntOf(jResp,"results[i].watcher.profilePicture.height");
        IsDefault = CkJsonObject_BoolOf(jResp,"results[i].watcher.profilePicture.isDefault");
        DisplayName = CkJsonObject_stringOf(jResp,"results[i].watcher.displayName");
        AccountId = CkJsonObject_stringOf(jResp,"results[i].watcher.accountId");
        AccountType = CkJsonObject_stringOf(jResp,"results[i].watcher.accountType");
        v_Email = CkJsonObject_stringOf(jResp,"results[i].watcher.email");
        PublicName = CkJsonObject_stringOf(jResp,"results[i].watcher.publicName");
        Username = CkJsonObject_stringOf(jResp,"results[i].watcher.username");
        UserKey = CkJsonObject_stringOf(jResp,"results[i].watcher.userKey");
        Value = CkJsonObject_stringOf(jResp,"results[i].watcher.details.business.value");
        PersonalValue = CkJsonObject_stringOf(jResp,"results[i].watcher.details.personal.value");
        spaceKey = CkJsonObject_stringOf(jResp,"results[i].spaceKey");
        contentId = CkJsonObject_stringOf(jResp,"results[i].contentId");
        j = 0;
        count_j = CkJsonObject_SizeOfArray(jResp,"results[i].watcher.operations");
        while (j < count_j) {
            CkJsonObject_putJ(jResp,j);
            operation = CkJsonObject_stringOf(jResp,"results[i].watcher.operations[j].operation");
            targetType = CkJsonObject_stringOf(jResp,"results[i].watcher.operations[j].targetType");
            j = j + 1;
        }

        i = i + 1;
    }



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

    }

Curl Command

curl -G -d "start=%3Cstring%3E"
	-d "limit=%3Cstring%3E"
https://your-domain.atlassian.net/wiki/rest/api/space/:spaceKey/watch

Postman Collection Item JSON

{
  "name": "Get space watchers",
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "{{baseUrl}}/api/space/:spaceKey/watch?start=<string>&limit=<string>",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "space",
        ":spaceKey",
        "watch"
      ],
      "query": [
        {
          "key": "start",
          "value": "<string>",
          "description": "The start point of the collection to return."
        },
        {
          "key": "limit",
          "value": "<string>",
          "description": "The limit of the number of items to return, this may be restricted by fixed system limits."
        }
      ],
      "variable": [
        {
          "key": "spaceKey",
          "value": "<string>",
          "type": "string",
          "description": "(Required) The key of the space to get watchers."
        }
      ]
    },
    "description": "Returns a list of watchers of a space"
  },
  "response": [
    {
      "name": "Returned if watchers list is returned.",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/api/space/:spaceKey/watch?start=<string>&limit=<string>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "space",
            ":spaceKey",
            "watch"
          ],
          "query": [
            {
              "key": "start",
              "value": "<string>"
            },
            {
              "key": "limit",
              "value": "<string>"
            }
          ],
          "variable": [
            {
              "key": "spaceKey"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"results\": [\n  {\n   \"type\": \"proident nisi dolo\",\n   \"watcher\": {\n    \"type\": \"veniam enim exercitation \",\n    \"profilePicture\": {\n     \"path\": \"Duis velit\",\n     \"width\": -59620755,\n     \"height\": 31433400,\n     \"isDefault\": true\n    },\n    \"displayName\": \"reprehenderit dolor ea magna\",\n    \"accountId\": \"sint enim volupta\",\n    \"accountType\": \"do ea ipsum ullamco\",\n    \"email\": \"dolor\",\n    \"publicName\": \"do aliqua\",\n    \"username\": \"nisi officia\",\n    \"userKey\": \"sint a\",\n    \"operations\": [\n     {\n      \"operation\": \"move\",\n      \"targetType\": \"attachment\"\n     },\n     {\n      \"operation\": \"move\",\n      \"targetType\": \"attachment\"\n     }\n    ],\n    \"details\": {\n     \"business\": {\n      \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n     },\n     \"personal\": {\n      \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n     }\n    }\n   },\n   \"spaceKey\": \"minim ex\",\n   \"contentId\": \"do\"\n  },\n  {\n   \"type\": \"ut in Duis ad\",\n   \"watcher\": {\n    \"type\": \"dolor id\",\n    \"profilePicture\": {\n     \"path\": \"dolore Ut\",\n     \"width\": -91859267,\n     \"height\": 76867520,\n     \"isDefault\": false\n    },\n    \"displayName\": \"magna in veniam aliqua dolor\",\n    \"accountId\": \"ut incididunt\",\n    \"accountType\": \"sint Lorem\",\n    \"email\": \"voluptate id\",\n    \"publicName\": \"Duis mi\",\n    \"username\": \"dolor consectetur venia\",\n    \"userKey\": \"reprehenderit eius\",\n    \"operations\": [\n     {\n      \"operation\": \"administer\",\n      \"targetType\": \"page\"\n     },\n     {\n      \"operation\": \"purge_version\",\n      \"targetType\": \"comment\"\n     }\n    ],\n    \"details\": {\n     \"business\": {\n      \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n     },\n     \"personal\": {\n      \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n     }\n    }\n   },\n   \"spaceKey\": \"Duis minim\",\n   \"contentId\": \"est irure dolore\"\n  }\n ],\n \"start\": 36796637,\n \"limit\": -14900038,\n \"size\": -90406538,\n \"_links\": {}\n}"
    },
    {
      "name": "Returned if there is no space with the given key",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/api/space/:spaceKey/watch?start=<string>&limit=<string>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "space",
            ":spaceKey",
            "watch"
          ],
          "query": [
            {
              "key": "start",
              "value": "<string>"
            },
            {
              "key": "limit",
              "value": "<string>"
            }
          ],
          "variable": [
            {
              "key": "spaceKey"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}