How to remove shared permission individual wise from an external user using One drive API inc#

Pradyut Sinha 21 Reputation points
2023-02-02T20:15:59.9266667+00:00

I have uploaded a file in one drive using MS graph one drive API. I have also shared this item to external

users by using one drive API. These two external users also showing in the manage access section as Link User.

i want to remove individual Link user by using one drive API in c#.

i have called MS graph API DELETE/me/drive/items/{item-id}/permissions/{perm-id} but it is removing al the external link user because permid is only one.

I want to delete permission for LINK external user individually.

Please Help.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,266 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,507 questions
OneDrive
OneDrive
A Microsoft file hosting and synchronization service.
1,142 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Srinivasa Rao Darna 6,741 Reputation points Microsoft Vendor
    2023-02-03T07:00:30.31+00:00

    Hello @Pradyut Sinha ,

    You can use /beta, permission: revokeGrants, revoke access to a listItem or driveItem granted via a sharing link by removing the specified recipient from the link.

    POST /drives/{drive-id}/items/{item-id}/permissions/{perm-id}/revokeGrants

    Note: This functionality is only available for sharing links scoped to users.

    
    GraphServiceClient graphClient = new GraphServiceClient( authProvider );
    
    var grantees = new List<DriveRecipient>()
    {
    	new DriveRecipient
    	{
    		Email = "ryan@contoso.com"
    	}
    };
    
    await graphClient.Me.Drive.Items["{driveItem-id}"].Permissions["{permission-id}"]
    	.RevokeGrants(grantees)
    	.Request()
    	.PostAsync();
    

    APIs under the /beta version in Microsoft Graph are subject to change. Use of these APIs in production applications is not supported.

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote it. If you have extra questions about this answer, please click Comment.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.