Create a sharing link for a DriveItem POST createLink / Error: Operation is not valid due to the current state of the object.

Lanvale Consulting 0 Reputation points

I'm having trouble creating a sharing link using the MS Graph application.

The process is as follows

  1. Create a SharePoint folder (DriveItem) on a specific Sharepoint site/ParentFolder (This action is currently working like a charm).
  2. When a folder is created, then generate an "Anyone" link for unauthenticated People outside the organization.

I confirm this is possible using the sharepoint UI

But using my Graph application with the following documentation permissions: Create a sharing link for a DriveItem

I'm not able to generate the "Anyone" Sharing Link for my folders

Below is the sharing settings of my SharePoint site:

Sharing: Anyone

Advanced settings for external sharing: Unchecked

Default Sharing Link Type: Anyone with the Link

Default Link Permission: Edit

When calling the createLink endpoint: POST /sites/{siteId}/drive/items/{itemId}/createLink

With the following payload:


"type": "edit",

"scope": "anonymous",

"retainInheritedPermissions": false


Server reply with the following:


    "error": {

        "code": "generalException",

        "message": "Operation is not valid due to the current state of the object.",

        "innerError": {

            "date": "2024-06-14T18:46:41",

            "request-id": "bccb5483-915a-47f6-8fb7-71cda1256ce0",

            "client-request-id": "bccb5483-915a-47f6-8fb7-71cda1256ce0"




I build my app following MS Graph documentation, I'm pretty sure everything is aligned.

I'll appreciate your help.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,318 questions
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,211 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 33,481 Reputation points Microsoft Vendor

    Hi @Lanvale Consulting,

    If you want to create a sharelink for driveitem, you will need to use following api

    POST /drives/{driveId}/items/{itemId}/createLink

    The endpoint you mentioned is to create a sharelink for items in sharepoint

    Here is the document for reference

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.