Ways to get PictureUrl from User Profile using REST in SharePoint Online

As we retrieve,update, delete different items using REST in Sharepoint, there is also a way to get the user image using this REST api service.

There are two ways one can get the userprofile picture in Sharepoint. The first one being a bit complex as it uses CORS(cross-domain request).

 

 

https://my.sharepoint.com/User%20Photos/Profile%20Pictures/”+variable+”_domain_com_MThumb.jpg.

Here, “+variable+” is to be replaced by the User’s Login name after trimming and leaving behind the ADID. This method is rarely used as every time the user has to authenticate by clicking on the above given URL which is different from the actual SP site Url. The CORS exception can be skipped off by applying request executor.js. Since, there is an alternate way, I choosed the one to easily do the work.

The Second method has the following URL-

https://Yoursharepointsite.com/_layouts/15/userphoto.aspx?username=abc.xyz@domain.com

Here, one just needs to pass the email address of the user at the last part of the URL and since it makes a call to an item in the same site no exception occurs as we saw in the first one.One can bind that image in a HTML img tag and can use it wherever required.

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s