Chilkat Online Tools

PureBasic / Atlassian Confluence Cloud / Get audit records

Back to Collection Items

IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkHttpResponse.pb"

Procedure ChilkatExample()

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

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    queryParams.i = CkJsonObject::ckCreate()
    If queryParams.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckUpdateString(queryParams,"startDate","<string>")
    CkJsonObject::ckUpdateString(queryParams,"endDate","<string>")
    CkJsonObject::ckUpdateString(queryParams,"searchString","<string>")
    CkJsonObject::ckUpdateInt(queryParams,"start",0)
    CkJsonObject::ckUpdateInt(queryParams,"limit",1000)

    resp.i = CkHttp::ckQuickRequestParams(http,"GET","https://your-domain.atlassian.net/wiki/rest/api/audit",queryParams)
    If CkHttp::ckLastMethodSuccess(http) = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(queryParams)
        ProcedureReturn
    EndIf

    sbResponseBody.i = CkStringBuilder::ckCreate()
    If sbResponseBody.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkHttpResponse::ckGetBodySb(resp,sbResponseBody)

    jResp.i = CkJsonObject::ckCreate()
    If jResp.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckLoadSb(jResp,sbResponseBody)
    CkJsonObject::setCkEmitCompact(jResp, 0)

    Debug "Response Body:"
    Debug CkJsonObject::ckEmit(jResp)

    respStatusCode.i = CkHttpResponse::ckStatusCode(resp)
    Debug "Response Status Code = " + Str(respStatusCode)
    If respStatusCode >= 400
        Debug "Response Header:"
        Debug CkHttpResponse::ckHeader(resp)
        Debug "Failed."
        CkHttpResponse::ckDispose(resp)

        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(queryParams)
        CkStringBuilder::ckDispose(sbResponseBody)
        CkJsonObject::ckDispose(jResp)
        ProcedureReturn
    EndIf

    CkHttpResponse::ckDispose(resp)

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

    ; {
    ;   "results": [
    ;     {
    ;       "author": {
    ;         "type": "user",
    ;         "displayName": "ut qui occaecat",
    ;         "operations": null,
    ;         "username": "officia dolor",
    ;         "userKey": "Ut Lorem"
    ;       },
    ;       "remoteAddress": "ullamco tempor id",
    ;       "creationDate": 87607791,
    ;       "summary": "ut laboris qui Ut",
    ;       "description": "pariatur ut cillum id quis",
    ;       "category": "pariatur et sunt enim dolor",
    ;       "sysAdmin": true,
    ;       "affectedObject": {
    ;         "name": "pariatur ea eu",
    ;         "objectType": "exerci"
    ;       },
    ;       "changedValues": [
    ;         {
    ;           "name": "voluptate Lorem nostrud",
    ;           "oldValue": "exercitation dolor",
    ;           "newValue": "nulla proident"
    ;         },
    ;         {
    ;           "name": "proid",
    ;           "oldValue": "sint eu",
    ;           "newValue": "sed adipisicing irure"
    ;         }
    ;       ],
    ;       "associatedObjects": [
    ;         {
    ;           "name": "eiusmod aliquip incididunt",
    ;           "objectType": "laboris aute elit tempor"
    ;         },
    ;         {
    ;           "name": "dolore adipisicing",
    ;           "objectType": "eiusmod cillum sunt Ut cupidatat"
    ;         }
    ;       ]
    ;     },
    ;     {
    ;       "author": {
    ;         "type": "user",
    ;         "displayName": "deserunt laboris voluptate cupidatat",
    ;         "operations": null,
    ;         "username": "et cillum ut cupidatat",
    ;         "userKey": "qui magna eu deserunt"
    ;       },
    ;       "remoteAddress": "v",
    ;       "creationDate": 42657177,
    ;       "summary": "enim sit dolore cillum",
    ;       "description": "Excepteur sit",
    ;       "category": "exercitation in ea",
    ;       "sysAdmin": true,
    ;       "affectedObject": {
    ;         "name": "ex cillum",
    ;         "objectType": "eu officia veniam labore"
    ;       },
    ;       "changedValues": [
    ;         {
    ;           "name": "dolor laborum sed do sunt",
    ;           "oldValue": "dolor eiusmod",
    ;           "newValue": "nulla"
    ;         },
    ;         {
    ;           "name": "consectetur eiusmod",
    ;           "oldValue": "Except",
    ;           "newValue": "culpa aliquip"
    ;         }
    ;       ],
    ;       "associatedObjects": [
    ;         {
    ;           "name": "adipisicing aliquip",
    ;           "objectType": "elit Ut laboris"
    ;         },
    ;         {
    ;           "name": "anim",
    ;           "objectType": "dolore in voluptate"
    ;         }
    ;       ]
    ;     }
    ;   ],
    ;   "start": 48713254,
    ;   "limit": 16739977,
    ;   "size": -39928545,
    ;   "_links": {}
    ; }

    ; Sample code for parsing the JSON response...
    ; Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

    v_Type.s
    DisplayName.s
    Operations.s
    Username.s
    UserKey.s
    remoteAddress.s
    creationDate.i
    summary.s
    description.s
    category.s
    sysAdmin.i
    Name.s
    ObjectType.s
    j.i
    count_j.i
    name.s
    oldValue.s
    newValue.s
    objectType.s

    start.i = CkJsonObject::ckIntOf(jResp,"start")
    limit.i = CkJsonObject::ckIntOf(jResp,"limit")
    size.i = CkJsonObject::ckIntOf(jResp,"size")
    i.i = 0
    count_i.i = CkJsonObject::ckSizeOfArray(jResp,"results")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        v_Type = CkJsonObject::ckStringOf(jResp,"results[i].author.type")
        DisplayName = CkJsonObject::ckStringOf(jResp,"results[i].author.displayName")
        Operations = CkJsonObject::ckStringOf(jResp,"results[i].author.operations")
        Username = CkJsonObject::ckStringOf(jResp,"results[i].author.username")
        UserKey = CkJsonObject::ckStringOf(jResp,"results[i].author.userKey")
        remoteAddress = CkJsonObject::ckStringOf(jResp,"results[i].remoteAddress")
        creationDate = CkJsonObject::ckIntOf(jResp,"results[i].creationDate")
        summary = CkJsonObject::ckStringOf(jResp,"results[i].summary")
        description = CkJsonObject::ckStringOf(jResp,"results[i].description")
        category = CkJsonObject::ckStringOf(jResp,"results[i].category")
        sysAdmin = CkJsonObject::ckBoolOf(jResp,"results[i].sysAdmin")
        Name = CkJsonObject::ckStringOf(jResp,"results[i].affectedObject.name")
        ObjectType = CkJsonObject::ckStringOf(jResp,"results[i].affectedObject.objectType")
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jResp,"results[i].changedValues")
        While j < count_j
            CkJsonObject::setCkJ(jResp, j)
            name = CkJsonObject::ckStringOf(jResp,"results[i].changedValues[j].name")
            oldValue = CkJsonObject::ckStringOf(jResp,"results[i].changedValues[j].oldValue")
            newValue = CkJsonObject::ckStringOf(jResp,"results[i].changedValues[j].newValue")
            j = j + 1
        Wend
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jResp,"results[i].associatedObjects")
        While j < count_j
            CkJsonObject::setCkJ(jResp, j)
            name = CkJsonObject::ckStringOf(jResp,"results[i].associatedObjects[j].name")
            objectType = CkJsonObject::ckStringOf(jResp,"results[i].associatedObjects[j].objectType")
            j = j + 1
        Wend
        i = i + 1
    Wend


    CkHttp::ckDispose(http)
    CkJsonObject::ckDispose(queryParams)
    CkStringBuilder::ckDispose(sbResponseBody)
    CkJsonObject::ckDispose(jResp)


    ProcedureReturn
