I am trying to implement a feature in our app to allow users to search for files in their Sharepoint & OneDrive accounts, as they see in Office365.
I am having trouble understanding why I am not seeing expected results from search API requests.
When I make a search request like this, I get 1 result as expected:
https://graph.microsoft.com/v1.0/sites/{my-site -id}/drive/root/search(q='brisbane')
However, when I search like this, there are no results:
https://graph.microsoft.com/v1.0/me/drive/search(q='brisbane')
If I modify the query for /me/drive/search, I do see results from OneDrive, but not from SharePoint.
According to the Microsoft Graph docs, /me/drive/search should search for 'Items a user can access'.
Is this the expected result? Is there any way to search all the current users' Sharepoint sites? Or do I have to ask the user to configure the sites they would like to search, then search each of them separately?
This is by design. You need to read below the "Searching for items a user can access" heading to understand what this means:
In addition to searching for items within a drive, your app can search more broadly to include items shared with the current user. To broaden the search scope, use the search method on the Drive resource.
When you're searching /me/drive/ you are searching that user's OneDrive for files they have uploaded themselves or have been explicitly shared with them. Files that live within a SharePoint library that a user happens to have access to are quite different than files "shared" with that user.
Related
At the bottom of most pages/docs in SharePoint Online modern pages, there are “Like” and “Save for later” toggles.
I would like to be able to programmatically retrieve a list of things that were either “Liked” or “Saved for later” by the currently logged in user.
Is this something I can fetch using the Microsoft Graph or does SharePoint have something more readily available for reading this data?
The ability to return the list of items of drive items that are followed is currently available in beta
https://learn.microsoft.com/en-us/graph/api/drive-list-following?view=graph-rest-beta
I believe that Like and save for later are different from follow. You may want to try this API to see whether they show up or not.
I'm trying to fetch recent files from SharePoint Online using Microsoft Graph.
The API I'm using is :
https://graph.microsoft.com/v1.0/me/drive/recent
But the results include files from all site collection. I need to restrict the results to only a single site collection.
After some research, I found that there is no direct API to restrict the site collection.
I also tried using adding filter like :
$filter=sharepointIds/siteId eq 'site-id'
but it was also not working. It gave a `501 (Not implemented) error.
Update:
I found another API from Graph which is
https://graph.microsoft.com/beta/me/insights/used
which is inside insights(beta) named "items viewed and modified by me"
But it again returns data across tenant and I need to restrict it to a single site collection. I guess filter conditions are not yet implemented for this API in Graph.
Is there any method to get recent files from a particular site collection? Any help is appreciated.
One correction, /me/drive/recent isn't pulling from all site collections, it's pulling from the current user's OneDrive. This includes recent files held within their drive and any recent changes to files that have been shared with them.
As for finding Recent Files from a SharePoint Document Library, you need to make this request within the context of the drive you want to pull from. For example:
https://graph.microsoft.com/v1.0/sites/root/drives/{documentLibraryId}/recent
We are using Microsoft Graph APIs (driveItem.search) to search the files those user can access on Sharepoint Online. But when we open the Sharepoint Online site and search at that site, the search's result from Sharepoint Online site and the search's result from API return is different.
Example:
The keyword that we are testing is "safety access" (including parenthesis)
Here is the result from Sharepoint Online site:
enter image description here
Here is the result from APIs:
enter image description here
Can anyone tell me why is it different like that?
Note: You can currently search only message and person collections.
https://developer.microsoft.com/en-us/graph/docs/concepts/query_parameters#search-parameter
https://graph.microsoft.com/v1.0/me/drives/b!05kpQIVuAkebEbnq3ftalG9eKBXqLXRJiiiQGZjVlDqML5T888BfS4YjkXMj9Exl/microsoft.graph.search(q='"Test"') will ignore the search parameter so you will see the following in the result, it just list all drive items in the site:
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(driveItem)"
Meanwhile, the query in SharePoint site itself just iterate over a specific document library.
Is there a way we can get Directory of all users? me/people gives relevant users which is not a complete list of users. We need to access complete list of users for searching.
The /users endpoint seems to be what you're looking for. Documentation is at https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/user_list
For example, a call to GET https://graph.microsoft.com/v1.0/users should return a paged list of all users in the tenant.
I also recommend you take a look at the Graph explorer that has samples for querying this endpoint. You can view these by clicking the show more samples link.
My requirement is to search for a file in my entire SharePoint Online (SPO) using Graph apis. I have my query something like this which I use in MS Graph Explorer:
https://'my domain'.sharepoint.com/_api/search/query?Querytext='res1a2b3c4d5e'
Basically above query is to search for all the documents having title/name as 'res1a2b3c4d5e'. This works fine if I search for any existing document. If I try to search for any document which was created/uploaded just before making above call I wont get the result.
If I search for the same after couple of minutes, then the request succeeds. Where as when I try the same on my customers site where it has millions of documents. It nearly takes around 20+ hours before I can do a successful search
So does graph api work on any SPO cache?
How can I search for newly added file without having to wait for 20+ hours?
Thanks in advance.
The search results will be available only after the search content is crawled and available in search index. While you can control the crawl schedule in SharePoint On-Premise, you cannot do so in SharePoint online. Crawling frequency in SharePoint online is managed by Microsoft.
More Details