// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Shares.Item.Permission.Grant;
using Microsoft.Graph.Models;
var requestBody = new GrantPostRequestBody
{
Recipients = new List<DriveRecipient>
{
new DriveRecipient
{
Email = "john@contoso.com",
},
new DriveRecipient
{
Email = "ryan@external.com",
},
},
Roles = new List<string>
{
"read",
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Shares["{sharedDriveItem-id}"].Permission.Grant.PostAsGrantPostResponseAsync(requestBody);
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.shares.item.permission.grant.GrantPostRequestBody grantPostRequestBody = new com.microsoft.graph.shares.item.permission.grant.GrantPostRequestBody();
LinkedList<DriveRecipient> recipients = new LinkedList<DriveRecipient>();
DriveRecipient driveRecipient = new DriveRecipient();
driveRecipient.setEmail("john@contoso.com");
recipients.add(driveRecipient);
DriveRecipient driveRecipient1 = new DriveRecipient();
driveRecipient1.setEmail("ryan@external.com");
recipients.add(driveRecipient1);
grantPostRequestBody.setRecipients(recipients);
LinkedList<String> roles = new LinkedList<String>();
roles.add("read");
grantPostRequestBody.setRoles(roles);
var result = graphClient.shares().bySharedDriveItemId("{sharedDriveItem-id}").permission().grant().post(grantPostRequestBody);
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph import GraphServiceClient
from msgraph.generated.shares.item.permission.grant.grant_post_request_body import GrantPostRequestBody
from msgraph.generated.models.drive_recipient import DriveRecipient
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = GrantPostRequestBody(
recipients = [
DriveRecipient(
email = "john@contoso.com",
),
DriveRecipient(
email = "ryan@external.com",
),
],
roles = [
"read",
],
)
result = await graph_client.shares.by_shared_drive_item_id('sharedDriveItem-id').permission.grant.post(request_body)