Dec 10 2016 07:20 AM
I've been searching for an opportunity to get files and folders guestaccess URL using REST api in Sharepoint Online
Is there a way to get it using RESTapi or JSOM?
I found an example authored by @Vesa Juvonen, where it done using CSOM:
https://github.com/SharePoint/PnP/tree/master/Samples/Core.ExternalSharing/Core.ExternalSharingWeb
There's a notice that similar API is available through REST also, but there not much documentation for this... :S
Any advice on this subject would be super :)
Dec 10 2016 08:25 AM - edited Dec 10 2016 08:43 AM
SolutionHi Mihkel,
It's possible with the following web's methods:
- CreateAnonymousLink
- CreateAnonymousLinkWithExpiration
Some valuable details can be read here in Steve Curran's blog post.
Methods are available in REST API POST calls. Below is an example calling `CreateAnonymousLink` method with jQuery:
var methodUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/SP.Web.CreateAnonymousLink"; var documentUrl = spPageContextInfo.webAbsoluteUrl + '/DocumentLib/DocumentName.docx'; $.ajax({ 'url': methodUrl, 'method': 'POST', 'data': JSON.stringify({ 'url': documentUrl, 'isEditLink': true }), 'headers': { 'accept': 'application/json;odata=verbose', 'content-type': 'application/json;odata=verbose', 'X-RequestDigest': $('#__REQUESTDIGEST').val() }, 'success': function(data) { console.log(data.d.CreateAnonymousLink); }, 'error': function(err) { console.log(err); } });
Dec 13 2016 01:38 AM
Thanks alot @Andrew Koltyakov!
That is exactly what I was looking for. Super!
Although I found these web method before, but I was assuming these are for creating these links. I did not expect these to return me existing links also.
Thanks again! :)
Dec 28 2018 07:34 AM
Hi @Mihkel Moorats! Did you ever get this working for you? I cannot seem to...
See my response here: https://techcommunity.microsoft.com/t5/SharePoint-Developer/Creating-anonymous-access-links-through-...
And someone else with a similar problem: https://stackoverflow.com/questions/50325403/create-a-sharepoint-anonymous-link-using-rest-api
Dec 29 2018 12:11 AM
Hy Tracy,
Yes I got it working just fine. Although the suggested way to use "getShareLink" also created the link.
In my latest project I found best solution to use PnP-JS:
https://github.com/SharePoint/PnP-JS-Core/wiki/Working-With:-Sharing#getsharinginformation
"getSharingInformation" is the one that returns sharing info. But you need to use POST method instead of GET.
I hope you find my answer useful :)
Mihkel
Dec 10 2016 08:25 AM - edited Dec 10 2016 08:43 AM
SolutionHi Mihkel,
It's possible with the following web's methods:
- CreateAnonymousLink
- CreateAnonymousLinkWithExpiration
Some valuable details can be read here in Steve Curran's blog post.
Methods are available in REST API POST calls. Below is an example calling `CreateAnonymousLink` method with jQuery:
var methodUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/SP.Web.CreateAnonymousLink"; var documentUrl = spPageContextInfo.webAbsoluteUrl + '/DocumentLib/DocumentName.docx'; $.ajax({ 'url': methodUrl, 'method': 'POST', 'data': JSON.stringify({ 'url': documentUrl, 'isEditLink': true }), 'headers': { 'accept': 'application/json;odata=verbose', 'content-type': 'application/json;odata=verbose', 'X-RequestDigest': $('#__REQUESTDIGEST').val() }, 'success': function(data) { console.log(data.d.CreateAnonymousLink); }, 'error': function(err) { console.log(err); } });