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());


})();
Posted by:.

One thought on “Calling Jira REST API using Javascript to get user permissions and groups

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s