There are two important REST API Services available to get the current logged in user or get full account details using the userId.
- 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.
- https://<<site details>>/sites/_api/web/currentuser/_api/web/currentuser?$select=Title,Email,Id
- https://<<site details>>/sites/_api/web/currentuser/_layouts/15/userdisp.aspx??ID=<User ID value>
- 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.");
- }
- });
- }
The Data object contains all user profile properties.
Join the conversation! Your thoughts help the community grow.