We can use REST API to communicate and manipulate SharePoint data, for instance, if we have some SharePoint list and if we want to retrieve all the list items from the list. The same thing applies to SharePoint document library. But, retrieving documents from a library is not as easy as from a SharePoint list because, in SharePoint document library, there may be a nested folder structure.
If the document library has more than 100 files, then we might need to use $top in URL or we can use data.d.__next property to identify the next set of items.
- var g;
- $.ajax({
- url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/Lists/GetByTitle('Training Material')/Items",
- type: 'GET',
- dataType: "json",
- headers: {
- "Accept": "application/json;odata=verbose",
- "content-type": "application/json; odata=verbose",
- "X-RequestDigest": $("#__REQUESTDIGEST").val()
- },
- success: function (data) {
- for (var i = 0; i < data.d.results.length; i++) {
- if (data.d.results[i].FileSystemObjectType != 1) {
- }
- }
- },
- error: function (request, error) {
- console.log(JSON.stringify(request));
- }
- });

ramesh vaghelaPosted Apr 13, 2018, 8:26 AM
Nice article. . thank you for sharing this information
Piyush AgarwalPosted Mar 8, 2018, 7:09 AM
Thanks Hiren, I tried this code to get all the pages in my pages library but could not get them. Is there something to be changes to get all the pages in different folders in a library???