var oPagesCollection=[];//object having url for all pages under root site and sub site getPage("") $.ajax({ url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/webinfos?$select=ServerRelativeUrl,Title", method: "GET", headers: { "Accept": "application/json; odata=verbose" }, success: function(subsites) { $.each(subsites.d.results, function() { getSubSites(this.ServerRelativeUrl, this.Title); getPage(this.ServerRelativeUrl); }); console.log(oPagesCollection); }, error: function(subsites) {}, async: false }); //function to get n level of subsites function getSubSites(SubSiteUrl, SubSiteTitle) { console.log(SubSiteUrl); $.ajax({ url: _spPageContextInfo.siteAbsoluteUrl + SubSiteUrl + "/_api/web/webinfos?$select=ServerRelativeUrl,Title", method: "GET", headers: { "Accept": "application/json; odata=verbose" }, success: function(subsites) { $.each(subsites.d.results, function(index) { getSubSites(this.ServerRelativeUrl, this.Title); getPage(this.ServerRelativeUrl); }); }, error: function(subsites) {}, async: false }); } function getPage(siteUrl){ $.ajax({ url: _spPageContextInfo.webAbsoluteUrl+ siteUrl + "/_api/web/lists/GetByTitle('Pages')/items?$select=FileRef", method: "GET", headers: { "Accept": "application/json; odata=verbose" }, success: function(data) { $.each(data.d.results,function(index,val){ oPagesCollection.push(val["FileRef"]); }); }, error: function(rootsite) {}, async: false }); }
Friday, 29 March 2019
Home
/
JSOM
/
REST API
/
SharePoint
/
SharePoint 2013
/
SharePoint Online
/
How to Retrieve all the pages from SharePoint Online sites and subsites using REST API
How to Retrieve all the pages from SharePoint Online sites and subsites using REST API

About Gowtham
I'm a software developer who enjoys building solutions, exploring new tech, and helping others grow through clean and simple content. This blog shares real-world coding tips, Power Platform how-tos, AI experiments, and lessons learned from hands-on experience.
SharePoint Online
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment