2

I have a custom user profile property named "My-Property".

I want to retrieve this property from a rest call.

How can I handle the dash in the property name ?

I tried :

  • http://server/_api/SP.UserProfiles.PeopleManager/GetMyProperties/?$select=My-Property
  • http://server/_api/SP.UserProfiles.PeopleManager/GetMyProperties/My-Property
  • http://server/_api/SP.UserProfiles.PeopleManager/GetMyProperties/?$select=My%20Property
  • http://server/_api/SP.UserProfiles.PeopleManager/GetMyProperties/My%20Property
  • http://server/_api/SP.UserProfiles.PeopleManager/GetMyProperties/?$select=MyProperty
  • http://server/_api/SP.UserProfiles.PeopleManager/GetMyProperties/MyProperty
  • http://server/_api/SP.UserProfiles.PeopleManager/GetMyProperties/?$select=MyProperty
  • http://server/_api/SP.UserProfiles.PeopleManager/GetMyProperties/?$select=UserProfileProperties/My-Property&$expand=UserProfileProperties/My-Property
  • http://server/_api/SP.UserProfiles.PeopleManager/GetMyProperties/?$select=UserProfileProperties/My%2DProperty&$expand=UserProfileProperties/My%2DProperty
  • http://server/_api/SP.UserProfiles.PeopleManager/GetMyProperties/?$select=UserProfileProperties/MyProperty&$expand=UserProfileProperties/MyProperty

With no luck.

What is the correct way to get this property ?

4

For this you will need to use "GetUserProfilePropertyFor" function.Please try below URL.

http://server/_api/SP.UserProfiles.PeopleManager/GetUserProfilePropertyFor(accountName=@v,propertyName='SPS-Birthday')?@v='Enter Current User Account Detail'

Reference Link : http://www.vrdmn.com/2013/07/sharepoint-2013-get-userprofile.html

0

You cannot filter/select on custom user property. It is a known issue. So its doesnt matter whether there is dash in the property or not.

User voice link - Enable selecting custom User Profile Properties from REST API

So you can use them as below:

For On Prem -

https://sitecollectionurl/_api/SP.UserProfiles.PeopleManager/GetUserProfilePropertyFor(accountName=@v,propertyName='My-Property')?@v='domain\username'

For Online -

https://sitecollectionurl/_api/SP.UserProfiles.PeopleManager/GetUserProfilePropertyFor(accountName=@v,propertyName='My-Property')?@v='i:0%23.f|membership|user.name@tenantname.onmicrosoft.com'

Full code:

$.ajax({
      url: "https://sitecollectionurl/_api/SP.UserProfiles.PeopleManager/GetUserProfilePropertyFor(accountName=@v,propertyName='SPS-JobTitle')?@v=%27i:0%23.f|membership|user.name@tenantname.onmicrosoft.com%27",
      type: "GET",
      headers: { "accept": "application/json;odata=verbose" },
      success: function(data){
        console.log(data);
      },
      error: function(data){        
      }
});

Reference - SharePoint 2013: Get UserProfile Properties with REST API

0

For future readers, according Sam's answer, here is my full code to retrieve the profile property for the logged user :

// 1st request to get the user login
jQuery.ajax({
    url: _spPageContextInfo.siteServerRelativeUrl + "/_api/SP.UserProfiles.PeopleManager/getmyproperties/accountname",
    headers :{Accept :"application/json;odata=verbose"},
    dataFilter: function (data, type) {
        var result = JSON.parse(data).d.AccountName;
        return JSON.stringify(result);
    }                
}).done(function(accountname) { 

    // 2nd request to get the property value
    jQuery.ajax({
        url: _spPageContextInfo.siteServerRelativeUrl + "/_api/SP.UserProfiles.PeopleManager/getuserprofilepropertyfor(accountname=@v,propertyName='My-Property')?@v='"+accountname+"'",
        headers :{Accept :"application/json;odata=verbose"},
        dataFilter: function (data, type) {
            var result = JSON.parse(data).d.GetUserProfilePropertyFor;
            return JSON.stringify(result);
        }
    }).done(function(myProperty){
        // final code when got the property
        console.log(myProperty);
    });

});

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.