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.
New to Office 365 SharePoint Online? Get Office 365 Enterprise E3 Subscription & Try out all the features
This new REST service is the best way to go in a variety of application scenarios. SharePoint Apps built-in JavaScript is one 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.
sourceid | Specifies the unique identifier of the Result Source to use for executing the search query. | String | Empty |
http://host/site/_api/search/query?querytext=’term’&sourceid=’b09a7990-05ea-4af9-81ef-edfab16c4e31′ |
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() {
$.ajax({
url:window.location.protocol + “//” + window.location.host + “/_api/search/query?querytext=’”+$(“#search-
input”).val()+”*’&sourceid=’b09a7990-05ea-4af9-81ef-
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;
}
else
{
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
ms-peopleux-imgUserLink”>’
+ ‘<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>’
}
$(“#Result”).html(divHTML);
}
else if (data.d.postquery)
results = data.d.postquery.PrimaryQueryResult.RelevantResults.Table.Rows.results;
else
throw “Results not found”;
}
});
});
function getValueByKey(key, results) {
var postItem = $.grep(results, function (e) {
if (e.Key === key)
return e;
})[0].Value;
return postItem;
}
});</script>
<input type=”text” id=”search-input”>
<input type=”button” id=”SearchQuery” value=”Search”>
<div id=”Result”></div>

You may like following SharePoint 2013 search tutorials:
- Create custom search result page and add custom search result page to SharePoint Online Search Center
- Create SharePoint 2013 Online Search Result Sources and attach to Search Result page
- Search Items based in ID column in SharePoint 2013 SmallInputSearchBox
- SharePoint 2013 Enable and Configure search alerts
- [Fixed] SharePoint 2013/2016/Online: Find an Item List search box does not return results
- How to force a list or document library to crawl in SharePoint 2013 search?
- Show hide Search box in SharePoint 2013/2016/Online list or document library
- Search Engine Optimization in SharePoint 2013
- Search People as a Search Scope or Content Source Using SharePoint 2013 REST API
Hope this will be helpful to Search People as a Search Scope or Content Source Using SharePoint 2013 REST API.