User Profile Service

The User Profile service is located at the following URL:

  • http(s)://<smarthub-web-app>/Services/UserProfileService.svc
    • Replace the first part of the URL below with the address of your own SmartHub instance

General Request Details

  1. type: GET and POST.

  2. headers:
    1. You must specify X-SH-Authorization in order to authenticate with SmartHub

  3. contentType: What is being sent to the server.
    1. application/json;charset=utf-8 is used by GetUserProfileProperties/SetUserProfileProperties
    2. GetUserPicture uses the default value.

  4. dataType: What you are expecting back from the server. In our case, this is a JSON response.
  5. data
     GetUserProfileProperties
    :
    1. You can send a total of three parameters:
      • userName(string):
        • This is the name of the user you want to make the request for.
        • If this parameter is missing, it will take identity of the current user.
      • properties(List<string>):
        • This is the list of properties or property that you want to request.
        • By default, the service is going to retrieve all of them: properties from provider + personalized store
      • personalizedStoreOnly(bool):
        • You can choose to skip the provider and get the values just from the personalized store only (this will decrease the request time).
        • By default, this value is set to false.

  6. SetUserProfileProperties:
    1. Only one parameter must be specified properties(Directory<string, string>).
    2. Specify a collection of properties and their values.

  7. GetUserPicture:
    1. User name is the only parameter required by this method.

  8. crossDomain
    1. Default
      1. False for same-domain requests
      2. True for cross-domain request.

Example: Get all user properties
Copy
$.ajax( {
    type: "POST",
    url: url + "GetUserProfileProperties",
    headers: {
        'X-SH-Authorization': 'Bearer ' + token
    },
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    crossDomain: true
} );

Example: Get a list of user properties
Copy
This request is only going to retrieve the "PropertyName" property, if it exists.
var properties = [ "PropertyName" ];
$.ajax( {
    url: url,
    type: "POST",
    headers: {
        'X-SH-Authorization': " Bearer " + token
    },
    contentType: "application/json; charset=utf-8",
    data: JSON.stringify( {
        properties: properties
    } ),
    dataType: "json",
    crossDomain: true
} );

Example: Getting just personal properties
Copy
personalizedStoreOnly set to true: Tells the service to skip calling the provider and just grab the data in the personalized store
$.ajax( {
    url: url,
    type: "POST",
    headers: {
        'X-SH-Authorization': " Bearer " + token
    },
    contentType: "application/json; charset=utf-8",
    data: JSON.stringify( {
        properties: properties,
        personalizedStoreOnly: true
    } ),
    dataType: "json",
    crossDomain: true
} );

Example: Get a user picture
Copy
var xhttp = new XMLHttpRequest( );
xhttp.open( "GET", url + "GetUserPicture", true );
xhttp.setRequestHeader( "X-SH-Authorization", "Bearer " + token );
xhttp.responseType = "blob";
xhttp.onreadystatechange = function ( ) {
    if ( this.readyState == 4 && this.status == 200 ) {
        var blob = new Blob( [ this.response ], {
            type: "image/png"        } );
        window.URL.createObjectURL( blob );
    }
}
xhttp.send( );