List folder contents of 'Shared with Me' folder from Office 365 OneDrive (Sharepoint) for Business and Education using the REST api? - rest

Is there a way to get the contents of the 'Shared with Me' folder from the Office 365 (Sharepoint) REST api ?
I can't see anything in the api reference reagrding this.
https://msdn.microsoft.com/office/office365/APi/files-rest-operations

Found the solution to this...
Instead of using the files api you must use the sharepoint search api.
The following endpoint with the KQL query parameters can be used to get a list of files 'shared with me'
https://{tenant}-my.sharepoint.com/_api/search/query?querytext='(SharedWithUsersOWSUSER:{UserAccountName} AND contentclass:STS_ListItem_MySiteDocumentLibrary)'
This above will get a list of files 'shared with me' but not anything inside a shared folder. To get the items inside a shared folder you can use the following endpoint.
https://{tenant}-my.sharepoint.com/_api/search/query?querytext='(ParentLink:{ParentLink})'
Make sure the parent link is url encoded. You can retrieve the parent link from the folder properties.
Finally to get the account name used in the first request you can make a request to the sharepoint webs api.
https://{tenant}-my.sharepoint.com/_api/web/CurrentUser

Related

How to get a single file that has been shared with me on OneDrive?

I'm building an app that uses the ms-graph v1.0 API to write data to excelsheets in my OneDrive. It works with excel files that I uploaded to my drive but doesn't work with excel files that've been shared with me.
I know that I can get a list of all shared files with me/drive/sharedWithMe and the file that i want to edit is amongst the files that are being returned.
However, when i try to get one shared drive item using its driveItem property parentReference: driveID like this: /drives/{driveID}/items/{itemID} it returns : 403 - acces denied.
Here are my permissions:
"user.read",
"calendars.read",
"directory.accessasuser.all",
"files.readwrite.all"
I couldn't try the shares path /shares/{shareID} because I don't know how to figure out the shareId. It doesn't seem to be among the properties of the item that is returned by /sharedWithMe. Where can I get it?
Figured it out by myself.
I got the error
"message": "Cannot reference a user's drive from another user's personal site"
so I removed the me/from the route me/drives/{driveID}/items/{itemId} and it worked.

How search for item in specific folder and get its properties with sharepoint online REST API?

I have to search in specific subfolder on sharepoint online for file with title.
Right now I am using the following call
/_api/web/lists/getByTitle('MyDoc3')/items?$select=FileRef&$filter=substringof(%27test2.docx%27,FileRef)
But here I am passing a list title to get the file ref as output. How can I search in specific folder by url and get the same output as above call?
You can use Regular Expressions to extract the list name from the URL- and then use the list name in the above query
You could use below GetFolderByServerRelativeUrl endpoint to get specific libray folder by relative url like below and select the file server relative url which is the same as FileRef.
Below get the default Document library root folder:
https://tenant.sharepoint.com/sites/dev/_api/web/GetFolderByServerRelativeUrl('/sites/dev/Shared%20Documents')/files?$select=ServerRelativeUrl
Reference:
Working with folders and files with REST

deals with hidden folder

We are a little company in france, and we have developed a add-in for outlook, that used the WS exchange and VSTO. We need to develope this plugins for office 365
How can we deals with hidden folder inside a outlook mailbox ?
With WS Exchange we can hide a folder in the directory of an outlook account. We can send an SingleValueExtendedProperties (0x104f : true) to make that.
Whit the office 365 we can send this same SingleValueExtendedProperties the folder is correctly hide, but after that we can't list them, we can't move them, we can't delete them... a ghost, but when we cant to create a folder whit the same name, we get an error that indicate a folder already exists...
Folder list
GET https://outlook.office.com/api/v2.0/me/MailFolders
create folder
POST
https://outlook.office.com/api/beta/me/MailFolders/{folder_id}/childfolders
{
"DisplayName": "Business"
}
Update folder : rename + hide -> 404 but no floder after that
PATCH https://outlook.office.com/api/v2.0/me/MailFolders/AAMkAGNlZmM5OTBlLTMwZTgtNGQzZS1iM2IzLTRjNWNkZDNlMTU4NAAuAAAAAADp0G8t0SUuQJyWc5hKYYdzAQA76fHUOjd6RImcXSS_fEDDAAAAADIrAAA=
{
"DisplayName": "test",
"SingleValueExtendedProperties":[
{
"PropertyId":"Boolean 0x10f4",
"Value": "true"
}
]
}
after this rest call, folder is hidden and unusable...
Thank's
The behavior is obvious. It won't allow to create new folder with the same name as it is just hiding the folder not removing permanently.
For Office 365 I would rather recommend you to use Outlook Web Add in template and for code Microsoft graph as It is providing all office 365 products api at single place. Then after you won't need to use VSTO Addin. single development will work for both Outlook client application and Outlook online.
screenshot: https://learn.microsoft.com/en-us/outlook/add-ins/images/uiless-command-shape.png
ref : https://learn.microsoft.com/en-us/outlook/add-ins/
Yes we adapt the addins to office 365 with graph api. But this for me is a bug in graph api. We can hide a folder and after all command sent an 404 error, folder not found.
If we have hide a folder, the rest api whould offer the possibility to move, edit, unhide, delete, list this item. In my case with a 365 office cloud instance, i can't made anything whit this folder, the administration panel of my company can't display folders of an user account, the user account administration panel can't edit the folder list. How can i manage this "ghost" folder.

