Onedrive-api-docs: API is creating invalid sharing links in some folders

Created on 6 May 2019  Â·  15Comments  Â·  Source: OneDrive/onedrive-api-docs

Category

  • [ ] Question
  • [ ] Documentation issue
  • [x] Bug

Expected or Desired Behavior

The API to create a sharing link should return a valid sharing link that can be accessed.

Observed Behavior

In some folders, when creating a Sharing Link, the generated link doesn't work. The API seems to always return the same Sharing Link but when I go to the folder and check the created Sharing Links it doesn't show any, and if I try to open the sharing link it says "Pedimos desculpa mas algo correu mal" which means something link "We are sorry but something went wrong".

I'm following this documentation: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_createlink?view=odsp-graph-online

I'm using a business account.

Steps to Reproduce

I create request with this information:
Item Id: 01CFGODSUNRIQ5P2BMDFGJVMQTKTPUSUQJ

Url: https://graph.microsoft.com/v1.0/me/drive/items/01CFGODSUNRIQ5P2BMDFGJVMQTKTPUSUQJ/createLink

Body:
    Format: JSON (application/json)
    Content: {"type":"edit","scope":"organization"}
Headers:
    Authorization: Bearer eyJ0eXAiOiJKV1QiLCJub25jZSI6Ik
    Content-Type: application/json

Postman images for more detail:

https://i.ibb.co/cvF1hT1/od-print-2-edited.png

https://i.ibb.co/6NZkDhL/od-print-3-edited.png

C# Code that I also used:

```c#
public Permission CreateSharedLinkOfItem(string itemId, string type)
{
string graphUrl = $"https://graph.microsoft.com/v1.0/me/drive/items/{itemId}/createLink";
HttpWebRequest request = WebRequest.CreateHttp(graphUrl);
request.Headers.Add("Authorization", "Bearer " + AccessToken);
request.ContentType = "application/json";
request.Method = "POST";

FolderSharedLink folderSharedLink = new FolderSharedLink
{
    Scope = "organization",
    Type = type
};

using (var streamWriter = new StreamWriter(request.GetRequestStream()))
{
    string json = JsonConvert.SerializeObject(folderSharedLink);
    streamWriter.Write(json);
    streamWriter.Flush();
    streamWriter.Close();
}

var response = request.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
    return JsonConvert.DeserializeObject<Permission>(reader.ReadToEnd());
}

}

Response:

I placed "*" in the response to hide some info about my company.

```json
{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#permission",
    "@odata.type": "#microsoft.graph.permission",
    "id": "f29249bb-616f-4522-a1c8-84c751e20fbb",
    "roles": [
        "write"
    ],
    "link": {
        "scope": "organization",
        "type": "edit",
        "webUrl": "https://spa*********-my.sharepoint.com/:f:/g/personal/fileserver_******_fr/Eo2KIdfoLBlMmrITVN9JUgkBrsp2N8CfXc2MPPLYzGoBIg"
    }
}

If I try to open the webUrl returned it shows this:

Original text

Pedimos desculpa, mas algo correu mal
Sorry, you cannot access this document. Please contact the person who shared it with you.
DETALHES TÉCNICOS



Resolver problemas com o Microsoft SharePoint Foundation.
ID de Correlação: 66e6d99e-100e-0000-6aa7-446c7920d509

Data e Hora: 5/6/2019 1:19:02 AM

Translated text

We're sorry, but something went wrong.
Sorry, you can not access this document. Please contact the person who shared it with you.
TECHNICAL DETAILS



Troubleshoot issues with Microsoft SharePoint Foundation.
Correlation ID: 66e6d99e-100e-0000-6aa7-446c7920d509

Date and Time: 5/6/2019 1:19:02 AM

https://i.ibb.co/R788456/od-print-4.png

investigating bug

Most helpful comment

Thanks for all the details @carloswbarros, while I'm still not sure what's going on it's fairly safe to say it's a bug. With the data you provided hopefully we can get to the bottom of it soon.

All 15 comments

Thanks for reporting @carloswbarros - is there anything special that these folders have in common? Could you post the request-id and date headers from the response that returns the invalid sharing link?

I think the sharing links of these folders were deleted manually in the OneDrive page, or they were created a long time ago. I not sure though...

I just made a request and got this headers:

Cache-Control →private
Content-Encoding →gzip
Content-Type →application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8
Date →Mon, 06 May 2019 15:24:45 GMT
Duration →682.1621
Location →https://graph.microsoft.com
OData-Version →4.0
Strict-Transport-Security →max-age=31536000
Transfer-Encoding →chunked
Vary →Accept-Encoding
client-request-id →fff8a9f7-8411-45d7-8e73-18b5c4231fb7
request-id →fff8a9f7-8411-45d7-8e73-18b5c4231fb7
x-ms-ags-diagnostic →{"ServerInfo":{"DataCenter":"North Europe","Slice":"SliceC","Ring":"3","ScaleUnit":"001","RoleInstance":"AGSFE_IN_26","ADSiteName":"NEU"}}

I found something, If I open the sharing url with the android app it works, even though in the website it doesn't show the created sharing url (https://i.ibb.co/6YxYL4n/od-print-1-edited.png), but by using the browser it doesn't work.

Hi @carloswbarros , I'd like to do an experiment and see if it resolves your issues. Can you use the permissions API to find all of the links currently associated with the item:

GET https://graph.microsoft.com/v1.0/me/drive/items/01CFGODSUNRIQ5P2BMDFGJVMQTKTPUSUQJ/permissions?filter=link%20ne%20null

Get the ids associated with the link you were trying to create (e.g. organization-edit, etc), and then make delete calls to remove them:

DELETE https://graph.microsoft.com/v1.0/me/drive/items/01CFGODSUNRIQ5P2BMDFGJVMQTKTPUSUQJ/permissions/d9d5bd57-fdb4-44cd-a9b0-a308a0e4f60c

After the DELETE, if you query for permissions again do you still see links? If so, repeat the process until they no longer come back.

Once the links are deleted, if you run your createLink request again does the returned link work?

Thank you for your contribution to OneDrive API Docs. We will be triaging your incoming issue as soon as possible.

I made this request (for the first time) and got this:

GET https://graph.microsoft.com/v1.0/me/drive/items/01CFGODSUNRIQ5P2BMDFGJVMQTKTPUSUQJ/permissions?filter=link%20ne%20null

Response:

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('7398509f-7fe1-4abc-b3f2-577aad047713')/drive/items('01CFGODSUNRIQ5P2BMDFGJVMQTKTPUSUQJ')/permissions",
    "value": []
}

Response Headers:

Cache-Control →private
Content-Encoding →gzip
Content-Type →application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8
Date →Thu, 09 May 2019 13:15:32 GMT
Duration →521.6312
OData-Version →4.0
Strict-Transport-Security →max-age=31536000
Transfer-Encoding →chunked
Vary →Accept-Encoding
client-request-id →7b06ca4a-a4d3-45eb-a90a-1e2a3b012322
request-id →7b06ca4a-a4d3-45eb-a90a-1e2a3b012322
x-ms-ags-diagnostic →{"ServerInfo":{"DataCenter":"North Europe","Slice":"SliceC","Ring":"3","ScaleUnit":"003","RoleInstance":"AGSFE_IN_40","ADSiteName":"NEU"}}

I don't think the createLink API it's working, I requested again the createLink and returned an invalid link and requested again this API and got this result empty values result.

I also changed the ItemId of this request for one folder that has working shared links and it returned all the links.

Strange, thanks @carloswbarros. While I see if anything stands out with the query you detailed above, can you try the GET ../permissions request against the troublesome item without the filter?

https://graph.microsoft.com/v1.0/me/drive/items/01CFGODSUNRIQ5P2BMDFGJVMQTKTPUSUQJ/permissions

What does it return? Anything that looks like the link that createLink returns?

@ificator, I made the request and I didn't get any links, only users:

I removed the emails and names for privacy.

Click me to open the response (big json)

**Response:**

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('7398509f-7fe1-4abc-b3f2-577aad047713')/drive/items('01CFGODSUNRIQ5P2BMDFGJVMQTKTPUSUQJ')/permissions",
    "value": [
        {
            "id": "id1",
            "roles": [
                "write"
            ],
            "grantedTo": {
                "user": {
                    "email": "<email-here-hidden>",
                    "id": "0f4235d3-e3c8-4931-a608-4cb7744c6e1c",
                    "displayName": "<Name-here-hidden>"
                }
            }
        },
        {
            "id": "id2",
            "roles": [
                "write"
            ],
            "grantedTo": {
                "user": {
                    "email": "<email-here-hidden>",
                    "id": "3916de4a-80d1-4d32-b0b5-02779fadb5a7",
                    "displayName": "<Name-here-hidden>"
                }
            }
        },
        {
            "id": "id3",
            "roles": [
                "write"
            ],
            "grantedTo": {
                "user": {
                    "email": "<email-here-hidden>",
                    "id": "1c3a6d89-51e2-4767-b424-91833ce09361",
                    "displayName": "<Name-here-hidden>"
                }
            }
        },
        {
            "id": "id4",
            "roles": [
                "write"
            ],
            "grantedTo": {
                "user": {
                    "email": "<email-here-hidden>",
                    "id": "d5d7af78-fd8d-41e4-bdfa-00bb35a3a9e4",
                    "displayName": "<Name-here-hidden>"
                }
            }
        },
        {
            "id": "id5",
            "roles": [
                "write"
            ],
            "grantedTo": {
                "user": {
                    "email": "<email-here-hidden>",
                    "id": "63bbfcf6-71ee-4ce3-ac7b-00586682e8d7",
                    "displayName": "<Name-here-hidden>"
                }
            }
        },
        {
            "id": "id6",
            "roles": [
                "write"
            ],
            "grantedTo": {
                "user": {
                    "email": "<email-here-hidden>",
                    "id": "43e3d5a0-071f-4904-aabf-4e43bf452734",
                    "displayName": "<Name-here-hidden>"
                }
            }
        },
        {
            "id": "id7",
            "roles": [
                "write"
            ],
            "grantedTo": {
                "user": {
                    "email": "<email-here-hidden>",
                    "id": "59ba3ea8-7d0b-4453-a6ca-da2087639eef",
                    "displayName": "<Name-here-hidden>"
                }
            }
        },
        {
            "id": "id8",
            "roles": [
                "write"
            ],
            "grantedTo": {
                "user": {
                    "email": "<email-here-hidden>",
                    "id": "2d4808f4-256b-4a67-8de5-2ad8d30d205a",
                    "displayName": "<Name-here-hidden>"
                }
            }
        },
        {
            "id": "id9",
            "roles": [
                "write"
            ],
            "grantedTo": {
                "user": {
                    "email": "<email-here-hidden>",
                    "id": "35c85854-0b96-4076-add7-16d7efd7beca",
                    "displayName": "<Name-here-hidden>"
                }
            }
        },
        {
            "id": "id10",
            "roles": [
                "write"
            ],
            "grantedTo": {
                "user": {
                    "email": "<email-here-hidden>",
                    "id": "f95f9a4d-54dc-47d6-ac90-b1ac713354ee",
                    "displayName": "<Name-here-hidden>"
                }
            }
        },
        {
            "id": "id11",
            "roles": [
                "write"
            ],
            "grantedTo": {
                "user": {
                    "email": "<email-here-hidden>",
                    "id": "4768b585-8767-455b-84d6-b0afe33df356",
                    "displayName": "<Name-here-hidden>"
                }
            }
        },
        {
            "id": "id12",
            "roles": [
                "write"
            ],
            "grantedTo": {
                "user": {
                    "email": "<email-here-hidden>",
                    "id": "f82e0036-02d5-448e-9d14-ef76ca028039",
                    "displayName": "<Name-here-hidden>"
                }
            }
        },
        {
            "id": "id13",
            "roles": [
                "write"
            ],
            "grantedTo": {
                "user": {
                    "email": "<email-here-hidden>",
                    "id": "3f8fb9b4-6903-4d55-8f52-6f67fd59c36e",
                    "displayName": "<Name-here-hidden>"
                }
            }
        },
        {
            "id": "id14",
            "roles": [
                "write"
            ],
            "grantedTo": {
                "user": {
                    "email": "<email-here-hidden>",
                    "id": "7b695ac6-b5b5-4ccc-afb8-493e82ed9371",
                    "displayName": "<Name-here-hidden>"
                }
            }
        },
        {
            "id": "id15",
            "roles": [
                "write"
            ],
            "grantedTo": {
                "user": {
                    "email": "<email-here-hidden>",
                    "id": "5c50d8cd-14e9-4f26-a045-72122c1d10ab",
                    "displayName": "<Name-here-hidden>"
                }
            }
        },
        {
            "id": "id16",
            "roles": [
                "write"
            ],
            "grantedTo": {
                "user": {
                    "email": "<email-here-hidden>",
                    "id": "616e91cc-7aec-4be8-98ee-549465544b43",
                    "displayName": "<Name-here-hidden>"
                }
            }
        },
        {
            "id": "id17",
            "roles": [
                "write"
            ],
            "grantedTo": {
                "user": {
                    "email": "<email-here-hidden>",
                    "id": "d249e84a-dda6-4756-909a-aa412fa57161",
                    "displayName": "<Name-here-hidden>"
                }
            }
        },
        {
            "id": "id18",
            "roles": [
                "write"
            ],
            "grantedTo": {
                "user": {
                    "email": "<email-here-hidden>",
                    "id": "7193145f-2788-4571-9842-271e30c6e7d5",
                    "displayName": "<Name-here-hidden>"
                }
            }
        },
        {
            "id": "id19",
            "roles": [
                "write"
            ],
            "grantedTo": {
                "user": {
                    "email": "<email-here-hidden>",
                    "id": "f4a4383b-d12e-489b-a678-df6d0c7a6b4d",
                    "displayName": "<Name-here-hidden>"
                }
            }
        },
        {
            "id": "id20",
            "roles": [
                "write"
            ],
            "grantedTo": {
                "user": {
                    "email": "<email-here-hidden>",
                    "id": "668a7243-39e4-4980-a5e8-52f4654edc7b",
                    "displayName": "<Name-here-hidden>"
                }
            }
        },
        {
            "id": "id21",
            "roles": [
                "write"
            ],
            "grantedTo": {
                "user": {
                    "email": "<email-here-hidden>",
                    "id": "1042a0b0-0fb6-4017-881e-13831e1e36ce",
                    "displayName": "<Name-here-hidden>"
                }
            }
        },
        {
            "id": "id22",
            "roles": [
                "write"
            ],
            "grantedTo": {
                "user": {
                    "email": "<email-here-hidden>",
                    "id": "928ec21b-db6c-4101-af1f-e1c354a45494",
                    "displayName": "<Name-here-hidden>"
                }
            }
        },
        {
            "id": "id23",
            "roles": [
                "write"
            ],
            "grantedTo": {
                "user": {
                    "email": "<email-here-hidden>",
                    "id": "4d0d2344-8bae-4f1a-aa78-ccce6d01b6dd",
                    "displayName": "<Name-here-hidden>"
                }
            }
        },
        {
            "id": "id24",
            "roles": [
                "write"
            ],
            "grantedTo": {
                "user": {
                    "email": "<email-here-hidden>",
                    "id": "6387f061-f260-418e-9eec-60dcd683e85c",
                    "displayName": "<Name-here-hidden>"
                }
            }
        },
        {
            "id": "id25",
            "roles": [
                "write"
            ],
            "grantedTo": {
                "user": {
                    "email": "<email-here-hidden>",
                    "id": "231252b0-2c71-4f55-ab1b-f206e9d03534",
                    "displayName": "<Name-here-hidden>"
                }
            }
        },
        {
            "id": "id26",
            "roles": [
                "write"
            ],
            "grantedTo": {
                "user": {
                    "email": "<email-here-hidden>",
                    "id": "207c2f9c-e5c3-4fd1-a8dd-cec2e3770cc0",
                    "displayName": "<Name-here-hidden>"
                }
            }
        },
        {
            "id": "id27",
            "roles": [
                "write"
            ],
            "grantedTo": {
                "user": {
                    "email": "<email-here-hidden>",
                    "id": "8af6ca94-a3b7-4a25-a772-4c98606d7e98",
                    "displayName": "<Name-here-hidden>"
                }
            }
        },
        {
            "id": "id28",
            "roles": [
                "write"
            ],
            "grantedTo": {
                "user": {
                    "email": "<email-here-hidden>",
                    "id": "f034f720-8308-46a0-9b8c-225b2d7c1aa6",
                    "displayName": "<Name-here-hidden>"
                }
            }
        },
        {
            "id": "id29",
            "roles": [
                "write"
            ],
            "grantedTo": {
                "user": {
                    "email": "<email-here-hidden>",
                    "id": "c5f92d1f-80a5-48ed-a331-06c8ee4d88c4",
                    "displayName": "<Name-here-hidden>"
                }
            }
        },
        {
            "id": "id30",
            "roles": [
                "owner"
            ],
            "grantedTo": {
                "user": {
                    "email": "<email-here-hidden>",
                    "id": "7398509f-7fe1-4abc-b3f2-577aad047713",
                    "displayName": "<Name-here-hidden>"
                }
            }
        }
    ]
}
**Response Headers:**
Cache-Control ?private
Content-Encoding ?gzip
Content-Type ?application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8
Date ?Thu, 09 May 2019 16:57:58 GMT
Duration ?546.0601
OData-Version ?4.0
Strict-Transport-Security ?max-age=31536000
Transfer-Encoding ?chunked
Vary ?Accept-Encoding
client-request-id ?1bdda7d6-cc7b-45ee-9347-09d14959c826
request-id ?1bdda7d6-cc7b-45ee-9347-09d14959c826
x-ms-ags-diagnostic ?{"ServerInfo":{"DataCenter":"North Europe","Slice":"SliceC","Ring":"3","ScaleUnit":"002","RoleInstance":"AGSFE_IN_26","ADSiteName":"NEU"}}

I appreciate your patience while we figure this out @carloswbarros.

It's strange that the link isn't returned as part of the /permisisons request. Here's something else we can try:

  1. Execute the createLink call again. Does it return a 200 or a 201?
  2. Get the id value from the response
  3. Call DELETE https://graph.microsoft.com/v1.0/me/drive/items/01CFGODSUNRIQ5P2BMDFGJVMQTKTPUSUQJ/permissions/id (where id is replaced with the GUID from the createLink response).
  4. Call createLink again. If it returns a 200 go to step 2 as that means it's using an existing link, and we want to make sure it's creating a new one.

@ificator,

The createLink returned 200 status code.

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#permission",
    "@odata.type": "#microsoft.graph.permission",
    "id": "f29249bb-616f-4522-a1c8-84c751e20fbb",
    "roles": [
        "write"
    ],
    "link": {
        "scope": "organization",
        "type": "edit",
        "webUrl": "https://spa******-my.sharepoint.com/:f:/g/personal/fileserver_******_fr/Eo2KIdfoLBlMmrITVN9JUgkBrsp2N8CfXc2MPPLYzGoBIg"
    }
}

I called DELETE https://graph.microsoft.com/v1.0/me/drive/items/01CFGODSUNRIQ5P2BMDFGJVMQTKTPUSUQJ/permissions/f29249bb-616f-4522-a1c8-84c751e20fbb with the id returned from createLink and got this response with the status code 404:

{
    "error": {
        "code": "itemNotFound",
        "message": "The resource could not be found.",
        "innerError": {
            "request-id": "f2e609f3-e881-4fb9-8950-0069befb68f5",
            "date": "2019-05-10T08:02:12"
        }
    }
}

I repeated the process but got no luck, it's always returning the same invalid shared link.

Thanks for all the details @carloswbarros, while I'm still not sure what's going on it's fairly safe to say it's a bug. With the data you provided hopefully we can get to the bottom of it soon.

Is there any updates on this? When can we expect this issue to be resolved?

Apologies for the delay, we are available to look into this bug. Are you still running into this issue?
If so could you call /createLink again and provide us with the date and time of the request, as well as the client-request-id so we can grab logs to get to the bottom of why this is occuring

Cheers

@k-tsoi thanks for taking an interest in this. Yes we still have this bug.

I made the following request:

Request

**Request**

POST https://graph.microsoft.com/v1.0/me/drive/items/01CFGODSUNRIQ5P2BMDFGJVMQTKTPUSUQJ/createLink

Authorization: Bearer eyJ0eXAiOiJKV1Qi....

Content-Type: application/json

And got this response:

Date: Mon, 22 Jul 2019 07:57:07 GMT
request-id: 6d0d79d6-f7db-4f61-8b40-814e8df38bc8

Full Response Body & Headers

**Response Body**

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#permission",
    "@odata.type": "#microsoft.graph.permission",
    "id": "f29249bb-616f-4522-a1c8-84c751e20fbb",
    "roles": [
        "write"
    ],
    "link": {
        "scope": "organization",
        "type": "edit",
        "webUrl": "https://*********-my.sharepoint.com/:f:/g/personal/******_fr/Eo2KIdfoLBlMmrITVN9JUgkBrsp2N8CfXc2MPPLYzGoBIg"
    }
}
**Response Headers:**
Cache-Control →private
Content-Encoding →gzip
Content-Type →application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8
Date →Mon, 22 Jul 2019 07:57:07 GMT
Duration →936.8338
Location →https://graph.microsoft.com
OData-Version →4.0
Strict-Transport-Security →max-age=31536000
Transfer-Encoding →chunked
Vary →Accept-Encoding
client-request-id →6d0d79d6-f7db-4f61-8b40-814e8df38bc8
request-id →6d0d79d6-f7db-4f61-8b40-814e8df38bc8
x-ms-ags-diagnostic →{"ServerInfo":{"DataCenter":"North Europe","Slice":"SliceC","Ring":"3","ScaleUnit":"002","RoleInstance":"AGSFE_IN_26","ADSiteName":"NEU"}}

And the 'webUrl' is always the same.

I spoke to the partner team that works in this area. They were able to shed some light as to why this issue could have occurred.

It seems this issue occurs when multiple createLink calls are made within a few milliseconds of one another. There is a race condition that leads to multiple sharingLinks being created, only the most recent share is effective on the ACL (Access Control List). However, only one of the created shares can be returned in the API. Unfortunately, in your case, the sharingLink that is return is one that does not work.

The team owning this area has been notified of this issue but cannot give an ETA for the fix.

In future to prevent this from occurring, ensure calls to createLink are not run multiple times within a short period of time, createLink does not support running multiple calls in parallel.

The only thing that can be done to fix your issue, would be to delete the broken sharingLink. Unfortunately, as this is the first time encountering this issue, there is no mechanism on our end that can help clean out all the broken sharingLinks on the item for you.
You could try delete the sharingLink from the UI. If this does not work, the next thing to try would be to copy the folder and its’ content and delete the original folder. From there you can start creating sharingLinks afresh.

Was this page helpful?
0 / 5 - 0 ratings