REST call to get user email

To use the following function to retrieve the user email from the SharePoint User Profile service, you would need to pass in the account name of the user.

GetUserEmail = (function () {
    "use strict";
    var _webUrl = "http://myurl.com";
    var load = function (selectedValue) {

        $.ajax({
            cache: false,
           url: _webUrl + "/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='" + encodeURIComponent(selectedValue) + "'&$select=Email",

            type: 'GET',
            headers: {
                "Accept": "application/json;odata=verbose"
            },
            success: function (data) {
                alert(JSON.stringify(data));
                var email = data.d.Email;
                $("#EmailContainer").val(email);

            }, 
            error: function (response) {
                alert(response.status + "  " + response.statusText);
            }

        });

    };
    return {
        load: load
    };
}());

Leave a Reply