KoenZomers / OneDriveAPI

API in .NET Framework 4.8.0, .NET Core 3.1 and .NET 6.0 to communicate with OneDrive Personal and OneDrive for Business
Eclipse Public License 1.0
109 stars 34 forks source link

GetItem method needs an override for the GraphAPI #29

Closed michaelbeaudin closed 3 years ago

michaelbeaudin commented 3 years ago

Describe the bug In the GraphAPI, the method "GetItem" doesn't work for the root folder like it did in the Consumer and O365 APIs.

To Reproduce To reproduce all you need to do is pass string.Empty to the "path" parameter of the "GetItem" method. You will be returned a null value. The previous API's were ok with sending "drive/root:/" concatenated with an empty path but the GraphAPI one only accepts "drive/root"

Expected behavior The expected behavior is to receive a OneDriveItem.

How to fix The fix for this should be simple. I have tried it on my side and the following works for me :

public override async Task<OneDriveItem> GetItem(string path)
            {
                if (string.IsNullOrEmpty(path))
                {
                    return await GetData<OneDriveItem>("drive/root");
                }

                return await GetData<OneDriveItem>(string.Concat("drive/root:/", path));
            }

Please do let me know when this is changed in the project or if I did anything wrong for me to need to do this.

Regards,

KoenZomers commented 3 years ago

Hi @michaelbeaudin, can you not use one of these instead?

image

These both work for me against the Microsoft Graph API.

What is it exactly that you're trying to receive? The files inside the root?

michaelbeaudin commented 3 years ago

Hello @KoenZomers,

Thank you for your answer. The method "GetDriveRoot" will work in my case. I must have somehow missed it when browsing through the files. I'll do a quick change to our code to make use of this method when the path is empty.

Regards,