SharePoint 2013 REST call - Get Current User

function getCurrentUser(){          
   var ajax = $.ajax({
       url:   _spPageContextInfo.siteAbsoluteUrl + "/_api/web/currentUser",
       method: "GET",
       headers: { "Accept": "application/json; odata=verbose" },
       error: function (data) {
           console.log(data);
          }
        });
       return ajax;
}
function getUserGroups (userId) {  
   var ajax = $.ajax  ({  
        url:  _spPageContextInfo.siteAbsoluteUrl + "/_api/web/GetUserById('"   + userId + "')/Groups",  
        method: "GET",  
           headers: { "Accept": "application/json; odata=verbose" }            
     });  
    return ajax;
    }
 
getCurrentUser().done(function(userId){
   getUserGroups(userId.d.Id).done(function(groups){                
       console.log(groups.d.results);
   });
});

Source:

http://michaelsoriano.com/understanding-sharepoint-rest-api-part-1-selecting-items/

Comments

Popular posts from this blog

IRM and the Object Model

This content database has a schema version which is not supported in this farm

Activate and Deactivate Feature through PowerShell