Chilkat Online Tools

C / Atlassian Confluence Cloud / Get watches for space

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 *Value;
    const char *PersonalValue;
    const char *Username;
    const char *UserKey;
    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_UpdateInt(queryParams,"start",0);
    CkJsonObject_UpdateInt(queryParams,"limit",200);

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

    resp = CkHttp_QuickRequestParams(http,"GET","https://your-domain.atlassian.net/wiki/rest/api/content/:id/notification/created",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": "incididunt ea",
    //       "watcher": {
    //         "type": "elit in minim aliquip",
    //         "profilePicture": {
    //           "path": "tempor commodo amet voluptate",
    //           "width": -39236226,
    //           "height": 75695638,
    //           "isDefault": true
    //         },
    //         "displayName": "qui",
    //         "operations": [
    //           {
    //             "operation": "copy",
    //             "targetType": "space"
    //           },
    //           {
    //             "operation": "purge",
    //             "targetType": "space"
    //           }
    //         ],
    //         "accountId": "nulla dolor",
    //         "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>"
    //           }
    //         },
    //         "username": "veniam exercitation deserunt",
    //         "userKey": "adipisicing culpa eu"
    //       },
    //       "contentId": "do nostrud consectetur"
    //     },
    //     {
    //       "type": "qui in aliquip",
    //       "watcher": {
    //         "type": "culpa velit Excepteur in",
    //         "profilePicture": {
    //           "path": "est iru",
    //           "width": -23304200,
    //           "height": -94415594,
    //           "isDefault": false
    //         },
    //         "displayName": "eiusmod Ut",
    //         "operations": [
    //           {
    //             "operation": "purge",
    //             "targetType": "page"
    //           },
    //           {
    //             "operation": "move",
    //             "targetType": "space"
    //           }
    //         ],
    //         "accountId": "laborum",
    //         "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>"
    //           }
    //         },
    //         "username": "conse",
    //         "userKey": "id ad velit incididunt Ut"
    //       },
    //       "contentId": "Duis labore voluptate consectetur"
    //     }
    //   ],
    //   "start": 86483335,
    //   "limit": 45770246,
    //   "size": 20684808,
    //   "_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");
        Value = CkJsonObject_stringOf(jResp,"results[i].watcher.details.business.value");
        PersonalValue = CkJsonObject_stringOf(jResp,"results[i].watcher.details.personal.value");
        Username = CkJsonObject_stringOf(jResp,"results[i].watcher.username");
        UserKey = CkJsonObject_stringOf(jResp,"results[i].watcher.userKey");
        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=0"
	-d "limit=200"
	-H "Authorization: Bearer <access_token>"
https://your-domain.atlassian.net/wiki/rest/api/content/:id/notification/created

Postman Collection Item JSON

{
  "name": "Get watches for space",
  "request": {
    "auth": {
      "type": "oauth2"
    },
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "{{baseUrl}}/api/content/:id/notification/created?start=0&limit=200",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "content",
        ":id",
        "notification",
        "created"
      ],
      "query": [
        {
          "key": "start",
          "value": "0",
          "description": "The starting index of the returned watches."
        },
        {
          "key": "limit",
          "value": "200",
          "description": "The maximum number of watches to return per page.\nNote, this may be restricted by fixed system limits."
        }
      ],
      "variable": [
        {
          "key": "id",
          "value": "<string>",
          "type": "string",
          "description": "(Required) The ID of the content to be queried for its watches."
        }
      ]
    },
    "description": "Returns all space watches for the space that the content is in. A user that\nwatches a space will receive receive notifications when any content in the\nspace is updated.\n\nIf you want to manage watches for a space, use the following `user` methods:\n\n- [Get space watch status for user](#api-user-watch-space-spaceKey-get)\n- [Add space watch](#api-user-watch-space-spaceKey-post)\n- [Remove space watch](#api-user-watch-space-spaceKey-delete)\n\n**[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:\nPermission to access the Confluence site ('Can use' global permission)."
  },
  "response": [
    {
      "name": "Returned if the requested watches are returned.",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": {
              "content": "Added as a part of security scheme: oauth2",
              "type": "text/plain"
            },
            "key": "Authorization",
            "value": "<token>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/content/:id/notification/created?start=0&limit=200",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "content",
            ":id",
            "notification",
            "created"
          ],
          "query": [
            {
              "key": "start",
              "value": "0"
            },
            {
              "key": "limit",
              "value": "200"
            }
          ],
          "variable": [
            {
              "key": "id"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"results\": [\n  {\n   \"type\": \"incididunt ea\",\n   \"watcher\": {\n    \"type\": \"elit in minim aliquip\",\n    \"profilePicture\": {\n     \"path\": \"tempor commodo amet voluptate\",\n     \"width\": -39236226,\n     \"height\": 75695638,\n     \"isDefault\": true\n    },\n    \"displayName\": \"qui\",\n    \"operations\": [\n     {\n      \"operation\": \"copy\",\n      \"targetType\": \"space\"\n     },\n     {\n      \"operation\": \"purge\",\n      \"targetType\": \"space\"\n     }\n    ],\n    \"accountId\": \"nulla dolor\",\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    \"username\": \"veniam exercitation deserunt\",\n    \"userKey\": \"adipisicing culpa eu\"\n   },\n   \"contentId\": \"do nostrud consectetur\"\n  },\n  {\n   \"type\": \"qui in aliquip\",\n   \"watcher\": {\n    \"type\": \"culpa velit Excepteur in\",\n    \"profilePicture\": {\n     \"path\": \"est iru\",\n     \"width\": -23304200,\n     \"height\": -94415594,\n     \"isDefault\": false\n    },\n    \"displayName\": \"eiusmod Ut\",\n    \"operations\": [\n     {\n      \"operation\": \"purge\",\n      \"targetType\": \"page\"\n     },\n     {\n      \"operation\": \"move\",\n      \"targetType\": \"space\"\n     }\n    ],\n    \"accountId\": \"laborum\",\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    \"username\": \"conse\",\n    \"userKey\": \"id ad velit incididunt Ut\"\n   },\n   \"contentId\": \"Duis labore voluptate consectetur\"\n  }\n ],\n \"start\": 86483335,\n \"limit\": 45770246,\n \"size\": 20684808,\n \"_links\": {}\n}"
    },
    {
      "name": "Returned if the authentication credentials are incorrect or missing\nfrom the request.",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": {
              "content": "Added as a part of security scheme: oauth2",
              "type": "text/plain"
            },
            "key": "Authorization",
            "value": "<token>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/content/:id/notification/created?start=0&limit=200",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "content",
            ":id",
            "notification",
            "created"
          ],
          "query": [
            {
              "key": "start",
              "value": "0"
            },
            {
              "key": "limit",
              "value": "200"
            }
          ],
          "variable": [
            {
              "key": "id"
            }
          ]
        }
      },
      "status": "Unauthorized",
      "code": 401,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}