Upload and set facet on the same onedrive upload request? - microsoft-graph-api

I want to use my onedrive as a document storage.
Each document should have some meta info associated so that I can search for them by using apis. So, suppose each document has a "student" and "age" associated meta.
According to the documentation I have to:
Make a PUT request against the OneDrive to upload my item
Make a PATCH request against the item, by providing a facet I previously created
Would it to be possible to create AND patch my item without having to make two request? It doesn't seem very intuitive to me...

Each action (uploading a DriveItem and updating a DriveItem record) requires a separate call to Microsoft Graph.
Considering the payload for your upload (PUT) is the binary content of the file, where would a developer deliver the JSON payload to update the metadata (PATCH)?

Related

how to get documents attached to a list item via graph api or sdk method?

Need to fetch this csv file from the list item via api/sdk method. Tried this api:
https://graph.microsoft.com/v1.0/sites/siteId/lists/listId/items/itemId , got the list item but not the attachments in it.
CRUD operations for list item's attachment are not supported by Graph API.
According this list item's attachment feature is in backlog.
Alternative is to use SharePoint API.
Its right as user2250152 mentioned,list items attachment is not supported by graph but you can raise a feature request here: https://techcommunity.microsoft.com/t5/microsoft-365-developer-platform/idb-p/Microsoft365DeveloperPlatform
Hope this helps.

Teams Graph API, Retrieving files from each Teams channel

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.

Is there a rest call to get the item id for a document on SharePoint online or on drive?

I need to obtain the document's information uploaded on SharePoint online. But I cannot use item id as it's not possible to keep a track of pre- uploaded documents.
Is there a rest call that can give the list of all the documents
Present on a drive/folder on SharePoint online or one drive?
Is there a rest call to get the item id for a document on SharePoint
online or on drive?
For this issue , you can retrieve the metadata for a DriveItem in a Drive by file system path or ID. For details please refer to this document.
Is there a rest call that can give the list of all the documents
Present on a drive/folder on SharePoint online or one drive?
For this issue,you have the below api to get all the files inside a folder. For details, please refer to this case.
<YouDomainServer>/_api/Web/GetFolderByServerRelativeUrl(<relativepath>)/Files
In addition ,you can also use Graph API to get user's one drive data in SharePoint. You can refer to this blog and case to get help.

Search sharePoint for specific contentType with MsGraph

I need to get sharePoint sites which contain specific type of items.
As I see on this docs
https://learn.microsoft.com/en-us/graph/query-parameters
searching is only supported for messages and persons, so I would need to know up-front in which sites and lists to look for the items of the given type or use the sharePoint api not the msGraph.
Am I correct or there is some other way?
For the files, you can use /search endpoint to perform search in the OneDrive and inside SharePoint/Group document libraries. Per documentation, you can use one of the following:
GET /drives/{drive-id}/root/search(q='{search-text}')
GET /groups/{group-id}/drive/root/search(q='{search-text}')
GET /me/drive/root/search(q='{search-text}')
GET /me/drive/search(q='{search-text}')
GET /sites/{site-id}/drive/root/search(q='{search-text}')
GET /users/{user-id}/drive/root/search(q='{search-text}')
For example, to retrieve all Excel files in user's OneDrive, you would perform such request:
GET /me/drive/root/search(q='.xlsx')
More info: https://learn.microsoft.com/en-us/graph/api/driveitem-search?view=graph-rest-1.0

OneDrive Search api does not support Expand query on ListItems

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

Resources