Chilkat Online Tools

delphiDll / Support API / List Audit Logs

Back to Collection Items

var
http: HCkHttp;
success: Boolean;
queryParams: HCkJsonObject;
resp: HCkHttpResponse;
sbResponseBody: HCkStringBuilder;
jResp: HCkJsonObject;
respStatusCode: Integer;
action: PWideChar;
action_label: PWideChar;
actor_id: PWideChar;
actor_name: PWideChar;
change_description: PWideChar;
created_at: PWideChar;
id: PWideChar;
ip_address: PWideChar;
source_id: PWideChar;
source_label: PWideChar;
source_type: PWideChar;
url: PWideChar;
i: Integer;
count_i: Integer;

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

http := CkHttp_Create();

CkHttp_putBasicAuth(http,True);
CkHttp_putLogin(http,'login');
CkHttp_putPassword(http,'password');

queryParams := CkJsonObject_Create();
CkJsonObject_UpdateString(queryParams,'filter[source_type]','<string>');
CkJsonObject_UpdateString(queryParams,'filter[source_id]','<integer>');
CkJsonObject_UpdateString(queryParams,'filter[actor_id]','<integer>');
CkJsonObject_UpdateString(queryParams,'filter[ip_address]','<string>');
CkJsonObject_UpdateString(queryParams,'filter[created_at]','<string>');
CkJsonObject_UpdateString(queryParams,'filter[action]','<string>');
CkJsonObject_UpdateString(queryParams,'sort_by','<string>');
CkJsonObject_UpdateString(queryParams,'sort_order','<string>');
CkJsonObject_UpdateString(queryParams,'sort','<string>');

CkHttp_SetRequestHeader(http,'Accept','application/json');

resp := CkHttp_QuickRequestParams(http,'GET','https://example.zendesk.com/api/v2/audit_logs',queryParams);
if (CkHttp_getLastMethodSuccess(http) = False) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http));
    Exit;
  end;

sbResponseBody := CkStringBuilder_Create();
CkHttpResponse_GetBodySb(resp,sbResponseBody);

jResp := CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,False);

Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(CkJsonObject__emit(jResp));

respStatusCode := CkHttpResponse_getStatusCode(resp);
Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));
if (respStatusCode >= 400) then
  begin
    Memo1.Lines.Add('Response Header:');
    Memo1.Lines.Add(CkHttpResponse__header(resp));
    Memo1.Lines.Add('Failed.');
    CkHttpResponse_Dispose(resp);
    Exit;
  end;
CkHttpResponse_Dispose(resp);

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

// {
//   "audit_logs": [
//     {
//       "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>"
//     },
//     {
//       "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

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'audit_logs');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    action := CkJsonObject__stringOf(jResp,'audit_logs[i].action');
    action_label := CkJsonObject__stringOf(jResp,'audit_logs[i].action_label');
    actor_id := CkJsonObject__stringOf(jResp,'audit_logs[i].actor_id');
    actor_name := CkJsonObject__stringOf(jResp,'audit_logs[i].actor_name');
    change_description := CkJsonObject__stringOf(jResp,'audit_logs[i].change_description');
    created_at := CkJsonObject__stringOf(jResp,'audit_logs[i].created_at');
    id := CkJsonObject__stringOf(jResp,'audit_logs[i].id');
    ip_address := CkJsonObject__stringOf(jResp,'audit_logs[i].ip_address');
    source_id := CkJsonObject__stringOf(jResp,'audit_logs[i].source_id');
    source_label := CkJsonObject__stringOf(jResp,'audit_logs[i].source_label');
    source_type := CkJsonObject__stringOf(jResp,'audit_logs[i].source_type');
    url := CkJsonObject__stringOf(jResp,'audit_logs[i].url');
    i := i + 1;
  end;

CkHttp_Dispose(http);
CkJsonObject_Dispose(queryParams);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);

Curl Command

