Chilkat Online Tools

unicodeC / Atlassian Confluence Cloud / Create audit record

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>
#include <C_CkStringBuilderW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkJsonObjectW json;
    HCkHttpResponseW resp;
    HCkStringBuilderW sbResponseBody;
    HCkJsonObjectW jResp;
    int respStatusCode;
    const wchar_t *name;
    const wchar_t *oldValue;
    const wchar_t *newValue;
    const wchar_t *objectType;
    const wchar_t *v_Type;
    const wchar_t *DisplayName;
    const wchar_t *Operations;
    const wchar_t *Username;
    const wchar_t *UserKey;
    const wchar_t *remoteAddress;
    int creationDate;
    const wchar_t *summary;
    const wchar_t *description;
    const wchar_t *category;
    BOOL sysAdmin;
    const wchar_t *Name;
    const wchar_t *ObjectType;
    int i;
    int count_i;

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

    http = CkHttpW_Create();

    // Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    // The following JSON is sent in the request body.

    // {
    //   "remoteAddress": "<string>",
    //   "author": {
    //     "type": "user",
    //     "displayName": "<string>",
    //     "operations": "<object>",
    //     "username": "<string>",
    //     "userKey": "<string>"
    //   },
    //   "creationDate": "<long>",
    //   "summary": "<string>",
    //   "description": "<string>",
    //   "category": "<string>",
    //   "sysAdmin": false,
    //   "affectedObject": {
    //     "name": "amet dolore",
    //     "objectType": "labore tempor veniam officia"
    //   },
    //   "changedValues": [
    //     {
    //       "name": "voluptate sit sed sint ",
    //       "oldValue": "proident nisi",
    //       "newValue": "dolore aute cupidatat enim"
    //     },
    //     {
    //       "name": "in eu",
    //       "oldValue": "enim laborum tempor Lorem",
    //       "newValue": "ipsum ex velit"
    //     }
    //   ],
    //   "associatedObjects": [
    //     {
    //       "name": "qui",
    //       "objectType": "ipsum"
    //     },
    //     {
    //       "name": "nostrud consectetur",
    //       "objectType": "sit dolore enim Ut"
    //     }
    //   ]
    // }

    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(json,L"remoteAddress",L"<string>");
    CkJsonObjectW_UpdateString(json,L"author.type",L"user");
    CkJsonObjectW_UpdateString(json,L"author.displayName",L"<string>");
    CkJsonObjectW_UpdateString(json,L"author.operations",L"<object>");
    CkJsonObjectW_UpdateString(json,L"author.username",L"<string>");
    CkJsonObjectW_UpdateString(json,L"author.userKey",L"<string>");
    CkJsonObjectW_UpdateString(json,L"creationDate",L"<long>");
    CkJsonObjectW_UpdateString(json,L"summary",L"<string>");
    CkJsonObjectW_UpdateString(json,L"description",L"<string>");
    CkJsonObjectW_UpdateString(json,L"category",L"<string>");
    CkJsonObjectW_UpdateBool(json,L"sysAdmin",FALSE);
    CkJsonObjectW_UpdateString(json,L"affectedObject.name",L"amet dolore");
    CkJsonObjectW_UpdateString(json,L"affectedObject.objectType",L"labore tempor veniam officia");
    CkJsonObjectW_UpdateString(json,L"changedValues[0].name",L"voluptate sit sed sint ");
    CkJsonObjectW_UpdateString(json,L"changedValues[0].oldValue",L"proident nisi");
    CkJsonObjectW_UpdateString(json,L"changedValues[0].newValue",L"dolore aute cupidatat enim");
    CkJsonObjectW_UpdateString(json,L"changedValues[1].name",L"in eu");
    CkJsonObjectW_UpdateString(json,L"changedValues[1].oldValue",L"enim laborum tempor Lorem");
    CkJsonObjectW_UpdateString(json,L"changedValues[1].newValue",L"ipsum ex velit");
    CkJsonObjectW_UpdateString(json,L"associatedObjects[0].name",L"qui");
    CkJsonObjectW_UpdateString(json,L"associatedObjects[0].objectType",L"ipsum");
    CkJsonObjectW_UpdateString(json,L"associatedObjects[1].name",L"nostrud consectetur");
    CkJsonObjectW_UpdateString(json,L"associatedObjects[1].objectType",L"sit dolore enim Ut");

    CkHttpW_SetRequestHeader(http,L"Content-Type",L"application/json");

    resp = CkHttpW_PostJson3(http,L"https://your-domain.atlassian.net/wiki/rest/api/audit",L"application/json",json);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        return;
    }

    sbResponseBody = CkStringBuilderW_Create();
    CkHttpResponseW_GetBodySb(resp,sbResponseBody);

    jResp = CkJsonObjectW_Create();
    CkJsonObjectW_LoadSb(jResp,sbResponseBody);
    CkJsonObjectW_putEmitCompact(jResp,FALSE);

    wprintf(L"Response Body:\n");
    wprintf(L"%s\n",CkJsonObjectW_emit(jResp));

    respStatusCode = CkHttpResponseW_getStatusCode(resp);
    wprintf(L"Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",CkHttpResponseW_header(resp));
        wprintf(L"Failed.\n");
        CkHttpResponseW_Dispose(resp);
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        CkStringBuilderW_Dispose(sbResponseBody);
        CkJsonObjectW_Dispose(jResp);
        return;
    }

    CkHttpResponseW_Dispose(resp);

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

    // {
    //   "author": {
    //     "type": "user",
    //     "displayName": "dolore do consectetur veniam",
    //     "operations": null,
    //     "username": "adipisicing nostrud ullamco",
    //     "userKey": "eu in"
    //   },
    //   "remoteAddress": "ea Duis minim p",
    //   "creationDate": -62196571,
    //   "summary": "laboris",
    //   "description": "dolor est sed non officia",
    //   "category": "eiusmod ut nulla",
    //   "sysAdmin": false,
    //   "affectedObject": {
    //     "name": "sint eu labore magna fugiat",
    //     "objectType": "ut exercitation"
    //   },
    //   "changedValues": [
    //     {
    //       "name": "ut ea occaecat ex cupidatat",
    //       "oldValue": "ipsum minim Duis",
    //       "newValue": "esse cupidatat ad"
    //     },
    //     {
    //       "name": "fugiat est enim deserunt commodo",
    //       "oldValue": "quis ipsum",
    //       "newValue": "occaecat Lorem"
    //     }
    //   ],
    //   "associatedObjects": [
    //     {
    //       "name": "in es",
    //       "objectType": "ut reprehenderit mollit exercitation"
    //     },
    //     {
    //       "name": "velit culpa eiusmod",
    //       "objectType": "tempor"
    //     }
    //   ]
    // }

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

    v_Type = CkJsonObjectW_stringOf(jResp,L"author.type");
    DisplayName = CkJsonObjectW_stringOf(jResp,L"author.displayName");
    Operations = CkJsonObjectW_stringOf(jResp,L"author.operations");
    Username = CkJsonObjectW_stringOf(jResp,L"author.username");
    UserKey = CkJsonObjectW_stringOf(jResp,L"author.userKey");
    remoteAddress = CkJsonObjectW_stringOf(jResp,L"remoteAddress");
    creationDate = CkJsonObjectW_IntOf(jResp,L"creationDate");
    summary = CkJsonObjectW_stringOf(jResp,L"summary");
    description = CkJsonObjectW_stringOf(jResp,L"description");
    category = CkJsonObjectW_stringOf(jResp,L"category");
    sysAdmin = CkJsonObjectW_BoolOf(jResp,L"sysAdmin");
    Name = CkJsonObjectW_stringOf(jResp,L"affectedObject.name");
    ObjectType = CkJsonObjectW_stringOf(jResp,L"affectedObject.objectType");
    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"changedValues");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        name = CkJsonObjectW_stringOf(jResp,L"changedValues[i].name");
        oldValue = CkJsonObjectW_stringOf(jResp,L"changedValues[i].oldValue");
        newValue = CkJsonObjectW_stringOf(jResp,L"changedValues[i].newValue");
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"associatedObjects");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        name = CkJsonObjectW_stringOf(jResp,L"associatedObjects[i].name");
        objectType = CkJsonObjectW_stringOf(jResp,L"associatedObjects[i].objectType");
        i = i + 1;
    }



    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(json);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonObjectW_Dispose(jResp);

    }

