1

I have a problem with SharePoint REST service. I can not get the User properties by User Id. This is my approach:

function GetUserByID(id) {
jQuery.ajax({
    url: "/_api/Web/GetUserById('" + id + "')",
    type: "GET",
    headers: {
        "accept": "application/json;odata=verbose"
    },
    success: function (data) {
        if (data.d != null) {
            GetUserProfile(data.d.LoginName);
        }
    },
    error: function (err) {
        alert(JSON.stringify(err));
    }
});}

function GetUserProfile(loginName) {
jQuery.ajax({
    url: "/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='" + loginName + "'",
    type: "GET",
    headers: {
        "accept": "application/json;odata=verbose",
        "X-RequestDigest": $("#__REQUESTDIGEST").val()
    },
    success: function (data) {
        alert(JSON.stringify(data.d));
    },
    error: function (err) {
        alert(JSON.stringify(err));
    }
});}

I can get the loginName (ex: SharePoint\System) by User Id and then I use it for retreiving the User properties, but the response data is empty.

When I use "/_api/SP.UserProfiles.PeopleManager/GetMyProperties?$select=PictureUrl,AccountName", I can get the User properties(SharePoint\System).

  • i would love to know if I can get userprofile via a user id ... it would be great and save me a lot of performance – Alex Jun 5 '15 at 13:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.