Microsoft Graph API - /drive/root/children always empty, even though I have files in my onedrive

I'm trying to use the Microsoft Graph API to List Children by Getting access without a user
I have built my URL as you would expect:
https://graph.microsoft.com/v1.0/edffcd1c-e5b2-42f2-b554-XXXXXXXXX/drive/root/children
Where edffcd1c-e5b2-42f2-b554-XXXXXXXXX is the user ID of whom I'm trying to list the files.
Yet when I call this I get an empty result every time:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#drive/root/children",
"value": []
}
Why is that?
UPDATE: It seems that this API is only returning files from the Sharepoint account... not the OneDrive account. I already have access to the Sharepoint files from the Sharepoint API's themselves. Is there a way to get OneDrive files from the Microsoft Graph API?
This URL https://dev.onedrive.com/README.htm seems to state that we should be able to do this.
Is there a way to get OneDrive files from the Microsoft Graph API?
Yes, there is: you must use the scope Files.Read.All or Files.ReadWrite.All
then, your requests to /drive/root/children will no longer return an empty array.
I just had a typo in the User:
https://graph.microsoft.com/v1.0/edffcd1c-e5b2-42f2-b554-XXXXXXXXX/drive/root/children
was supposed to be
https://graph.microsoft.com/v1.0/users('edffcd1c-e5b2-42f2-b554-XXXXXXXXX')/drive/root/children
You can also use this endpoint
https://graph.microsoft.com/v1.0/me/drive/root/children
and pass authorization header Bearer Token
There are two things:
1) First check if the user has given the permission for
Files.Read.All or Files.ReadWrite.All
2) The following endpoint didn't work for business account
/drive/root/children
I changed it to
/drives/{drive_id}/root/children
and it worked fine. Please check.

Unable to work with hidden folders in the office365 Graph mail folder API

I have successfully created some mail folder, and then made it hidden with the following update:
patch /users/xxx#xxxx/mailFolders/folderId
{"singleValueExtendedProperties": [{"id":"boolean 0x10f4", "value":"**true**"}]}
(explanations about creating a hidden folder https://msdn.microsoft.com/en-us/library/office/dn659505(v=exchg.150).aspx):
Then I checked it with EWSEditor.exe, which proved the folder was successfully made hidden.
(But the patch call return 404, I think it is some bug of this API, it should return 200 since the update is successful)
After that, if I try to make the folder visible, the update always fails:
patch /users/xxx#xxxx/mailFolders/folderId
{"singleValueExtendedProperties": [{"id":"boolean 0x10f4", "value":"**false**"}]}
And for this hidden folder, there is no way to list it out or find it out. Trying to delete this hidden folder with the remembered ID fails, too.
So, it seems there are some bugs in the Graph mail folder API:
It should be allowed to make a hidden folder visible after a
previous update to hidden from visible.
There should be some API to list the hidden folder.
The Delete API should be able to delete the hidden folder.
Reset this property to false in EWS editor and save. You will be able to get this folder again with graph api.
This feature is now available in Graph Public Beta. You can access hidden mail folders via the /mailFolders API by adding a new query parameter called includeHiddenFolders. ​You can read more about the feature # below links:
About Hidden Folders: https://learn.microsoft.com/en-us/graph/api/resources/mailfolder?view=graph-rest-beta#hidden-mail-folders
Get a list of hidden mailFolders: https://learn.microsoft.com/en-us/graph/api/user-list-mailfolders?view=graph-rest-beta&tabs=http#example-2-include-hidden-folders-in-the-signed-in-users-mailbox