logo
search
File Sharing Problems

How to Create a SharePoint Anonymous Link Using REST API

Huma Ashraf ChHuma Ashraf Ch Oct 22, 2026 868 views

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.

How to Create a SharePoint Anonymous Link Using REST API
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.
Before you start

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).

Solution 1Recommended

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.

1
Obtain an Access Token

Authenticate your application using OAuth 2.0 to obtain a Bearer access token with the necessary Microsoft Graph permissions.

2
Identify Resource IDs

Locate the target document's siteId, driveId, and itemId using standard Microsoft Graph queries.

3
Construct the POST Request

Send a POST request to the endpoint: https://graph.microsoft.com/v1.0/sites/{siteId}/drives/{driveId}/items/{itemId}/createLink

4
Configure the Payload

In the JSON request body, specify the link parameters by setting 'type' to 'view' or 'edit', and 'scope' to 'anonymous'.

5
Extract the Link

Parse the JSON response returned by the API to extract the newly generated sharing URL for your external users.

Generate Anonymous Links via Microsoft Graph API
Testing with Postman: When testing this workflow in Postman, ensure you add the Bearer token in the Authorization tab and set the Content-Type header to application/json.
Free Microsoft Office alternative

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. 1. Download and Install: Visit the official WPS Office website to download and install the free suite on your device.
  2. 2. Open Your File: Launch WPS Office and open the document, spreadsheet, or presentation you wish to share.
  3. 3. Share via Link: Click the 'Share' button in the top right corner to instantly generate a secure, accessible link for external users.
Seamlessly compatible with Microsoft Word, Excel, and PowerPoint formats (.docx, .xlsx, .pptx).Built-in one-click cloud sharing to easily generate viewing or editing links for external collaborators.Lightweight software that installs quickly and consumes minimal system resources.Familiar, tabbed user interface allowing a smooth transition from Microsoft Office.
microsoft office alternative - wps office

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.