Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get all sites #301

Closed
oktorok opened this issue Dec 3, 2020 · 5 comments
Closed

Get all sites #301

oktorok opened this issue Dec 3, 2020 · 5 comments
Labels

Comments

@oktorok
Copy link

oktorok commented Dec 3, 2020

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

@vgrem vgrem added the question label Dec 6, 2020
@oktorok
Copy link
Author

oktorok commented Jan 15, 2021

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

@vgrem
Copy link
Owner

vgrem commented Jan 18, 2021

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'))

@vgrem vgrem closed this as completed Jan 18, 2021
@oktorok
Copy link
Author

oktorok commented Jan 18, 2021

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?

@vgrem
Copy link
Owner

vgrem commented Jan 18, 2021

@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'))

@oktorok
Copy link
Author

oktorok commented Jan 18, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants