Office365-rest-python-client: Get all sites

Created on 3 Dec 2020  ·  5Comments  ·  Source: vgrem/Office365-REST-Python-Client

Hi, there is a method for get all sites from the API?

I can access to a site with url, but would be possible to get a list of sites with the url and iterate it?

Thank you so much

question

All 5 comments

Hi, do you have news on this topic? Or some workaround? No hurries only curiosity Thank you ^^

Hey,

positive, it is supported to retrieve all sites(site collections) within tenant, for example via method Tenant.get_site_properties_from_sharepoint_by_filters(filter, start_index=0, include_detail)

Example

The example demonstrates how to retrieve all sites within tenant and prints its url:

from office365.runtime.auth.user_credential import UserCredential
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.tenant.administration.site_properties import SiteProperties
from office365.sharepoint.tenant.administration.tenant import Tenant
from settings import settings

credentials = UserCredential(username, password)

admin_client = ClientContext("https://{tenant-prefix}-admin.sharepoint.com/").with_credentials(credentials)
tenant = Tenant(admin_client)
result = tenant.get_site_properties_from_sharepoint_by_filters("", 0).execute_query()
for siteProps in result:  # type: SiteProperties
    print(siteProps.get_property('Url'))

Hi @vgrem thank you for the code but, sadly, im not getting the url only None, None, None... but i can access with my credentials to the list of sites on sharepoint, hence i dont think the problem be my permissions. Do you know what could be the problem?

@oktorok ahh, it might the case with siteProps.get_property('Url') since get_property semantics has been changed recently.

Could you give it another shot with this syntax instead:

print(siteProps.properties.get('Url'))

Yes, effectively now its working, thank you so much.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Cesaaar picture Cesaaar  ·  7Comments

continda picture continda  ·  4Comments

stardust85 picture stardust85  ·  4Comments

etiennecelery picture etiennecelery  ·  4Comments

pobs93 picture pobs93  ·  4Comments