Chilkat Online Tools

SQL Server / Atlassian Confluence Cloud / Get watches for space

Back to Collection Items

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @http int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    DECLARE @queryParams int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @queryParams OUT

    EXEC sp_OAMethod @queryParams, 'UpdateInt', @success OUT, 'start', 0
    EXEC sp_OAMethod @queryParams, 'UpdateInt', @success OUT, 'limit', 200

    -- Adds the "Authorization: Bearer <access_token>" header.
    EXEC sp_OASetProperty @http, 'AuthToken', '<access_token>'

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'QuickRequestParams', @resp OUT, 'GET', 'https://your-domain.atlassian.net/wiki/rest/api/content/:id/notification/created', @queryParams
    EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @queryParams
        RETURN
      END

    DECLARE @sbResponseBody int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbResponseBody OUT

    EXEC sp_OAMethod @resp, 'GetBodySb', @success OUT, @sbResponseBody

    DECLARE @jResp int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @jResp OUT

    EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @sbResponseBody
    EXEC sp_OASetProperty @jResp, 'EmitCompact', 0


    PRINT 'Response Body:'
    EXEC sp_OAMethod @jResp, 'Emit', @sTmp0 OUT
    PRINT @sTmp0

    DECLARE @respStatusCode int
    EXEC sp_OAGetProperty @resp, 'StatusCode', @respStatusCode OUT

    PRINT 'Response Status Code = ' + @respStatusCode
    IF @respStatusCode >= 400
      BEGIN

        PRINT 'Response Header:'
        EXEC sp_OAGetProperty @resp, 'Header', @sTmp0 OUT
        PRINT @sTmp0

        PRINT 'Failed.'
        EXEC @hr = sp_OADestroy @resp

        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @queryParams
        EXEC @hr = sp_OADestroy @sbResponseBody
        EXEC @hr = sp_OADestroy @jResp
        RETURN
      END
    EXEC @hr = sp_OADestroy @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

    DECLARE @v_type nvarchar(4000)

    DECLARE @v_Type nvarchar(4000)

    DECLARE @Path nvarchar(4000)

    DECLARE @Width int

    DECLARE @Height int

    DECLARE @IsDefault int

    DECLARE @DisplayName nvarchar(4000)

    DECLARE @AccountId nvarchar(4000)

    DECLARE @Value nvarchar(4000)

    DECLARE @PersonalValue nvarchar(4000)

    DECLARE @Username nvarchar(4000)

    DECLARE @UserKey nvarchar(4000)

    DECLARE @contentId nvarchar(4000)

    DECLARE @j int

    DECLARE @count_j int

    DECLARE @operation nvarchar(4000)

    DECLARE @targetType nvarchar(4000)

    DECLARE @start int
    EXEC sp_OAMethod @jResp, 'IntOf', @start OUT, 'start'
    DECLARE @limit int
    EXEC sp_OAMethod @jResp, 'IntOf', @limit OUT, 'limit'
    DECLARE @size int
    EXEC sp_OAMethod @jResp, 'IntOf', @size OUT, 'size'
    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'results'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @v_type OUT, 'results[i].type'
        EXEC sp_OAMethod @jResp, 'StringOf', @v_Type OUT, 'results[i].watcher.type'
        EXEC sp_OAMethod @jResp, 'StringOf', @Path OUT, 'results[i].watcher.profilePicture.path'
        EXEC sp_OAMethod @jResp, 'IntOf', @Width OUT, 'results[i].watcher.profilePicture.width'
        EXEC sp_OAMethod @jResp, 'IntOf', @Height OUT, 'results[i].watcher.profilePicture.height'
        EXEC sp_OAMethod @jResp, 'BoolOf', @IsDefault OUT, 'results[i].watcher.profilePicture.isDefault'
        EXEC sp_OAMethod @jResp, 'StringOf', @DisplayName OUT, 'results[i].watcher.displayName'
        EXEC sp_OAMethod @jResp, 'StringOf', @AccountId OUT, 'results[i].watcher.accountId'
        EXEC sp_OAMethod @jResp, 'StringOf', @Value OUT, 'results[i].watcher.details.business.value'
        EXEC sp_OAMethod @jResp, 'StringOf', @PersonalValue OUT, 'results[i].watcher.details.personal.value'
        EXEC sp_OAMethod @jResp, 'StringOf', @Username OUT, 'results[i].watcher.username'
        EXEC sp_OAMethod @jResp, 'StringOf', @UserKey OUT, 'results[i].watcher.userKey'
        EXEC sp_OAMethod @jResp, 'StringOf', @contentId OUT, 'results[i].contentId'
        SELECT @j = 0
        EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'results[i].watcher.operations'
        WHILE @j < @count_j
          BEGIN
            EXEC sp_OASetProperty @jResp, 'J', @j
            EXEC sp_OAMethod @jResp, 'StringOf', @operation OUT, 'results[i].watcher.operations[j].operation'
            EXEC sp_OAMethod @jResp, 'StringOf', @targetType OUT, 'results[i].watcher.operations[j].targetType'
            SELECT @j = @j + 1
          END
        SELECT @i = @i + 1
      END

    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @queryParams
    EXEC @hr = sp_OADestroy @sbResponseBody
    EXEC @hr = sp_OADestroy @jResp


END
GO

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": ""
    }
  ]
}