Hi @Mariano Lorelli Thanks for reaching out. You can use following code in C# to generate link for a drive item.
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Drives.Item.Items.Item.CreateLink;
var requestBody = new CreateLinkPostRequestBody
{
Type = "view",
Password = "ThisIsMyPrivatePassword",
Scope = "anonymous",
RetainInheritedPermissions = false,
};
// 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}"].CreateLink.PostAsync(requestBody);
The above example requests a sharing link to be created for the DriveItem specified by {itemId} in the user's OneDrive. The sharing link is configured to be read-only and usable by anyone with the link. All existing permissions are removed when sharing for the first time if retainInheritedPermissions
is false.
For an item on sharepoint site you can use the following end point
/sites/{siteId}/drive/items/{itemId}/createLink
var result = await graphClient.Drives["{drive-id}"].Items["{driveItem-id}"].CreateLink.PostAsync(null);
For more information related to generating links with different access level refer to following documentation from Microsoft. https://learn.microsoft.com/en-us/graph/api/driveitem-createlink?view=graph-rest-1.0&tabs=csharp If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.