Abstract get() ?
Hello,
I'm trying to get our root SharePoint Site. However, I cannot find a way to get() abstract non-predefined values.
For example, In API, there is GET /sites/root which returns the root site. This feature doesn't exist in this python lib (at least yet). I can theoretically get this with
ressite = await graph_client.sites.with_url('https://graph.microsoft.com/v1.0/sites/root').get()
But then my return variable ressite expects typeof SiteCollectionResponse, but the get() (well, the URL endpoint) actually returns a Site. How could I abstractly get() any url I want to and force the result type properly?
Hello @jussihi tanks for using this SDK and for raising this.
I presume your intention is to get root site and be able to use its properties for in code,
This documentation here can be a good starting point https://learn.microsoft.com/en-us/graph/api/site-get?view=graph-rest-1.0&tabs=python
From the SDKs, the ways of getting sites/a site are:
- Getting all sites in a tenant
- Getting sites with site_id
- Get site with URL
Reference - https://github.com/microsoftgraph/msgraph-sdk-python/blob/main/msgraph/generated/sites/sites_request_builder.py
this gives get, get_all_sites, with_url and by_id as the available options.
root site for a group would map to https://learn.microsoft.com/en-us/graph/api/site-get?view=graph-rest-1.0&tabs=python
Sample
try:
all_sites = await user_client.sites.get()
print(f"All Sites: {all_sites}")
print(f"All Sites type: {type(all_sites)}")
for site in all_sites.value:
print(f"Site ID: {site.id}")
print(f"Site URL: {site.web_url}")
print(f"Site name: {site.display_name}")
except APIError as e:
print(f"Error: {e.response_status_code}")
print(f"Error: {e.message}")
print(f"Error: {e.response_status_code}")
print(f"Error: {e.error}")
With Abstract Get, what do you mean: A method to get the root site as a sitecollectionResponse? a method to get all sites?
Note that what the URL endpoint gives is a site, which we can get as a va;ue within the site collection response when we use get, get_all_sites etc.
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.