Forum Discussion

Bhavpreet Bains's avatar
Bhavpreet Bains
Iron Contributor
Sep 15, 2017

SharePoint Framework and existing webparts

Hello,

 

I want to integrate the similar functionality as that of Search Result webpart to get all the sites that I have access to. However, I didn't find any rest api that can do it and I am not sure what could be possibly the best approach. 

 

I looking for a direction that can help me create my first non-tutorial webpart.

 

Thank you.

4 Replies

  • 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 Bains's avatar
      Bhavpreet Bains
      Iron Contributor

      Hello Paul,

       

      Thank you for the references.

       

      I tried using the search api by changing the query in Microsoft Hello World tutorial. 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.

      • Waldek Mastykarz's avatar
        Waldek Mastykarz
        MVP
        The query is incorrect, it should be instead: /_api/search/query?querytext="contentclass:sts_web"

Resources