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

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

Related

List of files and folders that don't require authentication

How can I get a list of shared files or folders that don't require you to authenticate to download the file etc, is there a specific attribute for the listed files and folders using "files_list_folder"
There isn't such a property on the entries returned by files_list_folder/files_list_folder_continue directly, but you can use files_get_temporary_link to get a temporary direct link to a file. The files_get_temporary_link call itself requires authorization, but the resulting link doesn't.

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.

Downloading and Moving OneDrive files from shared link directory

I am looking for assistance to find out how I can download and move a OneDrive file that is accessed through a shared directory, via the shared link method of sharing.
I have two users:
user 'A' who is a Microsoft Consumer and has a regular OneDrive account and will host a csv file 'test.csv' in a folder 'toshare'
and user 'B' who is also a regular Microsoft Consumer who should use the graph API to download test.csv and then move the file to a subdirectory /toshare/archive
Aside: I am currently using the chrome app "advanced REST client" to manually make the REST calls, and am getting Authenticated OAuth BEARER tokens by inspecting network traffic from Microsoft's online "Graph Explorer" tool. After we understand the calls, we'll integrate it into our Java app.
I have succesfully followed the instructions here:
https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/shares_get
to view the folder contents.
To be more explicit, user 'A' has went into OneDrive and has right clicked the folder 'toshare' and selected shareLink. I have converted the shareLink to a share token and then used the following API call with the Graph API as user 'B':
GET https://graph.microsoft.com/v1.0/shares/<share-token>/root?$expand=children
this shows me all the files in the directory, which includes 'test.csv'
Now, using this information, how can I download test.csv? Assuming user 'B' doesn't know the name of the file, but can identify it by being a .csv file (we can do this in code). There does not appear to be much documentation on how to download the files through a share.
The closest I've gotten was to take the "webUrl" attribute of the children object for my file, and then turn that into a share token and call
GET https://graph.microsoft.com/v1.0/shares/<child-share-token>/root
This will show me the file meta-data. and then I try to download it by roughly following the api documentation to download https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/item_downloadcontent
GET https://graph.microsoft.com/v1.0/shares/<child-share-token>/root/content
This is interesting because this works if I make the call with user 'A' but does not work for user 'B' who instead gets a 403 in advanced REST client. (If I run it in Graph Explorer, I get "The site in the encoded share URI is invalid." instead, which I've discovered with other experimentation, really means there's an authorization issue.)
GET https://graph.microsoft.com/v1.0/shares/<share-token>/root:/test.csv:/content
Also does not work, it returns: "400 Bad Request" with message: "Resource not found for the segment 'root:'." It seems like the path style file navigation does not work for shared directories?
At this point I'm rather stuck. After downloading the file, I also would like to move it into a subdirectory, denoting that it has already been read in. I'd also like to get this working for OneDrive for Business, but that seems to be another set of challenges that I'll leave for another day.
Any insight would be great thanks,
Jeremy
It's best to consider the shares/{id} segments to be similar to drives/{id}, at which point all of the previous documentation around children access is applicable. Given your scenario I'd use the path syntax:
https://graph.microsoft.com/v1.0/shares/<share-token>/root/children/test.csv
This obviously necessitates knowing the file name, but it sounds like you already have an algorithm to do that.
Theoretically your approach for creating a child-share-token would work, but it would now require that User B both provide authentication as well as to have explicit permissions. Since your share-token was a sharing link User B is most likely getting permission by virtue of the fact that they have the URL, in which case generating a new one is probably removing the special token that allows this to work. That's why it's best to always use the original share-token where possible.
Similar rules will apply to move the file. First off, we'll assume that the sharing link provides the ability to "Edit" otherwise none of this will work :). Second, we'll assume that the archive folder already exists (if it doesn't you'd need to create it using a POST to https://graph.microsoft.com/v1.0/shares/<share-token>/root/children that looks like what we've documented here).
To move the file you'd want to PATCH to https://graph.microsoft.com/v1.0/shares/<share-token>/root/children/test.csv and provide a new parentReference as documented here. It's always best to use id values if you have them, but you should also be able to provide the path to the parent in the form of /shares/<share-token>/root/children/archive.

Import API not working in sisense

I was trying to use the dashboard import API from v1.0 which can be found in the REST API reference. I logged in to http://localhost:8083/dev/api/docs/#/ , gave the correct authorization token, and a dash file in the body, and a 24 character importFolder and hit the Run button to fire the API. It returns 201 as HTTP response, which means the request was successful. However, when I go back to the homepage, I don't see any new dashboard imported in to the said folder. I have tried both cases, where the importFolder exists (already created manually be me), and does not already exist, where I expect the API to create it for me. Neither of these, however, create/import the dashboard
A few comments that should help you resolve this:
When running the command from the interactive API reference (swagger) you don't need the authentication token, because you're already logged in with an active session.
Make sure the json of your dashboard is valid, by saving it as a .dash file and importing via the UI
The folder field is optional - if you leave the field blank, the dashboard is imported to the root of your navigation/folders panel.
If you'd like to import to a specific folder, you'll need to provide the folder ID, not its name, which can be found several ways such as using the /api/v1/folders endpoint, where you can provide a name filtering field and use the oid property of the returned object as the value for the folder field in the import endpoint.
If you can't get this to work still, use chrome's developer tools to look at the outgoing request when you import from the UI and compare the request (headers, body and path) to what you're doing via swagger in order to find the issue.

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

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