Reputation: 31
I have been using the following API where I suggest the TEAM_ID/GROUP_ID to search
https://graph.microsoft.com/v1.0/groups/GROUP_ID/drive/root/search(q='SEARCH_VALUE')
I'd rather want to search in all the groups I am a part of without the Group ID to search the contents in the Teams Drive. Any leads will be appreciated.
Upvotes: 2
Views: 157
Reputation: 31
I found the solution by using Search Drive Items which is currently available in Beta from Graph API. It searches the list of files in detail from all the team drives and Sharepoint drives you have access to under the azure tenant.
Upvotes: 1
Reputation: 7483
The group_id is required, see here.
You could try Powershell to get the groups that you want, then loop to request MS Graph API.
#sign in your azure account
Connect-AzureAD
#get access token
function Get-AzureRMBearerToken
{
[CmdletBinding()]
Param
(
$TenantID,
$AppID,
$ClientSecret
)
$Result=Invoke-RestMethod -Uri https://login.microsoftonline.com/$TenantID/oauth2/token?api-version=1.0 -Method Post -Body @{"grant_type" = "client_credentials"; "resource" = "https://graph.microsoft.com/"; "client_id" = "$AppID"; "client_secret" = "$ClientSecret" }
$Authorization = "{0} {1}" -f ($result.token_type , $result.access_token)
$Authorization
}
$accessToken = Get-AzureRMBearerToken -TenantID "{your tenant id}" -AppID "{application/client id}" -ClientSecret "{value in your client secret}"
#get all groups
$groups = Get-AzureADGroup -All
#request MS Graph API in the loop
Foreach($group in $groups){
$url = "https://graph.microsoft.com/v1.0/groups/"+$group.ObjectId+"/drive/root/search(q='SEARCH_VALUE')"
Invoke-RestMethod -Method Get -Uri $url -Headers @{ Authorization = $accessToken }
}
Note: Make sure your application has the required permissions. Refer to here and here.
Upvotes: 1
Reputation: 2766
O365 Groups are the foundation of many things in Microsoft's cloud world, a team is an add-on to office 365 groups, as is Sharepoint (where the team files are mostly stored)
I don't believe that there is a single graph query that can return all drive files that you have access to. you would have to build 2 queries, one to query the groups you are a member of, and then loop through it to do a search query on each of the groups. to get all group ids of groups you are a member of is /getMemberGroups https://learn.microsoft.com/en-us/graph/api/user-getmembergroups?view=graph-rest-1.0&tabs=http
You can probably do it with powershell or a simple program or really any language that can call graph.
Upvotes: 0