Question

I need to create a spfx webpart which fetch data from a list avaialble on different site collectionn. Ex: SPFx webpart deployed at https://test.sharepoint.com/sites/test1

List from where data need to be fetch is at site : https://test.sharepoint.com/sites/test2

Was it helpful?

Solution

Did sample test.

The script would get data from another site collection while there is potential issue, SPFx use current user credential to access SharePoint data, so if current user has no permission to target site collection, there would be issue.

this.props.context.spHttpClient.get(`https://xxx.sharepoint.com/sites/modernteam/_api/web/lists/getbytitle('List1')/items?select=ID,Title`,
      SPHttpClient.configurations.v1).then((response: SPHttpClientResponse) => {
        response.json().then((responseJSON: any) => {
          // to do
        });
      });

So, you may consider to use search/Microsoft graph instead.

Search in SPFx

Call graph api in SPFx

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top