Useful simple code in Javascript to get the username and groups of the current user in Jira using the public REST API.
(function() { function getCurrentUserData() { var user; AJS.$.ajax({ url: "/rest/api/2/myself", type: 'get', dataType: 'json', async: false, success: function(data) { user = data.key; } }); return user; } function getCurrentUserGroups() { var user; AJS.$.ajax({ url: "/rest/api/2/myself?expand=groups", type: 'get', dataType: 'json', async: false, success: function(data) { group = data.groups.items[0].name; } }); return group; } alert("User:" + getCurrentUserData()+ " Group:"+ getCurrentUserGroups()); })();
One thought on “Calling Jira REST API using Javascript to get user permissions and groups”