Question

I have created SPFx webpart with React. I am calling REST API to get documents from document library and it's work perfectly in workbench but in SharePoint page i am getting error 403 - Forbidden

private GetDetails(selectedFolder: string) {
    const queryString =
      "?$select=Title,Name,ServerRelativeUrl&$expand=File&$filter=Title ne null&$orderby=Title asc";
    var URL ="/_api/web/getfolderbyserverrelativeurl('" +selectedFolder + "')/files" + queryString;
    var options: Array<IPropertyPaneDropdownOption> = new Array<IPropertyPaneDropdownOption>();
    this.getItems(URL).then((iMapsItems: any[]) => {
      iMapsItems.map((items: any) => {
        var strFileDisplayName = items.Title;
        var strFileUrl = items.ServerRelativeUrl;        
      });
      if (
        options.length &&
        ((this.properties.scriptUrl && this.properties.scriptUrl == "/") ||
          !this.properties.scriptUrl)
      )
      this.properties.scriptUrl = options[0].key.toString();
      this.ddlImapFileSelector = options;
      this.context.propertyPane.refresh();
    });
 }
private getItems(url: string): Promise<any[]> {
    const queryUrl: string = this.properties.siteName + url;
    return this.requester
      .get(queryUrl, SPHttpClient.configurations.v1)
      .then((response: any) => {
        return response.json();
      })
      .then((json: { value: ISPIMapsItems[] }) => {
        return json.value.map((task: ISPIMapsItems) => {
          return task;
        });
      });
}

Thanks in advance.

Was it helpful?

Solution

Looks like you have set the isDomainIsolated property to true in the package-solution.json file.

Modify the value to false and then do the process again to package the webpart and re-upload it in the app catalog site collection. Should work now in the SharePoint pages.

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