SharePoint Asked by elb98rm on October 25, 2021
The Graph API isn’t well documented about a few things, and so I was wondering if anyone had some insight, or direct answers to the following problem:
I am attempting to create a RESTful API that interacts with the shared documents of a sharepoint site to automate much of the process.
I will be storing customer documents in a user folders. These folders are created using an identity (id/guid) style naming convention. Each file they create or are allocated are stored there. There may be duplicate names across customers.
I have created the C & D of CRUD, and with a microsoft ID can easily R (and download).
However, there are problems searching, and the microsoft documentation is far from complete.
These are the routes I’m (successfully) using to do my operations:
(all with the prefix: https://graph.microsoft.com/v1.0/
)
{site_name}/drive/root/children
{site_name}/drive/items/{parent_folder_id}:/content
{site_name}/drive/items/{resource_id}/
{site_name}/drive/items/{resource_id}/content
{site_name}/drive/items/{resource_id}
These are working as expected.
How do I format request in order to search:
There is no documentation I can find that shows to perform the list, but .. not at root level!
{site_name}/drive/root/children
.. so what is the format to limit this search to a folder.
Here’s some pseudo-code that doesn’t work:
{site_name}/drive/{folder_name}/children
{site_name}/drive/root/{folder_name}/children
Note: This is for the very common customer use case:
Given that many files in different folders will have the same name, how do I format a search to be limited to a folder.
The current suggested search criteria is as follows:
/search(q='{search_value')
If I run the following query, it runs at a root level:
{site_name}/drive/root/children?search(q='{search_value')
How do I format this to be limited to a folder?
Is there a way to limit the search criteria to search by a property? For example, to distinguish between the following:
abcdff.jpg
abcdef ...
…or some such combination of metadata.
So using some psuedo-SQL type URL:
{site_name}/drive/root/children?search(q='{name=search_value}')
Thanks in advance to all.
I'm just answering question detail #1.
As far as I've learnt, a SharePoint site has a drive associated with it and each document library or list has its own drive too.
In order to get the drive's id associated with a site or list/library, you've got to use the ODATA parameter expand
:
GET sites/{site-id}/?expand=drive
to get a site's drive id
GET sites/{site-id}/lists/{list-id}?expand=drive
to get a list or library's drive id
NOTE: it doesn't work with items in a list. Don't ask me why...
Once you've got the drive id you need, you can access the root of that document library like:
GET drives/{doc-library-drive-id}/root/children
: list the children of the root document library, where you'll see the first level of folders or document sets (very useful to use as "folders with metadata" and metadata inheritance.
You'll see that each folder has its own drive id too. So, to get the folder's children, I recommend using the following endpoint:
GET drives/{doc-library-drive-id}/items/{folder-drive-id}/children
This will fetch the children of that folder. I use this endpoint because I've had problems using the {site_name}/drive/root/{folder_name}/children
you suggested because of certain chars the folders may have (we speak Spanish in our organization).
NOTE: if you use the approach /sites/{site-id}/drive/items/{item-id}/children
as described in the docs, you'll access the default document library of the site (Documents). So, if you need to get to a different document library, you'll need to specify its drive id like described above
So, my approach to get the folder's children is:
Answered by Andrés Biarge on October 25, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP