Invite group to SPO document library using MS Api Graph

Sie7ex 0 Reputation points
2024-06-18T09:30:36.7+00:00

Hello.

I want to grant permissions to a group on a document library I have created in SharePoint using the MS Graph API.

I can read permissions using:

_graphServiceClient.Drives[driveid].Items[driveid].Permissions.GetAsync();

I can remove permissions using:

_graphServiceClient.Drives[driveid].Items[driveid].Permissions[perm.Id].DeleteAsync();

But when I try to add a group using:

var requestBody = new InvitePostRequestBody {
    Recipients = lstRecipients,
    RequireSignIn = true,
    SendInvitation = false,
    Roles = new List<string>() { "write"},
    RetainInheritedPermissions = true
};
_graphServiceClient.Drives[driveid].Items[driveid].Invite.PostAsInvitePostResponseAsync(requestBody);

I get the error "invalidRequest"

On the other hand, I can add permissions to an item within a document library using this method (It's just that in this case, I have an item ID different from the drive ID), but I cannot do so for the document library itself.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,162 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,771 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. AsithwMSFT 1,420 Reputation points Microsoft Vendor
    2024-06-22T20:57:31.09+00:00

    Hi @Sie7ex

    The documentation indicates that the message property is not optional. could you give a try including this property to the request body

    https://learn.microsoft.com/en-us/graph/api/driveitem-invite?view=graph-rest-1.0&tabs=csharp#request-body

    {
      "requireSignIn": false,
      "sendInvitation": false,
      "roles": [ "read | write"],
      "recipients": [
        { "@odata.type": "microsoft.graph.driveRecipient" },
        { "@odata.type": "microsoft.graph.driveRecipient" }
      ],
      "message": "string"
    }