How to Create a SharePoint Anonymous Link Using REST API
Question details
The user wants to generate an anonymous sharing link for a SharePoint document using REST API or tools like Postman, allowing external users to access it without signing in.

- Product
- Microsoft SharePoint
- Device & OS
- not provided
- Scenario
- Developing or testing an API integration to programmatically share SharePoint documents with external users.
- Observed behavior
- The goal is to successfully generate a valid 'Anyone with the link' URL using Microsoft Graph API or legacy SharePoint REST/CSOM endpoints.
Ensure that your SharePoint and OneDrive tenant-level sharing policies permit 'Anyone' (anonymous) links, and that you have registered an application in Azure AD with the necessary API permissions (e.g., Sites.ReadWrite.All).
Generate Anonymous Links via Microsoft Graph API
Use the modern Microsoft Graph API endpoint to create a sharing link for a DriveItem. This is the recommended approach for modern Microsoft 365 environments.
Microsoft Graph provides a unified extensibility routing endpoint for Microsoft 365. Using the createLink endpoint is the most robust way to generate external sharing URLs programmatically.
Authenticate your application using OAuth 2.0 to obtain a Bearer access token with the necessary Microsoft Graph permissions.
Locate the target document's siteId, driveId, and itemId using standard Microsoft Graph queries.
Send a POST request to the endpoint: https://graph.microsoft.com/v1.0/sites/{siteId}/drives/{driveId}/items/{itemId}/createLink
In the JSON request body, specify the link parameters by setting 'type' to 'view' or 'edit', and 'scope' to 'anonymous'.
Parse the JSON response returned by the API to extract the newly generated sharing URL for your external users.

Create Anonymous Link Using SharePoint CSOM
If you are working within a legacy .NET environment, you can use the Web.CreateAnonymousLinkForDocument method in the Client-Side Object Model.
Need a simpler way to manage and share documents?
While configuring SharePoint APIs for anonymous links requires coding and strict permission management, WPS Office provides an intuitive, built-in document sharing feature. WPS Office is a free, lightweight suite fully compatible with Microsoft Office formats, making external collaboration effortless without the need for complex API setups.
- 1. Download and Install: Visit the official WPS Office website to download and install the free suite on your device.
- 2. Open Your File: Launch WPS Office and open the document, spreadsheet, or presentation you wish to share.
- 3. Share via Link: Click the 'Share' button in the top right corner to instantly generate a secure, accessible link for external users.

Frequently Asked Questions
Why do I get an 'Access Denied' error when trying to create an anonymous link via API?
This typically happens if your SharePoint tenant's external sharing policy is restricted. An administrator must explicitly enable 'Anyone' links in the SharePoint Admin Center for the entire tenant or the specific site.
Can I set an expiration date for the anonymous API link?
Yes. When using the Microsoft Graph API, you can include an expirationDateTime parameter in your POST request body to automatically disable the link after a specific date.
Do I need special Azure AD permissions to generate these links via API?
Yes. Your application registration must be granted the appropriate delegated or application permissions, such as Sites.ReadWrite.All or Files.ReadWrite.All, by a tenant administrator.




