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.
Choose the permission or permissions marked as least privileged for this API. Use a higher privileged permission or permissions only if your app requires it. For details about delegated and application permissions, see Permission types. To learn more about these permissions, see the permissions reference.
Permission type
Least privileged permissions
Higher privileged permissions
Delegated (work or school account)
Files.ReadWrite
Files.ReadWrite.All, Sites.ReadWrite.All
Delegated (personal Microsoft account)
Files.ReadWrite
Files.ReadWrite.All
Application
Files.ReadWrite.All
Sites.ReadWrite.All
HTTP request
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
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 "[email protected]" 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
// Dependencies
using Microsoft.Graph.Drives.Item.Items.Item.Invite;
using Microsoft.Graph.Models;
var requestBody = new InvitePostRequestBody
{
Recipients = new List<DriveRecipient>
{
new DriveRecipient
{
Email = "[email protected]",
},
},
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",
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Drives["{drive-id}"].Items["{driveItem-id}"].Invite.PostAsInvitePostResponseAsync(requestBody);
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.drives.item.items.item.invite.InvitePostRequestBody invitePostRequestBody = new com.microsoft.graph.drives.item.items.item.invite.InvitePostRequestBody();
LinkedList<DriveRecipient> recipients = new LinkedList<DriveRecipient>();
DriveRecipient driveRecipient = new DriveRecipient();
driveRecipient.setEmail("[email protected]");
recipients.add(driveRecipient);
invitePostRequestBody.setRecipients(recipients);
invitePostRequestBody.setMessage("Here's the file that we're collaborating on.");
invitePostRequestBody.setRequireSignIn(true);
invitePostRequestBody.setSendInvitation(true);
LinkedList<String> roles = new LinkedList<String>();
roles.add("write");
invitePostRequestBody.setRoles(roles);
invitePostRequestBody.setPassword("password123");
invitePostRequestBody.setExpirationDateTime("2018-07-15T14:00:00.000Z");
var result = graphClient.drives().byDriveId("{drive-id}").items().byDriveItemId("{driveItem-id}").invite().post(invitePostRequestBody);
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph import GraphServiceClient
from msgraph.generated.drives.item.items.item.invite.invite_post_request_body import InvitePostRequestBody
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 = InvitePostRequestBody(
recipients = [
DriveRecipient(
email = "[email protected]",
),
],
message = "Here's the file that we're collaborating on.",
require_sign_in = True,
send_invitation = True,
roles = [
"write",
],
password = "password123",
expiration_date_time = "2018-07-15T14:00:00.000Z",
)
result = await graph_client.drives.by_drive_id('drive-id').items.by_drive_item_id('driveItem-id').invite.post(request_body)