I am using Microsoft Graph perform file operations on data in OneDrive. I have gained the access token with appropriate scopes and permissions (Files.ReadWrite.All).
A OneDrive user has shared a folder with me, which contains some files. Another user has given me rights to a the folder. I'm trying to move those files into my OneDrive but it doesn't allow me to do so. The client software is able to perform this operation (it might be doing it copy and then delete operation).
However I can copy those shared files into my account, and then later delete the shared one but I want to use the move file API.
I'm requesting along with access token retrieved previously, the request looks like:
https://graph.microsoft.com/v1.0/me/drives/{drive_id}/items/{item-id}
and I'm getting following response:
{
"error": {
"code": "invalidRequest",
"message": "Bad Argument",
"innerError": {
"request-id": "45d8b6a2-345a-44b7-a61e-abababababb",
"date": "2017-12-11T11:22:29"
}
}
}
Can someone please tell me which thing I'm missing?
This isn't a supported operation. You can only move a file within a single Drive, not from one Drive to another. From the documentation:
Items cannot be moved between Drives using this request.
Related
I need to export Exchange email (on premise) into *.eml file. The API
GET https://graph.microsoft.com/v1.0/users/{user_id}/mailFolders/Inbox/messages/{id}/$value
seems is the appropriate one. But it returns error below.
405 Method Not Allowed
{
"error": {
"code": "ErrorInvalidRequest",
"message": "The OData request is not supported. REST APIs for this mailbox are currently in preview. You can find more information about the preview REST APIs at https://dev.outlook.com/.",
"innerError": {
"date": "2022-02-19T15:22:01",
"request-id": "9118f0dd-8d06-4e2b-9fdb-355123ba6a66",
"client-request-id": "78ed917d-4602-867a-5db4-6615e6c29696"
}
}
}
I also tried the
GET https://graph.microsoft.com/v1.0/users/{user_id}/messages/{id}/$value
but still got same error.
But the
GET https://graph.microsoft.com/v1.0/users/{user_id}/mailFolders/Inbox/messages/{id}
can return result properly. It seems this is not security issue, because this API should already return enough data for constructing the *.eml file.
Any one have advise for this?
From the error it sounds like maybe you have a Hybrid environment https://learn.microsoft.com/en-us/graph/hybrid-rest-support and your trying to export a Message from a Mailbox that is onPrem?. If so that won't work for the onPrem mailboxes because they can only do a limited subset of the graph operations and Mime Export isn't one of the current features (not sure if that is going to change in the future). The only work around I know for onPrem would be to use EWS for those mailboxes https://learn.microsoft.com/en-us/exchange/client-developer/exchange-web-services/how-to-export-items-by-using-ews-in-exchange until this feature comes to the Graph for Hybrid mailboxes.
I am facing a weird issue with microsoft's graph api.
I am trying to retrieve files stored on Sharepoint. I don't know what the issue is and I have tried a lot of different things:
Call to get all drives for the site works and returns a list of all available drives:
GET https://graph.microsoft.com/v1.0/sites/site.sharepoint.com,<id>,<id>:/teams/myTeam:/drives
Via the previous endpoint I can extract the id for that drive with which I would then like to retrieve drive details (and in consequence all children of that drive):
GET https://graph.microsoft.com/v1.0/sites/site.sharepoint.com,<id>,<id>:/teams/myTeam:/drives/<driveId>
GET https://graph.microsoft.com/v1.0/sites/site.sharepoint.com,<id>,<id>:/teams/myTeam:/drives/<driveId>/root
GET https://graph.microsoft.com/v1.0/sites/site.sharepoint.com,<id>,<id>:/teams/myTeam:/drives/<driveId>/root/children
But all 3 above endpoints throw a 400 Bad Request Error with message: Url specified is invalid.
Additional information:
My access token has the following scopes: Sites.FullControl.All User.Read profile openid email
I am able to retrieve an individual drive item through the list endpoints (but the folder structure is quite complex and I need to list several layers of folders/files - this is why I believe the syntax with drive would be a lot more convenient):
GET https://graph.microsoft.com/v1.0/sites/site.sharepoint.com,<id>,<id>:/teams/myTeam:/lists/<list-id>/items/<item-id>/driveItem
via the field parentReference I am also able to fetch the driveId and even the relative path (/drives/<drive-id>/root:) but I also have no idea how I would get the content from that.
Help is greatly appreciated as I have been stuck for a long time now - thank you!
Try with the below HTTP call.
https://graph.microsoft.com/v1.0/sites/site.sharepoint.com,<id>,<id>/drives/driveid/root/children
It worked for me.
Microsoft introduced a special folder in OneDrive (I only see it in a personal OneDrive account, not in OneDrive for Business) called "Personal Vault". I searched the documentation of MS Graph API but could not find this mentioned.
So my question is: is there any way to access this personal vault as a third-party app?
Same problem here.
Funny thing is that:
It does not appear in the root children
It appears if you call the delta API where you can see a folder with the
specialFolder attribute not null and whose specialFolder.name is
"vault". This specialFolder, though, has the deleted facet, with the
state set to "hardDeleted". If you extract the ID from the delta API
call and try to address the folder directly with
https://graph.microsoft.com/v1.0/me/drive/items/{id}, however, you
get an access denied error
I am testing MSFT Graph's SharedWithMe REST API, and I continually get an empty collection returned from the service.
I have verified that there is a document (DriveItem) shared with me by a friend from another organization. I did this using the default, OneDrive webclient. There is a single document listed in that "tab" as expected.
I logged into my account (OneDrive Business) via Graph Explorer, and made sure I had Files.ReadWrite.All permission. I then issued the sample REST API to retrieve the items shared with me...but this is the response:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(driveItem)",
"value": []
}
Other REST calls via Graph Explorer do return results I would expect for my account, so I am positive I am authenticated properly.
I expect this API to have returned a collection with one (remote) DriveItem in it, but alas, it does not.
Since the REST service is returning a 200 (it's not syntactical), I'm at a loss as to how to troubleshoot this. Does anyone have any ideas?
Thanks.
It is not documented, but add the allowExternal querystring parameter:
https://graph.microsoft.com/v1.0/me/drive/sharedWithMe?allowExternal=true
I am currently working on a solution that is accessing OneDrive in Office 365 using Microsoft Graph. I am using the adal4j library to handle authentication and have configured the app in portal.azure.com.
My question relates the call to get the children for a specified drive. I am using a query similar to the one shown below, as I want to get folders and files at the root level of a specified users drive:
https://graph.microsoft.com/v1.0/users/*user id*/drives/*drive id*/root/children
When I login to the Graph Explorer and execute the query, I get a json result showing the root folder contents for the drive and user specified. All works as expected.
When I call it from my java application, the JSON node value is empty ([]).
Initially my thought was, because the Graph Explorer uses a different app id in the portal it was possibly something to do with access rights. However, I successfully read user profiles in our O365 tenant, the drive id's for each user, and if I execute the following:
https://graph.microsoft.com/v1.0/users/*user id*/drives/*drive id*/root/search(q='')
It provides me a complete list of all of the folders, sub folders etc within the appropriate user's drive.
Therefore, making me think this is a bug with the Graph query I am attempting to use rather than an authorization issue, but, that wouldn't explain why it works in the Graph Explorer.
The same java method is used for all calls, and the url is passed in as a parameter.
Just to follow up, the azure portal app permissions has the capability of adding permissions for the graph api. This was, indeed the problem. It would appear that the search was ignoring the permission and successfully reading the data whereas the /children call was honouring the security model. This caused a lot of confusion, but is now resolved.
Thanks Marc for your help.