Chilkat Online Tools

SQL Server / Atlassian Confluence Cloud / Get audit records for time period

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, 'number', 3
    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'units', 'MONTHS'
    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'searchString', '<string>'
    EXEC sp_OAMethod @queryParams, 'UpdateInt', @success OUT, 'start', 0
    EXEC sp_OAMethod @queryParams, 'UpdateInt', @success OUT, 'limit', 1000

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'QuickRequestParams', @resp OUT, 'GET', 'https://your-domain.atlassian.net/wiki/rest/api/audit/since', @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": [
    --     {
    --       "author": {
    --         "type": "user",
    --         "displayName": "eu qui amet",
    --         "operations": null,
    --         "username": "ut",
    --         "userKey": "amet ut eu Ut"
    --       },
    --       "remoteAddress": "irure sed commodo tempor",
    --       "creationDate": -28489517,
    --       "summary": "reprehenderit occaecat",
    --       "description": "sed in occaecat",
    --       "category": "magna qui Lorem",
    --       "sysAdmin": false,
    --       "affectedObject": {
    --         "name": "Ut est ad eu anim",
    --         "objectType": "tempor Excepteur"
    --       },
    --       "changedValues": [
    --         {
    --           "name": "non anim sint qui",
    --           "oldValue": "amet est qui esse",
    --           "newValue": "tempor quis"
    --         },
    --         {
    --           "name": "sed ipsum aut",
    --           "oldValue": "culpa",
    --           "newValue": "occaecat ad"
    --         }
    --       ],
    --       "associatedObjects": [
    --         {
    --           "name": "Excepteur fugiat",
    --           "objectType": "aute sint quis eiusmod qui"
    --         },
    --         {
    --           "name": "esse laborum in",
    --           "objectType": "magna irure"
    --         }
    --       ]
    --     },
    --     {
    --       "author": {
    --         "type": "user",
    --         "displayName": "anim nisi occaecat ipsum",
    --         "operations": null,
    --         "username": "anim in proident ex et",
    --         "userKey": "dolore sunt"
    --       },
    --       "remoteAddress": "ipsum mollit est",
    --       "creationDate": -68787259,
    --       "summary": "labore cupidatat amet laborum",
    --       "description": "et ea dolore",
    --       "category": "consequat ex enim occaecat",
    --       "sysAdmin": true,
    --       "affectedObject": {
    --         "name": "irure occaecat proident dolor id",
    --         "objectType": "veniam Ut in magna"
    --       },
    --       "changedValues": [
    --         {
    --           "name": "proident sunt laboris",
    --           "oldValue": "ut sunt dolore ullamco",
    --           "newValue": "enim adipisicing"
    --         },
    --         {
    --           "name": "non cillum laborum reprehenderit",
    --           "oldValue": "in mollit consectetur",
    --           "newValue": "fugiat ut anim pariatur"
    --         }
    --       ],
    --       "associatedObjects": [
    --         {
    --           "name": "qui anim dolore",
    --           "objectType": ""
    --         },
    --         {
    --           "name": "enim pariatur in ut sed",
    --           "objectType": "nostrud"
    --         }
    --       ]
    --     }
    --   ],
    --   "start": -42437008,
    --   "limit": 95954729,
    --   "size": -54456786,
    --   "_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 @DisplayName nvarchar(4000)

    DECLARE @Operations nvarchar(4000)

    DECLARE @Username nvarchar(4000)

    DECLARE @UserKey nvarchar(4000)

    DECLARE @remoteAddress nvarchar(4000)

    DECLARE @creationDate int

    DECLARE @summary nvarchar(4000)

    DECLARE @description nvarchar(4000)

    DECLARE @category nvarchar(4000)

    DECLARE @sysAdmin int

    DECLARE @Name nvarchar(4000)

    DECLARE @ObjectType nvarchar(4000)

    DECLARE @j int

    DECLARE @count_j int

    DECLARE @name nvarchar(4000)

    DECLARE @oldValue nvarchar(4000)

    DECLARE @newValue nvarchar(4000)

    DECLARE @objectType 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].author.type'
        EXEC sp_OAMethod @jResp, 'StringOf', @DisplayName OUT, 'results[i].author.displayName'
        EXEC sp_OAMethod @jResp, 'StringOf', @Operations OUT, 'results[i].author.operations'
        EXEC sp_OAMethod @jResp, 'StringOf', @Username OUT, 'results[i].author.username'
        EXEC sp_OAMethod @jResp, 'StringOf', @UserKey OUT, 'results[i].author.userKey'
        EXEC sp_OAMethod @jResp, 'StringOf', @remoteAddress OUT, 'results[i].remoteAddress'
        EXEC sp_OAMethod @jResp, 'IntOf', @creationDate OUT, 'results[i].creationDate'
        EXEC sp_OAMethod @jResp, 'StringOf', @summary OUT, 'results[i].summary'
        EXEC sp_OAMethod @jResp, 'StringOf', @description OUT, 'results[i].description'
        EXEC sp_OAMethod @jResp, 'StringOf', @category OUT, 'results[i].category'
        EXEC sp_OAMethod @jResp, 'BoolOf', @sysAdmin OUT, 'results[i].sysAdmin'
        EXEC sp_OAMethod @jResp, 'StringOf', @Name OUT, 'results[i].affectedObject.name'
        EXEC sp_OAMethod @jResp, 'StringOf', @ObjectType OUT, 'results[i].affectedObject.objectType'
        SELECT @j = 0
        EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'results[i].changedValues'
        WHILE @j < @count_j
          BEGIN
            EXEC sp_OASetProperty @jResp, 'J', @j
            EXEC sp_OAMethod @jResp, 'StringOf', @name OUT, 'results[i].changedValues[j].name'
            EXEC sp_OAMethod @jResp, 'StringOf', @oldValue OUT, 'results[i].changedValues[j].oldValue'
            EXEC sp_OAMethod @jResp, 'StringOf', @newValue OUT, 'results[i].changedValues[j].newValue'
            SELECT @j = @j + 1
          END
        SELECT @j = 0
        EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'results[i].associatedObjects'
        WHILE @j < @count_j
          BEGIN
            EXEC sp_OASetProperty @jResp, 'J', @j
            EXEC sp_OAMethod @jResp, 'StringOf', @name OUT, 'results[i].associatedObjects[j].name'
            EXEC sp_OAMethod @jResp, 'StringOf', @objectType OUT, 'results[i].associatedObjects[j].objectType'
            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 "number=3"
	-d "units=MONTHS"
	-d "searchString=%3Cstring%3E"
	-d "start=0"
	-d "limit=1000"
