I have a filename on the root of OneDrive. The filename has a long name, 344 characters below a maximum 400 characters (1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111112222222222222222222222222222222222222222222222222233333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444.png). When I try to get an object using a path, I get an error.
{
"error": {
"code": "UnknownError",
"message": "",
"innerError": {
"date": "2021-01-28T11:02:35",
"request-id": "22461ea7-7ef9-4ad8-b945-ff7d3b9694d8",
"client-request-id": "669fd185-019c-b32e-112b-c52e1732d78f"
}
}
}
I'm using C# GraphClient library. How can I work with long filenames using a path?
That name exceeds the 255 characters per segment limitation in OneDrive and SharePoint:
Each segment of the path (a segment is a file name or folder name like “Promotion” or “Some File.xlsx” in the examples above) can't be more than 255 characters due to operating system limitations.
You can get a DriveItem the file by its id:
GET /drives/{drive-id}/items/{item-id}
GET /groups/{group-id}/drive/items/{item-id}
GET /me/drive/items/{item-id}
GET /sites/{site-id}/drive/items/{item-id}
GET /sites/{site-id}/lists/{list-id}/items/{item-id}/driveItem
GET /users/{user-id}/drive/items/{item-id}
I think you can list the children of the parent drive, and get the corresponding driveItemId for this file.
GET /drives/{drive-id}/items/{item-id}/children
GET /groups/{group-id}/drive/items/{item-id}/children
GET /me/drive/items/{item-id}/children
GET /sites/{site-id}/drive/items/{item-id}/children
GET /users/{user-id}/drive/items/{item-id}/children
Related
If I (my.user#example.com = logged in user) try to get a delta on a mail folder another user (other.user#example.com) shares with me...
https://graph.microsoft.com/v1.0/users/other.user#example.com/mailFolders/OtherUsersInboxFolderId==/messages/microsoft.graph.delta?$filter=ReceivedDateTime%20ge%202021-04-01T08:00:00.0000000Z
... I get an ErrorItemNotFound:
{
"error": {
"code": "ErrorItemNotFound",
"message": "The specified object was not found in the store.",
"innerError": {
"date": "2021-04-19T10:00:00",
"request-id": "<GUID>",
"client-request-id": "<GUID>"
}
}
}
If I do not request a delta but simply the messages in that folder, the request succeeds and returns the expected messages:
https://graph.microsoft.com/v1.0/users/other.user#example.com/mailFolders/OtherUsersInboxFolderId==/messages
If I (my.user#example.com) try to get a delta for the Inbox folder of a shared mailbox (shared#example.com), the request also succeeds:
https://graph.microsoft.com/v1.0/users/shared#example.com/mailFolders/SharedUsersInboxFolderId==/messages
https://learn.microsoft.com/en-us/microsoft-365/admin/email/create-a-shared-mailbox?view=o365-worldwide
So now my question is:
Why do deltas not work on folders another user shares with me?
Is it simply not implemented in the Graph API or am I doing something wrong?
Delta call is not supported on a shared mail folder and that is why you get 404.
Can anybody tell me how to get a list of just files in a particular folder on OneDrive using Microsoft Graph API? I believe I found an approach I have to use but either I don't understand something or it is impossible. I can get a list of children items in a folder. I can use $filter=folder ne null to get just a list of folders but I don't understand how to get a list of files. If I negate the expression, make it $filter=folder eq null it gives me an error. I tried many other possible expressions like $filter=file ne null, $filter=size ne 0 even though it is not exactly a filter for files a files can be 0 size but anyway it gives an error as well.
Update:
Tested in a test tool. It gives
{
"error": {
"code": "invalidRequest",
"message": "Invalid request",
"innerError": {
"date": "2021-02-23T06:25:08",
"request-id": "4d1903d3-d989-4d90-8130-479ac1b24af2",
"client-request-id": "4d1903d3-d989-4d90-8130-479ac1b24af2"
}
}
for this query
https://graph.microsoft.com/v1.0/me/drive/root/children$filter=folder eq null
Here is the link to the tool
https://developer.microsoft.com/en-us/graph/graph-explorer
I'm referring to this page https://learn.microsoft.com/en-us/onedrive/developer/rest-api/api/shares_get?view=odsp-graph-online on how to encode URIs for use with MS Graph API accessing shares.
My test URL which is a publicly shared file and seems to work fine, even if not logged in, is: https://1drv.ms/x/s!Alwuj_GU-JiCgYEI-kYrrTjyHUStlw?e=lgkUYX
Then the described process is to base64 encode the URI and then perform some character replacements and a prefix, this gives:
Base64 encoded:
aHR0cHM6Ly8xZHJ2Lm1zL3gvcyFBbHd1al9HVS1KaUNnWUVJLWtZcnJUanlIVVN0bHc/ZT1sZ2tVWVg=
After char replacements and prefix:
u!aHR0cHM6Ly8xZHJ2Lm1zL3gvcyFBbHd1al9HVS1KaUNnWUVJLWtZcnJUanlIVVN0bHc_ZT1sZ2tVWVg
That should then mean this URI should fetch the document details:
https://graph.microsoft.com/v1.0/shares/u!aHR0cHM6Ly8xZHJ2Lm1zL3gvcyFBbHd1al9HVS1KaUNnWUVJLWtZcnJUanlIVVN0bHc_ZT1sZ2tVWVg/driveItem
But the response is (EDIT):
"code": "invalidRequest",
"message": "The site in the encoded share URI is invalid.",
"innerError": {
"date": "2020-12-09T11:44:29",
"request-id": "305c6344-d59f-481b-9d28-334d72bd8ab0",
"client-request-id": "66138690-8312-a6d7-b35f-97bee7c32523"
}
It gets the same both when running on the Graph Explorer (logged in) and from our application itself.
What am I doing wrong? Have tried a lot of variations on the above, can't find anything that works.
I am trying to download documents attached to a OneNote Page using the Microsoft Graph API.
I find attached documents by looking for <object> elements like this in the document:-
<object data-attachment="test.txt" type="text/plain" data="https://graph.microsoft.com/v1.0/siteCollections/contoso.sharepoint.com,eb44cb06-54aa-4c1b-b749-14a6bc939040,90c50fc9-e9d8-483c-817d-a6006510e8e8/onenote/resources/1-11dbf2c6ff9e32c6a479858c38ac4688!1-c256504c-f305-4df3-9d00-f6d72aef06fc/$value"></object>
According to this page the data attribute is the URL to the file. I make a GET request to that url, replacing $value in the URL with content according to how files are downloaded as binary as described here, authorizing my request with the token.
When I perform this request, I get HTTP Code 400 and the following in the body:-
{
"error": {
"code": "BadRequest",
"message": "Resource not found for the segment 'siteCollections'.",
"innerError": {
"date": "2020-08-14T12:32:04",
"request-id": "6b7a9242-8cc0-4df5-afb6-075735045d0d"
}
}
}
What am I doing wrong?
Replacing /siteCollections/ with /sites/ in the URL produced a URL that yielded a successful response.
Weird quirk of OneNote?
I am using
https://developer.microsoft.com/graph/graph-explorer/
to test out some things. When I use
https://graph.microsoft.com/v1.0/me/mailFolders
https://graph.microsoft.com/v1.0/me/mailFolders/Inbox/messages
I get what I expect, a list of my folders and messages in my Inbox. When change me to my email address I get the same information. Now when I try using a different mailbox I have access to and try to get the messages in "Interesting Messages" I get the ErrorInvalidIdMalformed. I assume the issue is the space in the path
https://graph.microsoft.com/v1.0/users/otheremail#company.com/mailFolders/Interesting Messages/messages
{
"error": {
"code": "ErrorInvalidIdMalformed",
"message": "Id is malformed.",
"innerError": {
"request-id": "f47d4c3b-5681-4b83-b8f4-c2b9be591ff6",
"date": "2019-02-07T22:39:31"
}
}
I've tried using %20 instead of the space and I still get the error. Is there a way of having spaces in the URL or do I need to get the mailbox renamed?
TIA,
Joe
As per the docs for get messages
https://learn.microsoft.com/en-us/graph/api/user-list-messages?view=graph-rest-1.0
GET /users/otheremail#company.com/mailFolders/{id}/messages
You have to use the {id} of the mailFolder. That's why you are getting "ErrorInvalidIdMalformed" as its expecting an id.
You can get this by calling
GET /users/{id | userPrincipalName}/mailFolders
https://learn.microsoft.com/en-us/graph/api/user-list-mailfolders?view=graph-rest-1.0