locked
REST API "GetUserProfilePropertiesFor" doesn't work RRS feed

  • Question

  • Hi everybody,

    i'am trying to get user properties (UserUrl, PictureUrl) using REST API "GetUserProfilePropertiesFor", but it doesn't work. Please anybody provide a "work"-example! Thanks a lot!

    The examples I got from next page (see 6. Get Multiple UserProfile Properties for Specific User).

    I tried also another simple way: 

    var x = "i:0#.w|sp20130\demo";
    		jQuery.ajax({
    		  url: _spPageContextInfo.webServerRelativeUrl + "/_api/sp.userprofiles.peoplemanager/getuserprofilepropertyfor(accountame=@v, propertyname='PictureURL')?@v='"+x+"'",
    		  type: "GET",
    		  headers: { "accept": "application/json;odata=verbose" },
    		  success: function (data) {
    				var result = data.d;
    				console.log(data.d);
    			},
    			error: function (err) {
    				alert(JSON.stringify(err));
    			}
    		});


    Every time I receive back a error - "Bad request".

    At this moment I have only one idea - it is a wrong url (problem with encoding of login name).

    #########################

    UPDATE! SOLUTION:

    var accountName = "sp20130\\demo";
    		jQuery.ajax({
    			url: siteUrl + "/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='" + encodeURIComponent(accountName) + "'",
    			method: "GET",
    			headers: { "Accept": "application/json; odata=verbose" },
    			success: function (data) {
    				console.log(data.d); 
    				var pictureUrl = data.d.PictureUrl;
    				var userUrl = data.d.UserUrl;
    				...
    			},
    			error: function (data) {
    				console.log(JSON.stringify(data));
    			}
    		});






    Saturday, March 5, 2016 8:13 PM

Answers

  • I found a solution for my problem!)

    The main part of script was ok, but login should be in the format: "domain\\login" (double slashes).

    var accountName = "sp20130\\demo";
    		jQuery.ajax({
    			url: siteUrl + "/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='" + encodeURIComponent(accountName) + "'",
    			method: "GET",
    			headers: { "Accept": "application/json; odata=verbose" },
    			success: function (data) {
    				console.log(data.d); 
    				var pictureUrl = data.d.PictureUrl;
    				var userUrl = data.d.UserUrl;
    				...
    			},
    			error: function (data) {
    				console.log(JSON.stringify(data));
    			}
    		});


    from MSDN forum...

    Sunday, March 6, 2016 8:49 PM

All replies

  • Hope below link will work for you

    http://aaclage.blogspot.ae/2015/05/get-user-profile-properties-and-update.html


    Regards, Sachin

    • Proposed as answer by Sachin Choube Sunday, March 6, 2016 12:56 PM
    Sunday, March 6, 2016 12:56 PM
  • Hope below link will work for you

    http://aaclage.blogspot.ae/2015/05/get-user-profile-properties-and-update.html


    Regards, Sachin

    Thanks for your resource, but I'm try to use this code not in the SharePoint App. I found my problem, it was very simple :), see below.

    from MSDN forum...

    Sunday, March 6, 2016 8:45 PM
  • I found a solution for my problem!)

    The main part of script was ok, but login should be in the format: "domain\\login" (double slashes).

    var accountName = "sp20130\\demo";
    		jQuery.ajax({
    			url: siteUrl + "/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='" + encodeURIComponent(accountName) + "'",
    			method: "GET",
    			headers: { "Accept": "application/json; odata=verbose" },
    			success: function (data) {
    				console.log(data.d); 
    				var pictureUrl = data.d.PictureUrl;
    				var userUrl = data.d.UserUrl;
    				...
    			},
    			error: function (data) {
    				console.log(JSON.stringify(data));
    			}
    		});


    from MSDN forum...

    Sunday, March 6, 2016 8:49 PM
  • Hi,

    Thanks for sharing! It will help others who suck with the problem!

    Best Regards,

    Dennis


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

    Tuesday, March 8, 2016 1:45 AM