curl  -u login:password -G -d "filter[source_type]=%3Cstring%3E"
	-d "filter[source_id]=%3Cinteger%3E"
	-d "filter[actor_id]=%3Cinteger%3E"
	-d "filter[ip_address]=%3Cstring%3E"
	-d "filter[created_at]=%3Cstring%3E"
	-d "filter[action]=%3Cstring%3E"
	-d "sort_by=%3Cstring%3E"
	-d "sort_order=%3Cstring%3E"
	-d "sort=%3Cstring%3E"
	-H "Accept: application/json"
https://example.zendesk.com/api/v2/audit_logs

Postman Collection Item JSON

{
  "name": "List Audit Logs",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v2/audit_logs?filter[source_type]=<string>&filter[source_id]=<integer>&filter[actor_id]=<integer>&filter[ip_address]=<string>&filter[created_at]=<string>&filter[action]=<string>&sort_by=<string>&sort_order=<string>&sort=<string>",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "audit_logs"
      ],
      "query": [
        {
          "key": "filter[source_type]",
          "value": "<string>",
          "description": "Filter audit logs by the source type. For example, user or rule"
        },
        {
          "key": "filter[source_id]",
          "value": "<integer>",
          "description": "Filter audit logs by the source id. Requires `filter[source_type]` to also be set."
        },
        {
          "key": "filter[actor_id]",
          "value": "<integer>",
          "description": "Filter audit logs by the actor id"
        },
        {
          "key": "filter[ip_address]",
          "value": "<string>",
          "description": "Filter audit logs by the ip address"
        },
        {
          "key": "filter[created_at]",
          "value": "<string>",
          "description": "Filter audit logs by the time of creation"
        },
        {
          "key": "filter[action]",
          "value": "<string>",
          "description": "Filter audit logs by the action"
        },
        {
          "key": "sort_by",
          "value": "<string>",
          "description": "Offset pagination only. Sort audit logs. Default is `sort_by=created_at`"
        },
        {
          "key": "sort_order",
          "value": "<string>",
          "description": "Offset pagination only. Sort audit logs. Default is `sort_order=desc`"
        },
        {
          "key": "sort",
          "value": "<string>",
          "description": "Cursor pagination only. Sort audit logs. Default is `sort=-created_at`"
        }
      ]
    },
    "description": "#### Allowed For\n\n* Admins on accounts that have audit log access\n\n#### Pagination\n\n* Cursor pagination (recommended)\n* Offset pagination\n\nSee [Pagination](/api-reference/introduction/pagination/).\n\nReturns a maximum of 100 records per page.\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?filter[source_type]=<string>&filter[source_id]=<integer>&filter[actor_id]=<integer>&filter[ip_address]=<string>&filter[created_at]=<string>&filter[action]=<string>&sort_by=<string>&sort_order=<string>&sort=<string>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "audit_logs"
          ],
          "query": [
            {
              "key": "filter[source_type]",
              "value": "<string>",
              "description": "Filter audit logs by the source type. For example, user or rule"
            },
            {
              "key": "filter[source_id]",
              "value": "<integer>",
              "description": "Filter audit logs by the source id. Requires `filter[source_type]` to also be set."
            },
            {
              "key": "filter[actor_id]",
              "value": "<integer>",
              "description": "Filter audit logs by the actor id"
            },
            {
              "key": "filter[ip_address]",
              "value": "<string>",
              "description": "Filter audit logs by the ip address"
            },
            {
              "key": "filter[created_at]",
              "value": "<string>",
              "description": "Filter audit logs by the time of creation"
            },
            {
              "key": "filter[action]",
              "value": "<string>",
              "description": "Filter audit logs by the action"
            },
            {
              "key": "sort_by",
              "value": "<string>",
              "description": "Offset pagination only. Sort audit logs. Default is `sort_by=created_at`"
            },
            {
              "key": "sort_order",
              "value": "<string>",
              "description": "Offset pagination only. Sort audit logs. Default is `sort_order=desc`"
            },
            {
              "key": "sort",
              "value": "<string>",
              "description": "Cursor pagination only. Sort audit logs. Default is `sort=-created_at`"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"audit_logs\": [\n    {\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    {\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  ]\n}"
    }
  ]
}