Chilkat Online Tools

unicodeC / Support API / Show Audit Log

Back to Collection Items

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

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkStringBuilderW sbResponseBody;
    HCkJsonObjectW jResp;
    int respStatusCode;
    const wchar_t *Action;
    const wchar_t *Action_label;
    const wchar_t *Actor_id;
    const wchar_t *Actor_name;
    const wchar_t *Change_description;
    const wchar_t *Created_at;
    const wchar_t *Id;
    const wchar_t *Ip_address;
    const wchar_t *Source_id;
    const wchar_t *Source_label;
    const wchar_t *Source_type;
    const wchar_t *v_Url;

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

    http = CkHttpW_Create();

    CkHttpW_putBasicAuth(http,TRUE);
    CkHttpW_putLogin(http,L"login");
    CkHttpW_putPassword(http,L"password");

    CkHttpW_SetRequestHeader(http,L"Accept",L"application/json");

    sbResponseBody = CkStringBuilderW_Create();
    success = CkHttpW_QuickGetSb(http,L"https://example.zendesk.com/api/v2/audit_logs/:audit_log_id",sbResponseBody);
    if (success == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkStringBuilderW_Dispose(sbResponseBody);
        return;
    }

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

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

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

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

    // {
    //   "audit_log": {
    //     "action": "<string>",
    //     "action_label": "<string>",
    //     "actor_id": "<integer>",
    //     "actor_name": "<string>",
    //     "change_description": "<string>",
    //     "created_at": "<dateTime>",
    //     "id": "<integer>",
    //     "ip_address": "<string>",
    //     "source_id": "<integer>",
    //     "source_label": "<string>",
    //     "source_type": "<string>",
    //     "url": "<string>"
    //   }
    // }

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

    Action = CkJsonObjectW_stringOf(jResp,L"audit_log.action");
    Action_label = CkJsonObjectW_stringOf(jResp,L"audit_log.action_label");
    Actor_id = CkJsonObjectW_stringOf(jResp,L"audit_log.actor_id");
    Actor_name = CkJsonObjectW_stringOf(jResp,L"audit_log.actor_name");
    Change_description = CkJsonObjectW_stringOf(jResp,L"audit_log.change_description");
    Created_at = CkJsonObjectW_stringOf(jResp,L"audit_log.created_at");
    Id = CkJsonObjectW_stringOf(jResp,L"audit_log.id");
    Ip_address = CkJsonObjectW_stringOf(jResp,L"audit_log.ip_address");
    Source_id = CkJsonObjectW_stringOf(jResp,L"audit_log.source_id");
    Source_label = CkJsonObjectW_stringOf(jResp,L"audit_log.source_label");
    Source_type = CkJsonObjectW_stringOf(jResp,L"audit_log.source_type");
    v_Url = CkJsonObjectW_stringOf(jResp,L"audit_log.url");


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

    }

Curl Command

curl  -u login:password -X GET
	-H "Accept: application/json"
https://example.zendesk.com/api/v2/audit_logs/:audit_log_id

Postman Collection Item JSON

{
  "name": "Show Audit Log",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v2/audit_logs/:audit_log_id",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "audit_logs",
        ":audit_log_id"
      ],
      "variable": [
        {
          "key": "audit_log_id",
          "value": "<integer>"
        }
      ]
    },
    "description": "#### Allowed For\n\n* Admins on accounts that have audit-log access\n"
  },
  "response": [
    {
      "name": "Success response",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": "Added as a part of security scheme: basic",
            "key": "Authorization",
            "value": "Basic <credentials>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v2/audit_logs/:audit_log_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "audit_logs",
            ":audit_log_id"
          ],
          "variable": [
            {
              "key": "audit_log_id"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"audit_log\": {\n    \"action\": \"<string>\",\n    \"action_label\": \"<string>\",\n    \"actor_id\": \"<integer>\",\n    \"actor_name\": \"<string>\",\n    \"change_description\": \"<string>\",\n    \"created_at\": \"<dateTime>\",\n    \"id\": \"<integer>\",\n    \"ip_address\": \"<string>\",\n    \"source_id\": \"<integer>\",\n    \"source_label\": \"<string>\",\n    \"source_type\": \"<string>\",\n    \"url\": \"<string>\"\n  }\n}"
    }
  ]
}