Currently, SharePoint isn't actually sharing anything externally in O365. Azure AD is sharing to external users. So setting the permission on a list item is actually assigning an existing user in Azure AD to the item. The Sharing mechanism is actually handled by Azure AD. When you share via the UI, you are starting an event handled by Azure AD to create the guest user if it doesn't exist into the directory, then assign the SharePoint permission to the item or site.
But, there is a not very well known client side api for sharing in Microsoft.SharePoint.Client.Sharing namespace ()
This could potentially be called via REST calls and not the permission assignment action.
SharingResult result = ctx.Web.ShareDocument("https://contoso.sharepoint.com/docs/sample.doc", "someone@example.com", ExternalSharingDocumentOption.Edit,true, "Here's your important document");
This requires PnP components from PnP/Samples/Core.ExternalSharing at master · SharePoint/PnP · GitHub
Thanks for your response. I also tried the same. But it is only for the document. Not for list item. I try to share the list item link via this document share method as following in Azure.
DocumentSharingManager.UpdateDocumentSharingInfo(ctx, fileUrl, userRoles, false, true, true, message, true, true);
But it is sharing all items on the list.
Can you use Microsoft.SharePoint.Client.Web.ShareObject instead?