Forum Discussion
SharePoint Framework and existing webparts
Search results are security trimmed no matter what so it's just a matter of using the search REST API in your web part to filter on site/web objects.
I've had some success using the following query expression with the contentclass managed property:
contentclass:"sts_site" OR contentclass:"sts_web"
- Bhavpreet BainsSep 20, 2017Iron Contributor
Hello Paul,
Thank you for the references.
I tried using the search api by changing the query in https://dev.office.com/sharepoint/docs/spfx/web-parts/get-started/connect-to-sharepoint. However, I am not able to get the proper response. I am using the following code. Can you possibly tell, what I could be doing wrong?
Code:
const spSearchConfig: ISPHttpClientConfiguration = {
defaultODataVersion: ODataVersion.v3
};const clientConfigODataV3: SPHttpClientConfiguration = SPHttpClient.configurations.v1.overrideWith(spSearchConfig);
private _getListData(): Promise<ISPLists> {
return this.context.spHttpClient.get(this.context.pageContext.web.absoluteUrl + `/_api/search/query?contentclass:sts_web`, clientConfigODataV3)
.then((response: SPHttpClientResponse) => {
return response.json();
});
}
Thank you.- Oct 03, 2017The query is incorrect, it should be instead: /_api/search/query?querytext="contentclass:sts_web"
- Paul SummersSep 21, 2017
Microsoft
Notice my quotes around "STS_Web". That might help.
The best way to troubleshoot queries with the search query tool. You can find that here: https://github.com/SharePoint/PnP-Tools/tree/master/Solutions/SharePoint.Search.QueryTool
Could you also provide the fully-resolved query expression? The variables might be hiding some details.