Get External User Invitation details using CSOM

64 Views Asked by At

I tried to add the external user to direct access and i got a specific people link with edit permission. then I tried to get the link details using the role assignments for the particular file and the external user is not visible. after the user authenticate and use open the file the external user is visible under the group name starts with "SharedLinks....".

My question is "Is it possible to get the invitations of the external user using CSOM?" if yes, then how can i do that.

Also i found some reference to get that details in Rest API call, https://42jghx.sharepoint.com/sites/1gate/_api/web/Lists(list_id)/GetItemById(item_id)/GetSharingInformation?$Expand=permissionsInformation&$Select=permissionsInformation
using this Api call I can get permission of the item and also details of the shared link with external user invitations in them.

Is there any relevant CSOM C# code for the above API call?

1

There are 1 best solutions below

1
RaytheonXie-MSFT On

Here's an example of how you can use CSOM in C# to get details about external user invitations:

using System;
using Microsoft.SharePoint.Client;

class Program
{
    static void Main()
    {
        // Replace these values with your SharePoint site URL and credentials
        string siteUrl = "https://your-sharepoint-site-url";
        string username = "[email protected]";
        string password = "your-password";

        using (ClientContext context = new ClientContext(siteUrl))
        {
            // Provide credentials
            context.Credentials = new SharePointOnlineCredentials(username, password);

            // Get the site collection
            Site site = context.Site;
            context.Load(site);
            context.ExecuteQuery();

            // Get the external user invitations
            var externalUserInvitations = site.GetInvitations();
            context.Load(externalUserInvitations);
            context.ExecuteQuery();

            // Display invitation details
            foreach (var invitation in externalUserInvitations)
            {
                Console.WriteLine($"Invitation ID: {invitation.InvitationId}");
                Console.WriteLine($"Email: {invitation.InvitedUserEmail}");
                Console.WriteLine($"Invited by: {invitation.InvitedBy}");
                Console.WriteLine($"Invited on: {invitation.InvitedOn}");
                Console.WriteLine($"Invitation status: {invitation.Status}");
                Console.WriteLine();
            }
        }
    }
}