Created
June 6, 2018 01:11
-
-
Save toru-takahashi/d6abff51d15c8b415a9b9e434b80258a to your computer and use it in GitHub Desktop.
Dump Zendesk Audit Logs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to run
This script export Zendesk auditlogs to CSV file (audit.csv)
Ref. https://developer.zendesk.com/rest_api/docs/core/audit_logs