forked from gabrielsroka/gabrielsroka.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExportZendeskAgentsToCSV.html
66 lines (63 loc) · 2.5 KB
/
ExportZendeskAgentsToCSV.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<!doctype html>
<html>
<head>
<title>Export Zendesk Agents To CSV</title>
<style>
body {
font-family: sans-serif;
}
</style>
</head>
<body>
<h1>Export Zendesk Agents To CSV</h1>
<p>This tool will export Zendesk agents to a CSV file.</p>
<b>Setup</b>
<ol>
<li>Show your bookmarks toolbar. In Chrome, … > Bookmarks > Show Bookmarks Bar. In Firefox, right-click in the title bar and click Bookmarks Toolbar.
<li>Drag/drop this <a id=bm>Export Agents</a> to the bookmarks toolbar.
</ol>
<br>
<b>Usage</b>
<ol>
<li>Open Zendesk and sign in.
<li>Click the "Export Agents" button from your bookmarks toolbar.
</ol>
<br>
<a href=https://github.com/gabrielsroka/gabrielsroka.github.io/blob/master/ExportZendeskAgentsToCSV.html>Source code</a>
<script id=code>
(async function () {
/* See https://developer.zendesk.com/api-reference/ticketing/ticket-management/search/ */
var url = '/api/v2/search.json?query=role:agent'; /* &per_page=1, page=2 */
const results = [];
while (url) {
const r = await fetch(url);
const data = await r.json();
data.results.forEach(r => results.push(toCSV(r.id, r.email, r.name, r.role, r.active)));
url = data.next_page;
}
downloadCSV('id,email,name,role,active', results, 'Zendesk Agents');
/* all columns:
'active', 'alias', 'created_at', 'custom_role_id', 'default_group_id', 'details', 'email',
'external_id', 'iana_time_zone', 'id', 'last_login_at', 'locale', 'locale_id', 'moderator', 'name', 'notes',
'only_private_comments', 'organization_id', 'phone', 'photo', 'report_csv', 'restricted_agent', 'result_type',
'role', 'role_type', 'shared', 'shared_agent', 'shared_phone_number', 'signature', 'suspended', 'tags',
'ticket_restriction', 'time_zone', 'two_factor_auth_enabled', 'updated_at', 'url', 'user_fields', 'verified'
*/
function downloadCSV(header, lines, filename) {
const a = document.body.appendChild(document.createElement("a"));
a.href = URL.createObjectURL(new Blob([header + "\n" + lines.join("\n")], {type: 'text/csv'}));
const date = (new Date()).toISOString().replace(/T/, " ").replace(/:/g, "-").slice(0, 19);
a.download = `${filename} ${date}.csv`;
a.click();
document.body.removeChild(a);
}
function toCSV(...fields) {
return fields.map(field => `"${field == undefined ? "" : field.toString().replace(/"/g, '""')}"`).join(',');
}
})
</script>
<script>
bm.href = 'javascript:' + code.innerText + '();';
</script>
</body>
</html>