I am trying to retrieve a list of documents in our document library using the API. I do a GET call to https://mysite.sharepoint.com/sites/RapidMachiningSolutionsLLC/_api/Web/Lists/getbytitle('myDocLibrary')/items, but the data that I receive is only for the .doc files in the library.
2 Answers
There are multiple ways to retrieve files from the Document library.
Using the REST API you have used, we need to add select and expand in the query as below.
/sites/RapidMachiningSolutionsLLC/_api/Web/Lists/getbytitle('myDocLibrary')/items?$select=EncodedAbsUrl,*,File/Name&$expand=File
Another approach is to use GetFolderByServerRelativeUrl method to get all the files.
/sites/RapidMachiningSolutionsLLC/_api/web/GetFolderByServerRelativeUrl('/myDocLibrary')/Files
Make sure you are using the INTERNAL NAME of your document library.
-
The first query you showed still does not include .docx or .xlsx files. I haven't been able to get GetFolderByServerRelativeUrl to work.MattWolc24– MattWolc242022-07-05 16:05:12 +00:00Commented Jul 5, 2022 at 16:05
-
what error you are getting?Dhruvil Prajapati– Dhruvil Prajapati2022-07-06 13:47:32 +00:00Commented Jul 6, 2022 at 13:47
You can expand files and folders by following rest api
/_api/web/GetFolderByServerRelativeUrl('folderUrl')?$expand=Folders,Files