Sends a sharing invitation for a driveItem.
A sharing invitation provides permissions to the recipients and optionally sends them an email with a sharing link.
Permissions
One of the following permissions is required to call this API. To learn more, including how to choose permissions, see Permissions.
POST /drives/{drive-id}/items/{item-id}/invite
POST /groups/{group-id}/drive/items/{item-id}/invite
POST /me/drive/items/{item-id}/invite
POST /sites/{siteId}/drive/items/{itemId}/invite
POST /users/{userId}/drive/items/{itemId}/invite
Request body
In the request body, provide a JSON object with the following parameters.
A collection of recipients who will receive access and the sharing invitation.
message
String
A plain text formatted message that is included in the sharing invitation. Maximum length 2000 characters.
requireSignIn
Boolean
Specifies whether the recipient of the invitation is required to sign-in to view the shared item.
sendInvitation
Boolean
If true, a sharing link is sent to the recipient. Otherwise, a permission is granted directly without sending a notification.
roles
Collection(String)
Specifies the roles that are to be granted to the recipients of the sharing invitation.
expirationDateTime
DateTimeOffset
Specifies the dateTime after which the permission expires. For OneDrive for Business and SharePoint, xpirationDateTime is only applicable for sharingLink permissions. Available on OneDrive for Business, SharePoint, and premium personal OneDrive accounts.
password
String
The password set on the invite by the creator. Optional and OneDrive Personal only.
retainInheritedPermissions
Boolean
Optional. If true (default), any existing inherited permissions are retained on the shared item when sharing this item for the first time. If false, all existing permissions are removed when sharing for the first time.
Example
This example sends a sharing invitation to a user with email address "ryan@contoso.com" with a message about a file being collaborated on.
The invitation grants Ryan read-write access to the file.
HTTP request
If successful, this method returns 200 OK response code and permission collection object in the response body.
// Code snippets are only available for the latest version. Current version is 5.x
var graphClient = new GraphServiceClient(requestAdapter);
var requestBody = new Microsoft.Graph.Drives.Item.Items.Item.Invite.InvitePostRequestBody
{
Recipients = new List<DriveRecipient>
{
new DriveRecipient
{
Email = "ryan@contoso.com",
},
},
Message = "Here's the file that we're collaborating on.",
RequireSignIn = true,
SendInvitation = true,
Roles = new List<string>
{
"write",
},
Password = "password123",
ExpirationDateTime = "2018-07-15T14:00:00.000Z",
};
var result = await graphClient.Drives["{drive-id}"].Items["{driveItem-id}"].Invite.PostAsync(requestBody);
<?php
// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($requestAdapter);
$requestBody = new InvitePostRequestBody();
$recipientsDriveRecipient1 = new DriveRecipient();
$recipientsDriveRecipient1->setEmail('ryan@contoso.com');
$recipientsArray []= $recipientsDriveRecipient1;
$requestBody->setRecipients($recipientsArray);
$requestBody->setMessage('Here\'s the file that we\'re collaborating on.');
$requestBody->setRequireSignIn(true);
$requestBody->setSendInvitation(true);
$requestBody->setRoles(['write', ]);
$requestBody->setPassword('password123');
$requestBody->setExpirationDateTime('2018-07-15T14:00:00.000Z');
$result = $graphServiceClient->drives()->byDriveId('drive-id')->items()->byItemId('driveItem-id')->invite()->post($requestBody);