Home

Sharepoint API to get list of all sites returning only partial result.

%3CLINGO-SUB%20id%3D%22lingo-sub-1272973%22%20slang%3D%22en-US%22%3ESharepoint%20API%20to%20get%20list%20of%20all%20sites%20returning%20only%20partial%20result.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1272973%22%20slang%3D%22en-US%22%3E%3CP%3EI%20was%20trying%20to%20get%20the%20list%20of%20all%20SharePoint%20sites%20(subsites%20not%20included)%20for%20my%20SharePoint%2C%20for%20which%20I%20came%20up%20with%20the%20following%20API.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fzxxxxxxxx.sharepoint.com%2F_api%2Fsearch%2Fquery%3Fquerytext%3D'contentclass%3ASTS_Site%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fzxxxxxxxx.sharepoint.com%2F_api%2Fsearch%2Fquery%3Fquerytext%3D'contentclass%3ASTS_Site%3C%2FA%3E'%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EInitially%2C%20during%20setup%2C%20I%20have%20created%20several%20sites%20(team%20sites%2C%20communication%20sites)%20and%20the%20above%20API%20returned%20the%20list%20of%20all%20APIs.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBut%20eventually%2C%20when%20I%20tried%20after%20a%20few%20days%2C%20it%20stopped%20returning%20some%20of%20the%20sites%2C%20(particularly%20some%20of%20the%20Team%20sites).%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EUnsure%20of%20the%20reason%2C%20I%20tried%20to%20edit%20and%20republish%20a%20few%20team%20sites%20and%20the%20API%20response%20included%20those%20sites.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20need%20an%20API%20to%20get%20all%20the%20sites%20at%20any%20point%20in%20time.%26nbsp%3B%20I%20do%20not%20wt%20to%20republish%20every%20time.%20Am%20I%20missing%20something%20here%3F%3CBR%20%2F%3E%3CBR%20%2F%3EAs%20an%20alternative%20approach%2C%20I%20tried%20graph%20APIs%20to%20get%20the%20list%20of%20sites.%20It%20always%20threw%20503%20Service%20unavailable.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECan%20anyone%20help%20me%20out%20with%20this.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1272973%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAdmin%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Server%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESites%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Highlighted
New Contributor

I was trying to get the list of all SharePoint sites (subsites not included) for my SharePoint, for which I came up with the following API.

 

https://zxxxxxxxx.sharepoint.com/_api/search/query?querytext='contentclass:STS_Site'  

 

Initially, during setup, I have created several sites (team sites, communication sites) and the above API returned the list of all APIs.

 

But eventually, when I tried after a few days, it stopped returning some of the sites, (particularly some of the Team sites). 

 

Unsure of the reason, I tried to edit and republish a few team sites and the API response included those sites.

 

I need an API to get all the sites at any point in time.  I do not wt to republish every time. Am I missing something here?

As an alternative approach, I tried graph APIs to get the list of sites. It always threw 503 Service unavailable.

 

Can anyone help me out with this.