Get Document Library document Templates - microsoft-graph-api

Once you defined additional document Templates within a Sharepoint document Library, how can they be retrieved through MS Graph?
Regarding MS documentation Templates are stored within a Folder called "Forms" (https://support.microsoft.com/en-us/office/set-a-custom-template-for-a-sharepoint-library-8e0177eb-46bd-4346-9998-330c32733c25). But this folder is neither listed through ms graph nor it can be browsed by path with ms graph. So my Question is how to access these document Templates?

SharePoint site and list has relationship to contentType.
ContentType resource type has property documentTemplate which should be what you are looking for.
Maybe the best way to start is to call Graph API and get contentType for your site or list.
GET https://graph.microsoft.com/v1.0/sites/{site_id}/contentTypes
GET https://graph.microsoft.com/v1.0/sites/{site_id}/contentTypes?$select=id,documentSet,documentTemplate
GET https://graph.microsoft.com/v1.0/sites/{site_id}/lists/{list_id}/contentTypes
GET https://graph.microsoft.com/v1.0/sites/{site_id}/lists/{list_id}/contentTypes?$select=id,documentSet,documentTemplate
Resources:
Content type

Related

Graph API create a driveItem with package property set

Using Microsoft graph API there are ways to create folders (as described here) or files (described here) driveItems.
However the driveItem also allows to have a package property, which makes it something different (currently only a package of {'type': 'oneNote'} can exist); it can easily be read but I can’t find a way to create such a package.
Using the OneNote graph API is not an option, since we work with tenant ID and it does not allow to create OneNote notebooks.
Am I missing something or is it really impossible (getting familiar with graph API I suspect the second)?
It is not possible to set a package property because it is read-only.
Resources:
driveItem properties

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

Graph API - Get recent files from a particular site collection

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

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