Microsoft Graph API - How to Filter SharePoint sites by Site Type? - sharepoint

SharePoint Admins in Microsoft 365 can create Team Sites and Communication Sites using the admin center.
In addition, individual users can have Personal Sites (Otherwise known as My Sites)
Using the Microsoft Graph .NET SDK I can retrieve all sites like this:-
await client.Sites.Request().GetAsync();
However this appears to include all Team, Personal and Communication Sites. Is there a way to limit the request to only one type of site, or detect the type of each site returned from the query? I could not find anything in the documentation about this.
Edit: If there's a way to get this information via SharePoint CSOM, I would be interested in that too

Unfortunately this is not available as of now but there is a uservoice already raised. Please upvote it so that this feature may be implemented in the future.

I don't know if it can help you but I found a workaround how to differentiate between a team/communication site and a personal site.
A personal site contains in the WebUrl field the string "my.sharepoint.com/personal/", then after you make the call: var sites = await client.Sites.Request().GetAsync(); you can use this filter to retrieve only personal site: var personalSites = sites.Where(s => s.WebUrl.Contains("my.sharepoint.com/personal/")); (Microsoft does not allow to use a filter on this request directly, so this is the reason why I used the filter after fetching all sites.)

Related

How to obtain ACLs for different sharepoint sites

Using the graph API or sharepoint REST APIs, is there a way to obtain, for each site, the list of users/o365 groups that are allowed read access to the site?
We are able to obtain the list of sites using the graph API GET /sites?search=* but cannot find a way to get the list of users allowed to access each site (except for Sharepoint team sites associates with o365 groups that we can enumerate using GET /groups/{group-id}/sites API call.
We are building a server side application so need to do this from the server using application-level permissions, and not from the client.
Pointers for how to do this are greatly appreciated!
Looks like there is no such endpoint that gets the site permissions and there are few uservoices here that are close to your scenario. Please upvote them so that it could be developed by the product team in future.

Security Query for the Users ina SharePoint Site

I am updating a SharePoint 2007 solution to SharePoint 2013. The solution creates a list of permissions for each site in a site collection. In SharePoint 2007 I used SOAP to query the ROLE object and got back the Groups and Users security objects for a site. In SharePoint 2013 ROLE and SOAP is deprecated. I am trying to use the REST API to recreate the solution. I am able to get the groups object for each site, but I am unable to find the way to get the Users security object for the sites. I can get Site Users for the site collection and get the Users in a SharePoint Group, but I find no way to get the Users Security Object for a site. Has anyone been able to accomplish get the Users for a site?
Sample REST api to check user permission for site.
You need encode the URL from(suppose your use default NTLM authentication)
/_api/web/getusereffectivepermissions(#user)?#user='i:0#.w|contoso\userb'
TO
/_api/web/getusereffectivepermissions(#user)?#user='i%3A0%23.w%7Ccontoso%5Cuserb'
About the return value, check below thread.
http://www.lifeonplanetgroove.com/checking-user-permissions-from-the-sharepoint-2013-rest-api/?doing_wp_cron=1449727796.2080190181732177734375

OneDrive REST API and Sharepoint Online

I have the app that uses OneDrive API (MS graph) to access OneDrive free accounts and OneDrive for business.
The app works fine.
In docs of the API i can see same API can be used also to access Sharepoint Online sites data.
How to do this? When i auth a user who has Sharepoint Online account with MS graph, there is only his drive (ondrive) but there is no his site listed.
How to get access to his sharepoint site too using same API?
I have found how to work with sites using the Graph API.
To get list of sites there is the call
GET /v1.0/sites/
Then use the SITEID to get list of drives (in fact, top level folders)
GET /v1.0/sites/SITEID/drives
Then to get contents of a drive user
GET /v1.0/sites/SITEID/drives/DRIVEID/root/children
And all next calls are same as for onedrive drive
However, there is the problem i still can not solve. How to create new top level folder (new drive on a site). There is no API call for this
I believe what you are looking for is the sites API. It lets you interact with a SharePoint site if you know the path or the id of the site. You can find the documentation for the api here:
https://dev.onedrive.com/resources/site.htm
There is no easy way to discover sites as of now. You can however search for a site. You can read more about it here:
https://dev.onedrive.com/sites/search.htm
This endpoint to get the list of sites is not working, so the last answer is not valid anymore.
https://graph.microsoft.com/v1.0/sites
I haven't found a way to do this, the discovery of sites, without admin consent. If the admin consent flow is not a problem you can try this workaround, use the endpoint of groups to ask for the groups that the user is member of, and you can use the groups to get the document libraries of the user.
To get the groups:
GET https://graph.microsoft.com/v1.0/me/memberOf
With the group id, you can use this endpoint:
GET https://graph.microsoft.com/v1.0/groups/{group-id}/drive
So if someone know how to do the discovery of sites for a user without admin consent, please share.
EDIT: I'm not sure why my answer was deleted, my answer basically has 2 things:
I gave notice that one answer here is not valid anymore.
I gave a possible other solution to the problem.

How to access Sharepoint site's document library via Microsoft Graph API?

I'm working on accessing document libraries for Sharepoint sites via Mircosoft Graph, but haven't had any luck so far.
Here is my setup:
I have two sites
https://mydomain.sharepoint.com
https://mydomain.sharepoint.com/teams/MyTestSite
When I make an api call to https://graph.microsoft.com/v1.0/drives, the response doesn't contain id of document library for second site (https://mydomain.sharepoint.com/teams/MyTestSite).
I have gone through documentation and haven't found anything on how to accomplish this. If anyone got any idea about this, please share.
Thanks.
I was able to figure out a solution for this. A sharepoint site is represented as a Group in Office 365. I found that out by doing some hit and trial.
So, after looking up their documentation for anything related to a Group, I got to this: https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/resources/group
And, by using the List groups endpoint I was finally able to get a list of all the Sharepoint sites which the authenticated user can access.
This API call requires Group.Read.All scope while requesting access token and only Admin users can authorize this scope. So, this will need a separate interface for Admin to list groups, potentially store the group-user mapping on my app for the user to be able to make api call (/groups/{group-id}/drive/items/{item-id}) related to the drive.
The V1.0 API has a way to list your doc lib as follows
GET https://graph.microsoft.com/v1.0/sites/mydomain.sharepoint.com:/Teams/MyTestSite:/drives
Hope this helps.
The beta API also exposes a Sharepoint endpoint.
You can also use the path if you already know your site structure:
GET https://graph.microsoft.com/beta/sharepoint:/sites

Sharepoint: get number of sites in a collection

I'm trying to get the total count of subsites created in a very large Sharepoint collection. Please note, I don't have direct access to the server.
Is there any native sharepoint feature I'm missing that will provide a site count?
Is there a webservice that can crawl the collection? (we have google analitics)
Are there any other options short of running a powershell script on the server?
Thanks!
I would suggest using the 'Webs' Web Service - you can invoke it by putting /_vti_bin/webs.asmx on the end of your site URL. It has a method GetAllSubWebCollection.
The only gotcha is that you will get filtered results based on the user being used to access the web service. For example, if you have a site collection that has a sub-web created for HR, Business, Management, Sales and IT - but your account only has access to the HR and Sales site - you will only get results back for the HR and Sales sites.
You may also find the SPServices jQuery library helpful as it has wrappers for most of the web services and can make calling them from a client much less painful.
Note: These web services exist for the 2007 and 2010 editions of SharePoint. You didn't mention a specific version but hopefully it is one of these two.

Resources