0

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.

  • You mean it is working in SharePoint workbench but not working in SharePoint Page when added as a web part from app catalog? Can you please add the code you are using and any other details of an error? – Ganesh Sanap Sep 17 '19 at 7:16
  • Exactly. Shared code – Chandani Prajapati Sep 17 '19 at 7:22
  • what is the value of selected folder in workbench and on the page? – harshal gite Sep 17 '19 at 9:06
  • Same value in both. selected-folder is the property pane value(In my scenario i have created cascading drop down in property pane) – Chandani Prajapati Sep 17 '19 at 9:26
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.