S1E13: The Easy Way to code with Nasty SharePoint Search restAPI JSON

The JSON returned by the SharePoint search restAPI is just downright nasty. Because it is so nasty, it will make your code nasty and un-scalable. BUT!!! With the right “data method” to encapsulate this nastiness, and leveraging our existing pattern, in this SharePoint Developer tutorial we will get the power of SharePoint search…which is very powerful and widely used/needed in SharePoint Online. Lucky for you, I’ve endured all the pain and these 12 lines of code will save your life (i.e. heartache, head banging, cliff jumping) function _getSPRelevantResults(endpoint) { return $http.get(endpoint, _getConfig).then(function (d) { var results = d.data.d.query.PrimaryQueryResult.RelevantResults.Table.Rows.results; var col = []; results.forEach(function (rItem) { var item = {}; rItem.Cells.results.forEach(function (cell) { item[cell.Key] = cell.Value; }); col.push(item); }); return col; }); } #spEasyDev#sharepointrefiners#ngsharepoint#spclassroom ? Subscribe to SPClassroom SharePoint and o365 videos – https://www.youtube.com/user/clardo11… SPClassroom is a collection of sharepoint developer tutorials for SharePoint 2013, SP2016, SharePoint Online, office365, and SPFx SharePoint Developer’s Framework, with a focus on training videos for Power Users, Developers, and SharePoint Architects.

Leave a Reply

Your email address will not be published.