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
Related
On daily basis I am getting an attachment in email. Basically that attachment is an excel spreadsheet. I am pushing that spreadsheet to google drive folder ./attachments using Microsoft Power Automate. The main purpose of pushing that spreadsheet into google drive is to load into PowerBi for Analytics purposes.
In PowerBi I am using the "Web" connector to import the file and it's working fine. The sample link is below.
https://docs.google.com/spreadsheets/u/2/d/1eBJR6wrcFrdjv4Lbf_Wq3MQOeUwBbgLw/export?format=xlsx
The above link exports the file into powerBi and hence I can load data into PowerBi.
The problem is, on daily basis I am getting new file in drive and the Unique Id of the file is not same. In the above example the unique Id 1eBJR6wrcFrdjv4Lbf_Wq3MQOeUwBbgLw will be different for the second file even though I am renaming the file with the same name using Microsoft Power Automate when pushing to Google Drive. eg: "PowerBi load file.xlsx". Is that possible that I can get a stable link for all the files with the same name?.
I have also shared the whole folder ./attachments and tried to get the link of the file but that doesn't work. eg:
https://drive.google.com/drive/folders/1h1VuPtXfWflgIQw7ecMTwweoLblADscq/PowerBi Analytics file.xlsx/export?format=xlsx
Any help, suggestions will be really appreciated.
Thanks everyone.
I believe your goals as follows.
You want to retrieve the file IDs from a filename.
You want to retrieve the file IDs from a shared folder.
Answer for question 1:
In order to retrieve the file IDs from a filename, I think that the method of "Files: list" of Drive API can be used.
The endpoint is as follows.
GET https://www.googleapis.com/drive/v3/files?q=name%3D%27{filename}%27
The search query is name='{filename}'.
In this case, the API key cannot be directly used because the file list tries to be retrieved from the while Google Drive including the file. In this case, the access token is required to be used.
By this, I thought that your goal 2 might be suitable.
Answer for question 2:
In order to retrieve the file IDs from a shared folder, I think that the method of "Files: list" of Drive API can be also used. In this case, at least, the file list is retrieved from the shared folder. By this, the API key can be used.
The endpoint is as follows.
GET https://www.googleapis.com/drive/v3/files?q=%271h1VuPtXfWflgIQw7ecMTwweoLblADscq%27%20in%20parents&key=[YOUR_API_KEY]
The search query is '1h1VuPtXfWflgIQw7ecMTwweoLblADscq' in parents.
In this case, the file list can be retrieved using the API key because the folder is publicly shared and the file list is directly retrieved from the publicly shared.
But, in order to use this, it is required to use the API key. Please be careful this.
Other pattern:
If you want to achieve your goal without the API key and the access token, I would like to propose to use the Web Apps created by Google Apps Script as a wrapper API. When this Web Apps is used, you can achieve above both goals without using the API key and the access token.
The official document of Web Apps is here.
The unofficial document of Web Apps including several sample situations is here.
References:
Files: list
Search for files and folders
I am trying to retrieve all of the files associated with each channel within each Team. Per the Microsoft Graph REST API V1.0 documentation, it is GET /teams/{id}/channels/{id}/filesFolder.\
Please see https://learn.microsoft.com/en-us/graph/api/channel-get-filesfolder?view=graph-rest-1.0&tabs=http
However, filesFolder no longer appears as an available query. Is there still a way to achieve this?
Edit: Appears to be the same for Messages. https://learn.microsoft.com/en-us/graph/api/channel-list-messages?view=graph-rest-beta&tabs=csharp&viewFallbackFrom=graph-rest-1.0
Why are these queries no longer available?
You can query Groups with team-id to get the items from the group's drive directly.
You can use https://graph.microsoft.com/v1.0/groups/{team-id}/drive/root/children where /drive/root can get the Document library that the channel folders are part of and /children can display all items from the folder. Referto this doc for more details on how to get a DriveItem.
I'm using consumer OneNote in this scenario.
I have been querying my OneNote pages across a number of Notebooks using Graph with some success, but I've run into a strange issue. I'm note sure if it's a quirk in Graph or my Notebooks. I've reproduced the problem using Graph Explorer.
For example, If I issue the following request using Graph Explorer:
https://graph.microsoft.com/v1.0/me/onenote/pages?$top=100&$filter=id+eq+'0-fe674713edf84357871dbc179dfd924c!1-816F7725BEF00A5F!731388'
then I get a JSON response with the 'value' full of useful data.
If I issue the following request using Graph explorer:
https://graph.microsoft.com/v1.0/me/onenote/pages?$top=100&$filter=id+eq+'0-1f9aa8a73e9a4f14b4daa7762b5aa530!42-816F7725BEF00A5F!665027'
then I get a JSON response with an empty 'value'. All I've done is changed one known good ID for another known good ID.
I can:
Access both pages from Graph Explorer using a direct URL with the IDs used above
Access both pages using OneNote web app and Windows 10 version
Search for the 'lost' pages by title in the OneNote user interface successfully
It doesn't seem to matter what attribute of the pages I search for, the result is the same. Interestingly this only appears to affect pages from a certain point in one Notebook onward. The affected pages look OK in OneNote and load in both Web and Windows 10 version without problems.
I can create new pages in the Notebook containing the problem pages, but the new pages don't show up when I try to search for them using Graph.
Has anyone got a suggestion as to what I should try next?
EDIT:
New pages created in the problem Notebook do appear when searched for, it appears I was too impatient. The existing pages still cannot be found.
If the filtered page is not in the top 100 results, the response will be empty
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.
I need to search for files with .docx extension in my OneDrive. So this bit is simple and it works using OneDrive search api. The piece that does not work, is that in the response, with each DriveItem, I also need the custom properties we created under ListItem.Fields associated with this DriveItem. These custom properties contain information I need to create some sort of a report.
Expanding ListItem seems to work on root/children resource without any search, but it does not solve my problem, I need the files with the .docx extension in their filenames, these files can be under root or any sub folder under the root.
So this request returns the CustomProperty with the response
/_api/v2.0/drives/[drive id]/root/children?select=*%2cwebDavUrl
%2csharepointIds&expand=listItem(select%3dfields%3bexpand%3dfields(select%3dCustomProperty))
But when I try to expand ListItem on the DriveItems returned from search query as below:
/_api/v2.0/drives/[drive id]/root/search(q='docx')?select=*%2cwebDavUrl%2csharepointIds&expand=listItem(select%3dfields%3bexpand%3dfields(select%3dCustomProperty))
I get an error:
Error: {"error":{"code":"notSupported","message":"The request is not supported by the system."}}
Is expanding ListItem.Fields on a DriveItem not supported in OneDrive Search api ?
If it is not, then is there another way for me to achieve what I want to do here? I am not trying to search on the CustomProperty, just want to retrieve that value as part of the response with its associated DriveItem.
Expectedly, I get same/similar error if I run this through Microsoft Graph Search api instead of OneDrive api.
One workaround I could do,
is to first search for .docx files without the expand keyword and it will recursively search and return all .docx files in my OneDrive. Then I could make individual calls to request these items again one by one from OneDrive using their DriveItem.Id and the expanded ListItem.Fields property. That would be a terrible workaround though. Because instead of achieving what I need in a single request, I would have to make 1000s or 10000s of individual I/O requests (one per .docx file) to get the expanded ListItem properties..
This is a known issue with the /search endpoint. Unfortunately, there isn't a good workaround available at the moment either. In order to retrieve the ListItem resources, you will need to retrieve each DriveItem from your search result directly:
/drives/{drive-id}/items/{item-id}?$expand=listItem