Skip to content

Instantly share code, notes, and snippets.

@tstachl
Created December 18, 2013 02:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tstachl/8016456 to your computer and use it in GitHub Desktop.
Save tstachl/8016456 to your computer and use it in GitHub Desktop.
This gist shows a very simple way of fetching all admin users in your desk.com account and displaying it in a knowledge base article. IMPORTANT: this will only work if you're logged in as a desk.com agent and should never be a public article.
<style>
table#users { width: 100%; }
table#users th { font-weight: bold; font-size: 120%; }
</style>
<table class="table table-striped" id="users">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Level</th>
<th>Last Login</th>
</thead>
<tbody>
</tbody>
</table>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.4.0/moment.min.js"></script>
<script>
(function($) {
$el = $('#users tbody');
function processUsers(users) {
$.each(users._embedded.entries, function(idx, user) {
if (!user.level.match('admin')) return;
$([
'<tr>',
' <td>' + user.name + '</td>',
' <td><a href="mailto:' + user.email + '">' + user.email + '</a></td>',
' <td>' + user.level + '</td>',
' <td>' + moment(user.last_login_at).format('lll') + '</td>',
'</tr>'
].join("\n")).appendTo($el);
});
if (users._links.next) { $.getJSON(users._links.next.href, processUsers); }
}
$.getJSON('/api/v2/users', processUsers);
}(jQuery));
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment