Skip to content

Instantly share code, notes, and snippets.

@toru-takahashi
Created June 6, 2018 01:11
Show Gist options
  • Save toru-takahashi/d6abff51d15c8b415a9b9e434b80258a to your computer and use it in GitHub Desktop.
Save toru-takahashi/d6abff51d15c8b415a9b9e434b80258a to your computer and use it in GitHub Desktop.
Dump Zendesk Audit Logs
import requests
import pandas as pd
from pandas.io.json import json_normalize
import time
url = 'https://ZENDESKDOMAIN.zendesk.com/api/v2/audit_logs.json?sort_order=desc'
user = 'ZENDESK_EMAIL' + '/token'
pwd = 'ZENDESK_APIKEY'
session = requests.Session()
session.auth = (user, pwd)
auditlog_results = []
while url:
response = session.get(url)
if response.status_code == 429:
print('Rate limited! Please wait.')
time.sleep(int(response.headers['retry-after']))
continue
if response.status_code != 200:
print('Status:', response.status_code, 'Problem with the request. Exiting.')
exit()
data = response.json()
auditlog_results.extend(data['audit_logs'])
url = data['next_page']
p = json_normalize(auditlog_results)
p.to_csv('audit.csv')
@toru-takahashi
Copy link
Author

How to run

pip install pandas
python dump_zendesk_auditlog.py

This script export Zendesk auditlogs to CSV file (audit.csv)

Ref. https://developer.zendesk.com/rest_api/docs/core/audit_logs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment