Search People as a Search Scope or Content Source Using SharePoint 2013 REST API

SharePoint 2013 Search API via REST for the first time.  I wanted to search for people, not documents.  The key learning here is that you specify content sources via its GUID.

This new REST service is the best way to go in a variety of application scenarios. SharePoint Apps built-in JavaScript is a good example. External Applications to SharePoint that require search functionality; can also leverage this service as the endpoint for communication into the Search platform.

The old search.asmx SOAP  web service is marked as deprecated in SharePoint 2013, and the new Search.

sourceidSpecifies the unique identifier of the Result Source to use for executing the search query.StringEmpty

The following steps shows:

Step-1: Navigate to your SharePoint 2013 site.

Steps-2: From this page select Site Actions | Edit Page:

Edit the page, go to the “Insert” tab in the Ribbon and click the “Web Part” option. In the “Web Parts” picker area, go to the “Media and Content” category, select the “Script Editor” Web Part and press the “Add button”. Read about script editor web part in SharePoint.

Step-3: Once the Web Part is inserted into the page, you will see an “EDIT SNIPPET” link click. You can insert the HTML and/or JavaScript:

<script src="/Scripts/jquery-1.10.1.min.js" type="text/javascript"></script>

<script type="text/javascript">
$(document).ready(function () {
$("#SearchQuery").click(function() {
url:window.location.protocol + "//" + + "/_api/search/query?querytext='"+$("#search-
edfab16c4e31'&rowlimit='100'&selectproperties='PictureURL, PreferredName, Country'",
headers: { "Accept": "application/json; odata=verbose" },
contentType: "application/json; odata=verbose",
success: function (data) {
var results;
var divHTML = ";
var Picurl;
if (data.d) {
if (data.d.query)
var users = new Array();
results = data.d.query.PrimaryQueryResult.RelevantResults.Table.Rows.results;
for (i = 0; i < results.length; i++) {
var item = results[i];
var itemCell = item.Cells;
var itemResults = itemCell.results;
//Get Values for User
var userPic = getValueByKey("PictureURL", itemResults);
var fullname = getValueByKey("PreferredName", itemResults);
var CountryName= getValueByKey("Country", itemResults);
if(userPic!= null){
Picurl= userPic;
Picurl = '/Style Library/styles/images/tempPic.png';
// alert(PicId);
divHTML += '<div class="item">'
+ '<div class="id">'
+ '<div class="ms-tableCell ms-verticalAlignTop">'
+ '<div class="ms-peopleux-userImgDiv">'
+ '<div class="ms-imnSpan">'
+ '<div style="width: 36px; height: 30px;" id="ImgPicSpan1″ class="ms-peopleux-userImgWrapper ms-subtleLink
+ '<img style="cliptop: 0px; clipright: 36px; clipbottom: 36px; clipleft: 0px; min-height: 30px; max-height:30px; min-
width: 30px; max-width: 30px;" id="PictureDiv1″ class="ms-peopleux-userImg" src="' + Picurl + '"/>'
+ '</div>'
+ '</div>'
+ '</div>'
+ '</div>'
+ '<div id="PersonNameDiv" class="ms-tableCell ms-verticalAlignTop" >' + '<div> ' + fullname + ' </div>'
+ '<div class="place">' + CountryName + ' </div>'
+ '</div>'
+ '</div>'
+ '</div>'
+ '</div>'
+ '</div>'
+ '</div>'
else if (data.d.postquery)
results = data.d.postquery.PrimaryQueryResult.RelevantResults.Table.Rows.results;
throw "Results not found";
function getValueByKey(key, results) {
var postItem = $.grep(results, function (e) {
if (e.Key === key)
return e;

return postItem;

<input type="text" id="search-input">

<input type="button" id="SearchQuery" value="Search">

<div id="Result"></div>
Search People as a Search Scope or Content Source Using SharePoint 2013 REST API
Search People as a Search Scope or Content Source Using SharePoint 2013 REST API

You may like following SharePoint 2013 search tutorials:

I hope this will be helpful to Search People as a Search Scope or Content Source Using SharePoint 2013 REST API.

Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

Get update on Webinars, video tutorials, training courses etc.