Curl Command

curl -X POST
	-H "Content-Type: application/json"
	-d '{
    "remoteAddress": "<string>",
    "author": {
        "type": "user",
        "displayName": "<string>",
        "operations": "<object>",
        "username": "<string>",
        "userKey": "<string>"
    },
    "creationDate": "<long>",
    "summary": "<string>",
    "description": "<string>",
    "category": "<string>",
    "sysAdmin": false,
    "affectedObject": {
        "name": "amet dolore",
        "objectType": "labore tempor veniam officia"
    },
    "changedValues": [
        {
            "name": "voluptate sit sed sint ",
            "oldValue": "proident nisi",
            "newValue": "dolore aute cupidatat enim"
        },
        {
            "name": "in eu",
            "oldValue": "enim laborum tempor Lorem",
            "newValue": "ipsum ex velit"
        }
    ],
    "associatedObjects": [
        {
            "name": "qui",
            "objectType": "ipsum"
        },
        {
            "name": "nostrud consectetur",
            "objectType": "sit dolore enim Ut"
        }
    ]
}'
https://your-domain.atlassian.net/wiki/rest/api/audit

Postman Collection Item JSON

{
  "name": "Create audit record",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"remoteAddress\": \"<string>\",\n    \"author\": {\n        \"type\": \"user\",\n        \"displayName\": \"<string>\",\n        \"operations\": \"<object>\",\n        \"username\": \"<string>\",\n        \"userKey\": \"<string>\"\n    },\n    \"creationDate\": \"<long>\",\n    \"summary\": \"<string>\",\n    \"description\": \"<string>\",\n    \"category\": \"<string>\",\n    \"sysAdmin\": false,\n    \"affectedObject\": {\n        \"name\": \"amet dolore\",\n        \"objectType\": \"labore tempor veniam officia\"\n    },\n    \"changedValues\": [\n        {\n            \"name\": \"voluptate sit sed sint \",\n            \"oldValue\": \"proident nisi\",\n            \"newValue\": \"dolore aute cupidatat enim\"\n        },\n        {\n            \"name\": \"in eu\",\n            \"oldValue\": \"enim laborum tempor Lorem\",\n            \"newValue\": \"ipsum ex velit\"\n        }\n    ],\n    \"associatedObjects\": [\n        {\n            \"name\": \"qui\",\n            \"objectType\": \"ipsum\"\n        },\n        {\n            \"name\": \"nostrud consectetur\",\n            \"objectType\": \"sit dolore enim Ut\"\n        }\n    ]\n}"
    },
    "url": {
      "raw": "{{baseUrl}}/api/audit",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "audit"
      ]
    },
    "description": "Creates a record in the audit log.\n\n**[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:\n'Confluence Administrator' global permission."
  },
  "response": [
    {
      "name": "Returned if the record is created in the audit log.",
      "originalRequest": {
        "method": "POST",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"remoteAddress\": \"<string>\",\n    \"author\": {\n        \"type\": \"user\",\n        \"displayName\": \"<string>\",\n        \"operations\": \"<object>\",\n        \"username\": \"<string>\",\n        \"userKey\": \"<string>\"\n    },\n    \"creationDate\": \"<long>\",\n    \"summary\": \"<string>\",\n    \"description\": \"<string>\",\n    \"category\": \"<string>\",\n    \"sysAdmin\": false,\n    \"affectedObject\": {\n        \"name\": \"ut Lorem reprehenderit dolore tempor\",\n        \"objectType\": \"magna consectetur\"\n    },\n    \"changedValues\": [\n        {\n            \"name\": \"in\",\n            \"oldValue\": \"nisi cillum eiusmod exercitation\",\n            \"newValue\": \"in nulla adipisicing ni\"\n        },\n        {\n            \"name\": \"esse ea\",\n            \"oldValue\": \"mollit elit laborum\",\n            \"newValue\": \"sint ut nisi elit\"\n        }\n    ],\n    \"associatedObjects\": [\n        {\n            \"name\": \"veniam qui\",\n            \"objectType\": \"magna laborum mollit\"\n        },\n        {\n            \"name\": \"sit tempor ad id adipisicing\",\n            \"objectType\": \"reprehenderit Duis est ex commodo\"\n        }\n    ]\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/audit",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "audit"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"author\": {\n  \"type\": \"user\",\n  \"displayName\": \"dolore do consectetur veniam\",\n  \"operations\": null,\n  \"username\": \"adipisicing nostrud ullamco\",\n  \"userKey\": \"eu in\"\n },\n \"remoteAddress\": \"ea Duis minim p\",\n \"creationDate\": -62196571,\n \"summary\": \"laboris\",\n \"description\": \"dolor est sed non officia\",\n \"category\": \"eiusmod ut nulla\",\n \"sysAdmin\": false,\n \"affectedObject\": {\n  \"name\": \"sint eu labore magna fugiat\",\n  \"objectType\": \"ut exercitation\"\n },\n \"changedValues\": [\n  {\n   \"name\": \"ut ea occaecat ex cupidatat\",\n   \"oldValue\": \"ipsum minim Duis\",\n   \"newValue\": \"esse cupidatat ad\"\n  },\n  {\n   \"name\": \"fugiat est enim deserunt commodo\",\n   \"oldValue\": \"quis ipsum\",\n   \"newValue\": \"occaecat Lorem\"\n  }\n ],\n \"associatedObjects\": [\n  {\n   \"name\": \"in es\",\n   \"objectType\": \"ut reprehenderit mollit exercitation\"\n  },\n  {\n   \"name\": \"velit culpa eiusmod\",\n   \"objectType\": \"tempor\"\n  }\n ]\n}"
    },
    {
      "name": "Returned if the `remoteAddress` property is not specified.",
      "originalRequest": {
        "method": "POST",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"remoteAddress\": \"<string>\",\n    \"author\": {\n        \"type\": \"user\",\n        \"displayName\": \"<string>\",\n        \"operations\": \"<object>\",\n        \"username\": \"<string>\",\n        \"userKey\": \"<string>\"\n    },\n    \"creationDate\": \"<long>\",\n    \"summary\": \"<string>\",\n    \"description\": \"<string>\",\n    \"category\": \"<string>\",\n    \"sysAdmin\": false,\n    \"affectedObject\": {\n        \"name\": \"ut Lorem reprehenderit dolore tempor\",\n        \"objectType\": \"magna consectetur\"\n    },\n    \"changedValues\": [\n        {\n            \"name\": \"in\",\n            \"oldValue\": \"nisi cillum eiusmod exercitation\",\n            \"newValue\": \"in nulla adipisicing ni\"\n        },\n        {\n            \"name\": \"esse ea\",\n            \"oldValue\": \"mollit elit laborum\",\n            \"newValue\": \"sint ut nisi elit\"\n        }\n    ],\n    \"associatedObjects\": [\n        {\n            \"name\": \"veniam qui\",\n            \"objectType\": \"magna laborum mollit\"\n        },\n        {\n            \"name\": \"sit tempor ad id adipisicing\",\n            \"objectType\": \"reprehenderit Duis est ex commodo\"\n        }\n    ]\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/audit",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "audit"
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}