Search code examples
c#microsoft-graph-api

Microsoft Graph API - error on getting shares


I m using Microsoft Graph API to get a list of all available shares as follows.

GraphServiceClient _graphClient = new GraphServiceClient(myAuthProvider);
var shares = _graphClient.Shares.Request().GetAsync().Result;

I get the following error.

The request is malformed or incorrect

Other API calls for drives, sites, users, groups etc. work fine. Only this request fails. Why? How to find all available shares?


Solution

  • You have to specify shareId or sharing URL.

    GraphServiceClient graphClient = new GraphServiceClient(authProvider);
    
    var sharedDriveItem = await graphClient.Shares["{sharedDriveItem-id}"]
        .Request()
        .GetAsync();
    

    To encode a sharing URL, use base64 encode the URL

    Reference:

    Accessing shared DriveItems

    Encoding sharing URLs