In this blog, I have explained how to get the current user properties using AJAX call.
Introduction
In the demonstration, we get the current logged in user profile properties, like email, name, job title, profile URL, picture etc.
GetMyProperties
This property name helps to get the current user properties.
REST URL
http://<site url>/_api/sp.userprofiles.peoplemanager/<property name>
Let’s build the code to retrieve the current user properties.
Add jQuery reference.
Code
- <script src="https://sharepointtechie.sharepoint.com/sites/appnfc/SiteAssets/jquery-1.7.1.min.js" type="text/javascript"></script>
Ajax Request
- var reqUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/sp.userprofiles.peoplemanager/GetMyProperties";
- // Get the Api
- $.ajax(
- {
- url: reqUrl, type: "GET", headers:
- {
- "accept": "application/json;odata=verbose"
- },
- success: successHandler, error: errorHandler
- });
- function successHandler(data)
- {
- console.log(data);
- var Name = data.d.DisplayName;
- var email = data.d.Email;
- var oneUrl = data.d.PersonalUrl;
- var imgUrl = data.d.PictureUrl;
- var jobTitle = data.d.Title;
- var profUrl = data.d.UserUrl;
- var html = '';
- // Rendering the HTML structure html
- += "<li>Name: "+ Name +"</li>
- </br>
- <li>Email: "+ email +"
- </li>
- </br>
- <li>Personal: <a href ='"+ oneUrl +"'>One Drive</a></li> </br>
- <li>Profile Image: <img src ='" +imgUrl +"' alt='' width='40' height='40'></img></li></br>"; html += "<li>Job Title: "+ jobTitle +"</li>
- </br>
- <li>My Profile: <a href ="+ profUrl +">View my full profile</a></li>";
- $("#info").append(html);
- $('#new').attr('src', data.d.PictureUrl);
- }
- function errorHandler(error)
- {
- alert(JSON.stringify(error));
- }



Madhan ThuraiPosted Aug 21, 2017, 2:44 AM
Good One.......... (Y)