Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to get a Special Folder by name using the GraphServiceClient. #2624

Open
MaxxDelusional opened this issue Aug 16, 2024 · 3 comments
Open
Assignees
Labels
status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close type:question An issue that's a question

Comments

@MaxxDelusional
Copy link

Problem:

According to the docs, the request for a special folder should be GET /me/drive/special/{name}, however, there is no way to construct this path using the Graph SDK.

What I tried:

This does not work, because DriveRequestBuilder does not contain a definition for Special.

var result = await graphClient.Me.Drive.Special["approot"].GetAsync();

This will not work, because the slash will become url encoded.

var result = await graphClient.Me.Drives["special/approot"].GetAsync();

The C# example in the docs say to do this.

var result = await graphClient.Drives["{drive-id}"].Special["{driveItem-id}"].GetAsync();

But there is no drive-id to specify. Attempting to use null or empty string as the drive id created an invalid request url.

BaseGraphServiceClient does not contain a DriveRequestBuilder so we can't do something like this.

var result = graphClient.Drive.Special["approot"].GetAsync();

Potential Workaround:

The only way I have found to get the drive is by specifying the entire url, but clearly this is not ideal.

var result = await graphClient.Me.Drive
    .WithUrl("https://graph.microsoft.com/v1.0/drive/special/approot")
    .GetAsync();

Side Question: Is there a way to get the baseUrl from an instance of GraphServiceClient? Or any way to build a url with a relative path?

Suggestion:

Add SpecialRequestBuilder to DriveRequestBuilder or add handling for null drive-id in DrivesRequestBuilder.

The docs should also be updated, as the current C# example doesn't work. (You shouldn't need a drive-id, but the docs say to specify one).

@MaxxDelusional MaxxDelusional added the status:waiting-for-triage An issue that is yet to be reviewed or assigned label Aug 16, 2024
@shemogumbe shemogumbe added the P2 label Aug 19, 2024
@shemogumbe shemogumbe self-assigned this Aug 19, 2024
@andrueastman andrueastman removed the P2 label Aug 22, 2024
@andrueastman
Copy link
Member

Thanks for raising this @MaxxDelusional

Aside from the workaround suggested, you can pull in the drive Id as below.

            var myDrive = await graphClient.Me.Drive.GetAsync();
            var result = await graphClient.Drives[myDrive.Id].Special["approot"].GetAsync();

This is covered in a section of the docs at the link as to why the requestbuilders are not present due to large API surface increasing the SDK to a very large size.

https://github.com/microsoftgraph/msgraph-sdk-dotnet/blob/main/docs/upgrade-to-v5.md#drive-item-paths

@andrueastman andrueastman added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close type:question An issue that's a question and removed status:waiting-for-triage An issue that is yet to be reviewed or assigned labels Aug 22, 2024
@MaxxDelusional
Copy link
Author

It seems weird to make an extra call to the Graph API, just to grab a value that isn't actually needed, but I understand the desire to keep the SDK as small as possible.

If there was a way to provide a relative url to the WithUrl method, that would be ideal.

I tried this, but it's not supported.

var result = await graphClient.Me.Drive
    .WithUrl("{+baseurl}/drive/special/approot")
    .GetAsync();

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 and removed status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close labels Aug 22, 2024
@andrueastman
Copy link
Member

If there was a way to provide a relative url to the WithUrl method, that would be ideal.

At the moment you can't pass a relative url. You can however use the BaseUrl property in the request adapter to make a request as below.

var result = await graphClient.Me.Drive
    .WithUrl($"{graphClient.RequestAdapter.BaseUrl}/drive/special/approot")
    .GetAsync();

@andrueastman andrueastman added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close and removed Needs: Attention 👋 labels Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close type:question An issue that's a question
Projects
None yet
Development

No branches or pull requests

3 participants