I've created a custom web part that displays documents from a relative URL.

const queryUrlGetAllItems: string = this._webAbsoluteUrl + `/_api/web/GetFolderByServerRelativeUrl('${libraryRelativeUrl}')/Files?$expand=ListItemAllFields`;

My client has many custom document library views that have many filters and sorting options.

Is there a way to use the API (or some other way) to retrieve all documents from a direct document library view?

ex. https://contoso.sharepoint.com/sites/CommSite/MyDocumentsFolder/Forms/AllItems.aspx?viewid=e3025c96%2D13a9%2D4854%2Da3cf%2Da1797d31e2c7

Any help would be appreciated!

1 Answer 1


You can use code like the one found in this sample in the _loadDataFromList.

It uses PnPJs, but you can:

    const list = await sp.web.lists.getById("yourlistid"); // or get by title

    // Get the view definition
      const view = await list.getView("your view id")();
      const viewSchema = view.HtmlSchemaXml;

    // Get the data as returned by the view
    const { Row: data } = await list.renderListDataAsStream({
      ViewXml: viewSchema

I hope it helps?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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