https://your-domain.atlassian.net/wiki/rest/api/audit/since

Postman Collection Item JSON

{
  "name": "Get audit records for time period",
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "{{baseUrl}}/api/audit/since?number=3&units=MONTHS&searchString=<string>&start=0&limit=1000",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "audit",
        "since"
      ],
      "query": [
        {
          "key": "number",
          "value": "3",
          "description": "The number of units for the time period."
        },
        {
          "key": "units",
          "value": "MONTHS",
          "description": "The unit of time that the time period is measured in."
        },
        {
          "key": "searchString",
          "value": "<string>",
          "description": "Filters the results to records that have string property values\nmatching the `searchString`."
        },
        {
          "key": "start",
          "value": "0",
          "description": "The starting index of the returned records."
        },
        {
          "key": "limit",
          "value": "1000",
          "description": "The maximum number of records to return per page.\nNote, this may be restricted by fixed system limits."
        }
      ]
    },
    "description": "Returns records from the audit log, for a time period back from the current\ndate. For example, you can use this method to get the last 3 months of records.\n\nThis contains information about events like space exports, group membership\nchanges, app installations, etc. For more information, see\n[Audit log](https://confluence.atlassian.com/confcloud/audit-log-802164269.html)\nin the Confluence administrator's guide.\n\n**[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:\n'Confluence Administrator' global permission."
  },
  "response": [
    {
      "name": "Returned if the requested records are returned.",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/api/audit/since?number=3&units=MONTHS&searchString=<string>&start=0&limit=1000",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "audit",
            "since"
          ],
          "query": [
            {
              "key": "number",
              "value": "3"
            },
            {
              "key": "units",
              "value": "MONTHS"
            },
            {
              "key": "searchString",
              "value": "<string>"
            },
            {
              "key": "start",
              "value": "0"
            },
            {
              "key": "limit",
              "value": "1000"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"results\": [\n  {\n   \"author\": {\n    \"type\": \"user\",\n    \"displayName\": \"eu qui amet\",\n    \"operations\": null,\n    \"username\": \"ut\",\n    \"userKey\": \"amet ut eu Ut\"\n   },\n   \"remoteAddress\": \"irure sed commodo tempor\",\n   \"creationDate\": -28489517,\n   \"summary\": \"reprehenderit occaecat\",\n   \"description\": \"sed in occaecat\",\n   \"category\": \"magna qui Lorem\",\n   \"sysAdmin\": false,\n   \"affectedObject\": {\n    \"name\": \"Ut est ad eu anim\",\n    \"objectType\": \"tempor Excepteur\"\n   },\n   \"changedValues\": [\n    {\n     \"name\": \"non anim sint qui\",\n     \"oldValue\": \"amet est qui esse\",\n     \"newValue\": \"tempor quis\"\n    },\n    {\n     \"name\": \"sed ipsum aut\",\n     \"oldValue\": \"culpa\",\n     \"newValue\": \"occaecat ad\"\n    }\n   ],\n   \"associatedObjects\": [\n    {\n     \"name\": \"Excepteur fugiat\",\n     \"objectType\": \"aute sint quis eiusmod qui\"\n    },\n    {\n     \"name\": \"esse laborum in\",\n     \"objectType\": \"magna irure\"\n    }\n   ]\n  },\n  {\n   \"author\": {\n    \"type\": \"user\",\n    \"displayName\": \"anim nisi occaecat ipsum\",\n    \"operations\": null,\n    \"username\": \"anim in proident ex et\",\n    \"userKey\": \"dolore sunt\"\n   },\n   \"remoteAddress\": \"ipsum mollit est\",\n   \"creationDate\": -68787259,\n   \"summary\": \"labore cupidatat amet laborum\",\n   \"description\": \"et ea dolore\",\n   \"category\": \"consequat ex enim occaecat\",\n   \"sysAdmin\": true,\n   \"affectedObject\": {\n    \"name\": \"irure occaecat proident dolor id\",\n    \"objectType\": \"veniam Ut in magna\"\n   },\n   \"changedValues\": [\n    {\n     \"name\": \"proident sunt laboris\",\n     \"oldValue\": \"ut sunt dolore ullamco\",\n     \"newValue\": \"enim adipisicing\"\n    },\n    {\n     \"name\": \"non cillum laborum reprehenderit\",\n     \"oldValue\": \"in mollit consectetur\",\n     \"newValue\": \"fugiat ut anim pariatur\"\n    }\n   ],\n   \"associatedObjects\": [\n    {\n     \"name\": \"qui anim dolore\",\n     \"objectType\": \"\"\n    },\n    {\n     \"name\": \"enim pariatur in ut sed\",\n     \"objectType\": \"nostrud\"\n    }\n   ]\n  }\n ],\n \"start\": -42437008,\n \"limit\": 95954729,\n \"size\": -54456786,\n \"_links\": {}\n}"
    },
    {
      "name": "Returned if the calling user does not have permission to view the audit\nlog.",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/api/audit/since?number=3&units=MONTHS&searchString=<string>&start=0&limit=1000",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "audit",
            "since"
          ],
          "query": [
            {
              "key": "number",
              "value": "3"
            },
            {
              "key": "units",
              "value": "MONTHS"
            },
            {
              "key": "searchString",
              "value": "<string>"
            },
            {
              "key": "start",
              "value": "0"
            },
            {
              "key": "limit",
              "value": "1000"
            }
          ]
        }
      },
      "status": "Forbidden",
      "code": 403,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}