Created
December 18, 2013 02:36
-
-
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.
This file contains hidden or 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
<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