EndProcedure

Curl Command

curl -G -d "startDate=%3Cstring%3E"
	-d "endDate=%3Cstring%3E"
	-d "searchString=%3Cstring%3E"
	-d "start=0"
	-d "limit=1000"
https://your-domain.atlassian.net/wiki/rest/api/audit

Postman Collection Item JSON

{
  "name": "Get audit records",
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "{{baseUrl}}/api/audit?startDate=<string>&endDate=<string>&searchString=<string>&start=0&limit=1000",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "audit"
      ],
      "query": [
        {
          "key": "startDate",
          "value": "<string>",
          "description": "Filters the results to the records on or after the `startDate`.\nThe `startDate` must be specified as a [timestamp](https://www.unixtimestamp.com/)."
        },
        {
          "key": "endDate",
          "value": "<string>",
          "description": "Filters the results to the records on or before the `endDate`.\nThe `endDate` must be specified as a [timestamp](https://www.unixtimestamp.com/)."
        },
        {
          "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 all records in the audit log, optionally for a certain date range.\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?startDate=<string>&endDate=<string>&searchString=<string>&start=0&limit=1000",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "audit"
          ],
          "query": [
            {
              "key": "startDate",
              "value": "<string>"
            },
            {
              "key": "endDate",
              "value": "<string>"
            },
            {
              "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\": \"ut qui occaecat\",\n    \"operations\": null,\n    \"username\": \"officia dolor\",\n    \"userKey\": \"Ut Lorem\"\n   },\n   \"remoteAddress\": \"ullamco tempor id\",\n   \"creationDate\": 87607791,\n   \"summary\": \"ut laboris qui Ut\",\n   \"description\": \"pariatur ut cillum id quis\",\n   \"category\": \"pariatur et sunt enim dolor\",\n   \"sysAdmin\": true,\n   \"affectedObject\": {\n    \"name\": \"pariatur ea eu\",\n    \"objectType\": \"exerci\"\n   },\n   \"changedValues\": [\n    {\n     \"name\": \"voluptate Lorem nostrud\",\n     \"oldValue\": \"exercitation dolor\",\n     \"newValue\": \"nulla proident\"\n    },\n    {\n     \"name\": \"proid\",\n     \"oldValue\": \"sint eu\",\n     \"newValue\": \"sed adipisicing irure\"\n    }\n   ],\n   \"associatedObjects\": [\n    {\n     \"name\": \"eiusmod aliquip incididunt\",\n     \"objectType\": \"laboris aute elit tempor\"\n    },\n    {\n     \"name\": \"dolore adipisicing\",\n     \"objectType\": \"eiusmod cillum sunt Ut cupidatat\"\n    }\n   ]\n  },\n  {\n   \"author\": {\n    \"type\": \"user\",\n    \"displayName\": \"deserunt laboris voluptate cupidatat\",\n    \"operations\": null,\n    \"username\": \"et cillum ut cupidatat\",\n    \"userKey\": \"qui magna eu deserunt\"\n   },\n   \"remoteAddress\": \"v\",\n   \"creationDate\": 42657177,\n   \"summary\": \"enim sit dolore cillum\",\n   \"description\": \"Excepteur sit\",\n   \"category\": \"exercitation in ea\",\n   \"sysAdmin\": true,\n   \"affectedObject\": {\n    \"name\": \"ex cillum\",\n    \"objectType\": \"eu officia veniam labore\"\n   },\n   \"changedValues\": [\n    {\n     \"name\": \"dolor laborum sed do sunt\",\n     \"oldValue\": \"dolor eiusmod\",\n     \"newValue\": \"nulla\"\n    },\n    {\n     \"name\": \"consectetur eiusmod\",\n     \"oldValue\": \"Except\",\n     \"newValue\": \"culpa aliquip\"\n    }\n   ],\n   \"associatedObjects\": [\n    {\n     \"name\": \"adipisicing aliquip\",\n     \"objectType\": \"elit Ut laboris\"\n    },\n    {\n     \"name\": \"anim\",\n     \"objectType\": \"dolore in voluptate\"\n    }\n   ]\n  }\n ],\n \"start\": 48713254,\n \"limit\": 16739977,\n \"size\": -39928545,\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?startDate=<string>&endDate=<string>&searchString=<string>&start=0&limit=1000",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "audit"
          ],
          "query": [
            {
              "key": "startDate",
              "value": "<string>"
            },
            {
              "key": "endDate",
              "value": "<string>"
            },
            {
              "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": ""
    }
  ]
}