Search code examples
sharepointmicrosoft-graph-apionedrive

How do you create a share link for a document in Sharepoint through Microsoft Graph API


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?


Solution

  • 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