SharePoint REST API - Get loggedin User reporting

Mercury Man 21 Reputation points
2021-11-28T12:53:46.203+00:00

Hi All,

Our client is having SharePoint 2016 on-premises. For one of the application, we would like to get the logged-in user, reporting users (e.g.: if the manager logged in then it should bring all its team members) like we have SharePoint Org browser web part. using SharePoint Rest API.

can some one please guide me here?

Microsoft 365 and Office SharePoint Server Development
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
    2021-11-29T02:13:06.773+00:00

    Hi @Mercury Man ,
    If you want to get all users of site then

    _spPageContextInfo.webAbsoluteUrl + "/_api/Web/SiteUsers"  
    

    If You want to display information of User in site then

    _spPageContextInfo.webAbsoluteUrl + "/_api/Web/SiteUserInfoList"  
    

    If you want to get the properties of the current user on the site then you can use :

    _spPageContextInfo.webAbsoluteUrl + "/_api/Web/currentUser"  
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


    0 comments No comments

  2. Mercury Man 21 Reputation points
    2021-11-30T07:46:57.87+00:00

    Hi RaytheonXie-MSFT,

    Actually I am looking for logged-in user reporters and display them into jquery datatable using rest API

    0 comments No comments

  3. RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
    2021-11-30T08:00:33.18+00:00

    Hi @Mercury Man ,
    The following code have retrieved all site users and emails. Please take as reference

    	<script type="text/javascript" src="https://code.jquery.com/jquery-1.7.1.min.js"></script>  
    	<script type="text/javascript">  
    		$(function() {  
    			$.ajax({  
    				url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/SiteUsers",  
    				type: "GET",  
    				headers: { "accept": "application/json;odata=verbose" },  
    				success: (function (data, textStatus, jqXHR) {  
    					var listItemInfo = "";  
    					$.each(data.d.results, function (key, value) {  
    						listItemInfo += "<strong>Title: </strong>" + value.Title + " <strong>Description: </strong>" + value.Email + "<br />";  
    					});  
    					$("#listItems").html(listItemInfo);  
      
    				}),  
    				error: (function (xhr, ajaxOptions, thrownError) {  
    					  
    				})  
    		});  
    		});  
    	</script>  
    	  
    	<div id="listItems">  
    	</div>  
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.