User Profile Service

General Request Headers

  1. type: HTTP Method types for UserProfileService: GET and POST.
  2. url: By default, the path to service is: /_bai/v1.0/userprofile
  3. headers: You must specify X-SH-Authorization in order to authenticate with SmartHub.
  4. contentType: What is being sent to the server.
    1. application/json;charset=utf-8 is used by GetProperties/SetProperties
    2. GetPicture uses the default value.
  5. dataType: What you expect back from the server. In our case, this is a JSON file.
  6. data
     GetProperties: 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.
  7. SetUserProfileProperties: Only one parameter must be specified: properties(Directory<string, string>). Specify a collection of properties and their values.
  8. GetUserPicture: username is the only parameter required by this method.
  9. crossDomain: Default: false for same-domain requests, true for cross-domain request.


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

 

Example: Get a list of user properties

This request is only going to retrieve the "PropertyName" property, if it exists.

Copy
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

personalizedStoreOnly set to true tells the service to skip calling the provider and just grab the data in the personalized store.

Copy
$.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 + "/picture", 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( );