1

My google searches have all led to dead ends.

Is there a way to retrieve the durable link code for a document using the REST API?

When you copy a link in the GUI, it takes the form of:-

https://mysite.sharepoint.com/sites/mysite/mylibrary/myDocSet?d=w9570bf1d91a541679abbf03996bbbff7

I would like to know how to retrieve the d=.... part, using the SharePoint REST API, given I have the ID of the library item (e.g 847) and the library location details etc.

1 Answer 1

0

It is present in the LinkingUrl property of the file in a document library.

So, to get that value, you need to modify the endpoint as below:

https://mysite.sharepoint.com/sites/mysite/_api/web/lists/getbytitle('mylibrary')/items(847)
?$select=File/LinkingUrl&$expand=File

Reference - SP Durable links

7
  • I had seen that page, however I couldn't resolve how to apply it to an endpoint.
    – user77766
    Commented Sep 6, 2018 at 14:32
  • I get a response from the server, however it does not appear to contain the required field. (It does not contain a value that matches the string obtainable from the SP GUI for the same Document Set in the same Document Library) Nor does it contain a node 'LinkingURL'. Any other hints to what I might be doing wrong?
    – user77766
    Commented Sep 6, 2018 at 14:36
  • The above code works for Files. To make it work for folder or document sets, you can use https://mysite.sharepoint.com/sites/mysite/_api/web/lists/getbytitle('mylibrary')/_api/web/lists/getbytitle('Documents')/items(32)?$select=*,Folder/UniqueId&$expand=Folder. It will give you the uniqueId property of the document set which will be the value you can use for d=... section ! Commented Sep 6, 2018 at 14:48
  • That's great - thank you. The REST API is now returning a <d:UniqueId> node, with a value similar to the GUI's. Is it safe to assume that I should always pre-pend a w, and strip out the dashes (-) to arrive at the same link the GUI would supply?
    – user77766
    Commented Sep 6, 2018 at 15:35
  • Also, BTW, I believe there was a surplus /_api/web/lists/getbytitle('Documents') in the URI you posted in your comment, above - I ended up using https://mysite.sharepoint.com/sites/mysite/_api/web/lists/getbytitle('mylibrary')/items(32)?$select=*,Folder/UniqueId&$expand=Folder
    – user77766
    Commented Sep 6, 2018 at 15:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.