Articles about European Sharepoint Hosting Service
Getting Current Logged In User Using Rest API In SharePoint Online And Get User Details Using User ID
There are two important REST API Services available to get the current logged in user or get full account details using the userId.
1 |
https://<<site details>>/sites/_api/web/currentuser |
This will return complete details of the current logged user in your data in XML. If it is run in the browser itself, we can create an AJAX call and get particular value (or) filter it.
1 |
https://<<site details>>/sites/_api/web/currentuser/_api/web/currentuser?$select=Title,Email,Id |
Another way of getting value using User Id value is to consume “_layouts/15/userdisp.aspx” and pass userId as query string value and get complete myblog site as response.
1 |
https://<<site details>>/sites/_api/web/currentuser/_layouts/15/userdisp.aspx??ID=<User ID value> |
Complete function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
function GetUserDetails() { var url = "https://XXXXX.sharepoint.com/sites/testsite" + "/_api/web/currentuser"; $.ajax({ url: url, headers: { Accept: "application/json;odata=verbose" }, async: false, success: function (data) { var items = data.d.results; // Data will have user object }, eror: function (data) { alert("An error occurred. Please try again."); } }); } |
Debugger Console screenshot.
The Data object contains all user profile properties.
Print article | This entry was posted by Peter on June 21, 2017 at 7:30 am, and is filed under European SharePoint 2013 Hosting. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |