none
Trying To Read User Profile Properties Using REST API RRS feed

  • Question

  • I keep getting this response text:

    {"code":"-1, Microsoft.Sharepoint.Client.InvalidClientQueryException","message":{"lang":"en-US", "value":"The query string \"accountName\" is missing or invalid."}}}

    and my targetUser (for my user account) in the "domainName\userName" format looks like this:

    xxxxxxxxxx.xxxxxx.xxx\hversemann@xxxxxx.xxx

    The url that I'm using to hit the API looks like this:

    https://xxxxxxxxxx.xxxxxx.xxx/xxxxxxxxxxxx/henrys/_api/SpP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v=xxxxxxxxxx.xxxxxx.xxx\hversemann@xxxxxx.xxx

    and based on what little I know actually looks good, to me.

    I can see all of my own available properties if I hit the API using GetMyProperties endpoint, but can't get them this way.

    Any idea why?

    Thanks for looking.

    Henry

    Wednesday, April 5, 2017 7:36 PM

Answers

  • Hi Henry,

    Please go to Central Administration-> Manage service applications->User Profile Service Application->Manage User Profiles. Then check the user profile.

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Friday, April 7, 2017 1:56 AM
    Moderator

All replies

  • Hi,

    Please try the below

    https://social.technet.microsoft.com/Forums/office/en-US/e8665952-edd7-4da4-9ac5-f4fa32616e06/how-to-retrieve-user-profile-propertieseg-picture-using-rest-sharepoint?forum=sharepointdevelopment


    Please remember to click Mark as Answer on the answer if it helps you

    Wednesday, April 5, 2017 8:03 PM
  • Hi 

    The user name needs to be URL encoded. Assuming you are targeting SharePoint Online, try the following

    _api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v=%27i%3A0%23.f%7Cmembership%7reshmee%40domain.onmicrosoft.com%27

    Good luck

    Reshmee 

    Wednesday, April 5, 2017 8:54 PM
  • Hi Henry,

    Please check the following code. Add the code below into a script editor web part to test it.

    <script src="//code.jquery.com/jquery-3.1.0.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(function () {
    	var user="denguo\\administrator";
    	var userProperties=GetUserProperties(user);
    	alert(userProperties);
    });
    
    function GetUserProperties(user){
    	var userProperties="";
    	var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='"+user+"'";
    	$.ajax({
    		url: requestUri,
    		method: "GET",
    		async: false,
    		headers: { "Accept": "application/json; odata=verbose" },
    		success: function (data) {					 
    			userProperties="MY PROPERTIES ARE:\n DISPLAY NAME("+data.d.DisplayName+"),\n ACCOUNT NAME("+data.d.AccountName+"),\n EMAIL("+data.d.Email+"),\n TITLE("+data.d.Title+"),\n PICTURE-URL("+data.d.PictureUrl+").\n";
    		},
    		error: function (data) {
    		}
    	});
    	return userProperties;
    }
    </script>

    If it still not works, please check the account name in AD.

    Best Regard,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com


    Thursday, April 6, 2017 3:15 AM
    Moderator
  • You can utilize $().SPServices.GetUserProfileByName to access the user profile details

    var profile = {};
    $().SPServices({
        operation: "GetUserProfileByName",
        async: false,
        AccountName: 'i:0#.f|membership|amitkumar@amitkumarmca04.blogspot.com',
        completefunc: function (xData, Status) {
            $(xData.responseXML).find("PropertyData").each(function (idx, val) {
                var $val = $(val);
                var name = $val.find("Name").text();
                var value = $val.find("Value").text();
                profile[name] = value;
            });
    
    
        }
    });
    console.log(profile);
    

    You can get following values

    1.	AboutMe:""
    2.	AccountName:"i:0#.f|membership|amitkumar@amitkumarmca04.blogspot.com"
    3.	Assistant:""
    4.	CellPhone:""
    5.	DelveFlags:""
    6.	Department:""
    7.	Fax:""
    8.	FirstName:"Amit"
    9.	HomePhone:""
    10.	LastName:"Kumar"
    11.	Manager:"i:0#.f|membership|manager@amitkumarmca04.blogspot.com"
    12.	Office:"Bengaluru "
    13.	OfficeGraphEnabled:""
    14.	PersonalSpace:"/personal/amitkumar_amitkumarmca04_blogspot_com /"
    15.	PictureURL:""
    16.	PreferredName:"Kumar, Amit AK"
    17.	PublicSiteRedirect:"https://Office.com/experience.aspx?accountname=amitkumar"
    18.	PulseMRUPeople:""
    19.	QuickLinks:""
    20.	SPS-AdjustHijriDays:""
    21.	SPS-AltCalendarType:""
    22.	SPS-Birthday:""
    23.	SPS-CalendarType:""
    24.	SPS-ClaimID:"amitkumarmca04.blogspot.com"
    25.	SPS-ClaimProviderID:"membership"
    26.	SPS-ClaimProviderType:"Forms"
    27.	SPS-ContentLanguages:""
    28.	SPS-Department:""
    29.	SPS-DisplayOrder:""
    30.	SPS-DistinguishedName:"CN=xx,OU=xx,OU=xx,OU=MSOnline,DC=xx,DC=msft,DC=net"
    31.	SPS-DontSuggestList:""
    32.	SPS-Dotted-line:""
    33.	SPS-EmailOptin:"0"
    34.	SPS-FeedIdentifier:""
    35.	SPS-FirstDayOfWeek:""
    36.	SPS-FirstWeekOfYear:""
    37.	SPS-HashTags:""
    38.	SPS-HideFromAddressLists:""
    39.	SPS-HireDate:""
    40.	SPS-Interests:""
    41.	SPS-JobTitle:"Technical Architect"
    42.	SPS-LastColleagueAdded:""
    43.	SPS-LastKeywordAdded:""
    44.	SPS-Locale:""
    45.	SPS-Location:""
    46.	SPS-MUILanguages:""
    47.	SPS-MasterAccountName:""
    48.	SPS-MultiGeoFlags:""
    49.	SPS-MySiteUpgrade:""
    50.	SPS-O15FirstRunExperience:"1000"
    51.	SPS-OWAUrl:""
    52.	SPS-ObjectExists:""
    53.	SPS-PastProjects:""
    54.	SPS-Peers:""
    55.	SPS-PersonalSiteCapabilities:"4"
    56.	SPS-PersonalSiteFirstCreationError:"Personal Site already exists."
    57.	SPS-PersonalSiteFirstCreationTime:"xxx-xx-xx:xx:xx"
    58.	SPS-PersonalSiteInstantiationState:"2"
    59.	SPS-PersonalSiteLastCreationTime:" xx-xx-xx:01:10"
    60.	SPS-PersonalSiteNumberOfRetries:"1"
    61.	SPS-PhoneticDisplayName:""
    62.	SPS-PhoneticFirstName:""
    63.	SPS-PhoneticLastName:""
    64.	SPS-PictureExchangeSyncState:"0"
    65.	SPS-PicturePlaceholderState:"1"
    66.	SPS-PictureTimestamp:"46466"
    67.	SPS-PointPublishingUrl:""
    68.	SPS-PrivacyActivity:"0"
    69.	SPS-PrivacyPeople:"false"
    70.	SPS-ProxyAddresses:""
    71.	SPS-RecipientTypeDetails:"100"
    72.	SPS-RegionalSettings-FollowWeb:""
    73.	SPS-RegionalSettings-Initialized:""
    74.	SPS-ResourceAccountName:""
    75.	SPS-Responsibility:""
    76.	SPS-SavedAccountName:"i:0#.f|membership|amitkumar@amitkumarmca04.blogspot.com"
    77.	SPS-School:""
    78.	SPS-SharePointHomeExperienceState:""
    79.	SPS-ShowWeeks:""
    80.	SPS-SipAddress:"amitkumar@amitkumarmca04.blogspot.com"
    81.	SPS-Skills:""
    82.	SPS-SourceObjectDN:""
    83.	SPS-StatusNotes:""
    84.	SPS-TenantInstanceId:""
    85.	SPS-Time24:""
    86.	SPS-TimeZone:""
    87.	SPS-UserPrincipalName:"amitkumar@amitkumarmca04.blogspot.com"
    88.	SPS-UserType:"0"
    89.	SPS-WorkDayEndHour:""
    90.	SPS-WorkDayStartHour:""
    91.	SPS-WorkDays:""
    92.	Title:"Technical Architect"
    93.	UserName:"amitkumar@amitkumarmca04.blogspot.com"
    94.	UserProfile_GUID:"xxx-xx-1234-4464-XXXXXX"
    95.	VideoUserPopup:""
    96.	WebSite:""
    97.	WorkEmail:"amitkumar@amitkumarmca04.blogspot.com"
    98.	WorkPhone:""
    99.	msOnline-ObjectId:"xxx-xx-xx-xx-xxxxx"
    


    Thanks, Amit Kumar, LinkedIn Profile ** My Blog

    Thursday, April 6, 2017 1:17 PM
  • Amit,

    I am working in a test system version of sharepoint, which is on-premises.

    So would the code be the same for that and if so then would the name format be in this format:

    "domain\\username"

    Please explain further.

    Thanks.

    Henry

    Thursday, April 6, 2017 6:56 PM
  • Dennis,

    Thanks for the reply.

    The system I'm testing in is an on-premises test system. I will check or find out from one of my colleagues how things look in Active Driectory.

    We really have no idea how much user profile information is currently being built into our tests system(it was loaded by a third party vendor when Sharepoint was installed on our system), so is it possible that maybe we have very little or no user-profile information being built into it?

    If so is there a way to tell or somewhere to look in sharepoint, to see or look at an overview of all the user accounts/userprofiles which are currently housed in our test system, using some kind of programmatic inquiry that I can execute within sharepoint, to find out any of this information?

    Let me know when you can.

    Thanks.

    Henry

    Thursday, April 6, 2017 7:08 PM
  • Reshmee,

    Thanks for responding I have tried to resolve my problem by encoding the targetUser and so far it has not made a difference.

    I will do that from now on.

    Thanks for the help.

    Henry

    Thursday, April 6, 2017 7:12 PM
  • Hi Henry,

    Please go to Central Administration-> Manage service applications->User Profile Service Application->Manage User Profiles. Then check the user profile.

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Friday, April 7, 2017 1:56 AM
    Moderator
  • Hi Henry,

    The "AccountName" for on-prem would be "domain\\username", but please verify by running "$().SPServices.SPGetCurrentUser()" in console. 


    Thanks, Amit Kumar, LinkedIn Profile ** My Blog

    Friday, April 7, 2017 5:20 AM
  • Dennis,

    I forwarded your last response to a colleague who has been working with me in our test portal and he took a look at my user profile and he forwarded back to me a screen print which showed my profile as almost completely empty. The fields in it which were formatted were job-title. department, and the very first field which did not show a label, but did show a value of STA\hversemann which is probably my username. so I asked him to let me know if his profile looked the same as mine as well as look for the profiles of other people in our team. Then I asked him if it might be possible to just populate some dummy data into some dummy user profiles. This seems to explain why I haven't been able to see much of my own data, because most of its not been formatted into my profile. So as far as testing this part of my code, I'm going to try to get him populate some dummy data for me to test with.

    Thanks for the help and suggestions.

    Henry

    Friday, April 7, 2017 2:03 PM
  • Amit,

    I tried to run the code you suggested above like this:

    var accntName = "xxxxxxxxxx.xxxxxx.xxx\\hversemann@xxxxxx.xxx";
    var profile = {};

    $().SPServices(
    {
        operation: "GetCurrentUser",
        async: false,
        AccountName: accntName,
        completeFunc: function (xData, Status)
        {
            $(xData.responseXML).find("PropertyData").each(function (idx, val) 
    {
                var $val = $(val);
                var name = $val.find("Name").text();
                var value = $val.find("Value").text();
                profile[name] = value;
    });
        }
    });

    console.log(profile);

    and I'm getting this error from it:

    SCRIPT438: Object doesn't support property or method 'SPServices'

    Friday, April 7, 2017 2:42 PM