I'm trying to create an anonymous link (it's OK if it times out after N number of days) from a file which is in SharePoint Online.
The documentation below seems to work for /me/
folders which are OneDrive for Business basically.
Is there no way of creating a share / anonymous link from a file stored in SharePoint?
I'm way too late to help you, but as I just wasted 2.5 hours to get this done, here's the trick :
POST https://graph.microsoft.com/v1.0/sites/{tenantName}.sharepoint.com,{siteCollectionId},{webId}/lists/{listId}/items/{itemId}/driveitem/createLink
With body :
{"type":"view","scope":"anonymous"}
{sitecollectionId}
: Can be obtained via {siteCollectionUrl}/_api/site/id
{webId}
: Can be obtained via {webUrl}/_api/web/id
{listId}
: Can be obtained in URL from the list settings page
{itemId}
: Can be obtained by displaying the "ID" field in the current view
How to get the DriveItem from a ListItem : https://learn.microsoft.com/en-us/graph/api/resources/listitem?view=graph-rest-1.0
How to build a share link for a DriveItem : https://learn.microsoft.com/en-us/graph/api/driveitem-createlink?view=graph-rest-1.0&tabs=csharp