SOLVED

How to get guestaccess URL of on item/file?

%3CLINGO-SUB%20id%3D%22lingo-sub-34962%22%20slang%3D%22en-US%22%3EHow%20to%20get%20guestaccess%20URL%20of%20on%20item%2Ffile%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-34962%22%20slang%3D%22en-US%22%3E%3CP%3EI've%20been%20searching%20for%20an%20opportunity%20to%20get%20files%20and%20folders%20guestaccess%20URL%20using%20REST%20api%20in%20Sharepoint%20Online%3CBR%20%2F%3EIs%20there%20a%20way%20to%20get%20it%20using%20RESTapi%20or%20JSOM%3F%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3EI%20found%20an%26nbsp%3Bexample%20authored%20by%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F369%22%20target%3D%22_blank%22%3E%40Vesa%20Juvonen%3C%2FA%3E%2C%20where%20it%20done%26nbsp%3Busing%20CSOM%3A%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FSharePoint%2FPnP%2Ftree%2Fmaster%2FSamples%2FCore.ExternalSharing%2FCore.ExternalSharingWeb%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2FSharePoint%2FPnP%2Ftree%2Fmaster%2FSamples%2FCore.ExternalSharing%2FCore.ExternalSharingWeb%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThere's%20a%20notice%20that%20similar%20API%20is%20available%20through%20REST%20also%2C%20but%20there%20not%20much%20documentation%20for%20this...%20%3AS%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%3EAny%20advice%20on%20this%20subject%20would%20be%20super%20%3A)%3C%2Fimg%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-34962%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-307405%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20get%20guestaccess%20URL%20of%20on%20item%2Ffile%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-307405%22%20slang%3D%22en-US%22%3E%3CP%3EHy%20Tracy%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYes%20I%20got%20it%20working%20just%20fine.%20Although%20the%20suggested%20way%20to%20use%20%22getShareLink%22%20also%20created%20the%20link.%3C%2FP%3E%3CP%3EIn%20my%20latest%20project%20I%20found%20best%20solution%20to%20use%20PnP-JS%3A%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FSharePoint%2FPnP-JS-Core%2Fwiki%2FWorking-With%3A-Sharing%23getsharinginformation%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2FSharePoint%2FPnP-JS-Core%2Fwiki%2FWorking-With%3A-Sharing%23getsharinginformation%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%22getSharingInformation%22%20is%20the%20one%20that%26nbsp%3Breturns%20sharing%20info.%20But%20you%20need%20to%20use%20POST%20method%20instead%20of%20GET.%3CBR%20%2F%3E%3CBR%20%2F%3EI%20hope%20you%20find%20my%20answer%20useful%20%3A)%3C%2Fimg%3E%3CBR%20%2F%3E%3CBR%20%2F%3EMihkel%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-307251%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20get%20guestaccess%20URL%20of%20on%20item%2Ffile%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-307251%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F32105%22%20target%3D%22_blank%22%3E%40Mihkel%20Moorats%3C%2FA%3E!%26nbsp%3B%20Did%20you%20ever%20get%20this%20working%20for%20you%3F%26nbsp%3B%20I%20cannot%20seem%20to...%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESee%20my%20response%20here%3A%26nbsp%3B%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2FSharePoint-Developer%2FCreating-anonymous-access-links-through-REST-API%2Fm-p%2F145937%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2FSharePoint-Developer%2FCreating-anonymous-access-links-through-REST-API%2Fm-p%2F145937%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnd%20someone%20else%20with%20a%20similar%20problem%3A%26nbsp%3B%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fstackoverflow.com%2Fquestions%2F50325403%2Fcreate-a-sharepoint-anonymous-link-using-rest-api%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fstackoverflow.com%2Fquestions%2F50325403%2Fcreate-a-sharepoint-anonymous-link-using-rest-api%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-35301%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20get%20guestaccess%20URL%20of%20on%20item%2Ffile%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-35301%22%20slang%3D%22en-US%22%3E%3CP%3EThanks%20alot%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F29128%22%20target%3D%22_blank%22%3E%40Andrew%20Koltyakov%3C%2FA%3E!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThat%20is%20exactly%20what%20I%20was%20looking%20for.%20Super!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAlthough%20I%20found%20these%20web%20method%20before%2C%20but%20I%20was%20assuming%20these%20are%20for%20creating%20these%20links.%26nbsp%3BI%20did%20not%20expect%20these%20to%20return%20me%20existing%20links%20also.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20again!%20%3A)%3C%2Fimg%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-34964%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20get%20guestaccess%20URL%20of%20on%20item%2Ffile%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-34964%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Mihkel%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt's%20possible%20with%20the%20following%20web's%20methods%3A%3C%2FP%3E%3CP%3E-%20CreateAnonymousLink%3C%2FP%3E%3CP%3E-%20CreateAnonymousLinkWithExpiration%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESome%20valuable%20details%20can%20be%20read%20%3CA%20href%3D%22http%3A%2F%2Fsharepointfieldnotes.blogspot.ru%2F2016%2F01%2Fwhats-new-in-sharepoint-2016-remote-api_28.html%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehere%3C%2FA%3E%26nbsp%3Bin%20Steve%20Curran's%20blog%20post.%3C%2FP%3E%3CP%3EMethods%20are%20available%20in%20REST%20API%20POST%20calls.%20Below%20is%20an%20example%20calling%20%60%3CSPAN%3ECreateAnonymousLink%3C%2FSPAN%3E%60%20method%20with%20jQuery%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3Evar%20methodUrl%20%3D%20_spPageContextInfo.webAbsoluteUrl%20%2B%20%22%2F_api%2FSP.Web.CreateAnonymousLink%22%3B%0Avar%20documentUrl%20%3D%20spPageContextInfo.webAbsoluteUrl%20%2B%20'%2FDocumentLib%2FDocumentName.docx'%3B%0A%0A%24.ajax(%7B%0A%20%20%20%20'url'%3A%20methodUrl%2C%0A%20%20%20%20'method'%3A%20'POST'%2C%0A%20%20%20%20'data'%3A%20JSON.stringify(%7B%0A%20%20%20%20%20%20%20%20'url'%3A%20documentUrl%2C%0A%20%20%20%20%20%20%20%20'isEditLink'%3A%20true%0A%20%20%20%20%7D)%2C%0A%20%20%20%20'headers'%3A%20%7B%0A%20%20%20%20%20%20%20%20'accept'%3A%20'application%2Fjson%3Bodata%3Dverbose'%2C%0A%20%20%20%20%20%20%20%20'content-type'%3A%20'application%2Fjson%3Bodata%3Dverbose'%2C%0A%20%20%20%20%20%20%20%20'X-RequestDigest'%3A%20%24('%23__REQUESTDIGEST').val()%0A%20%20%20%20%7D%2C%0A%20%20%20%20'success'%3A%20function(data)%20%7B%0A%20%20%20%20%20%20%20%20console.log(data.d.CreateAnonymousLink)%3B%0A%20%20%20%20%7D%2C%0A%20%20%20%20'error'%3A%20function(err)%20%7B%0A%20%20%20%20%20%20%20%20console.log(err)%3B%0A%20%20%20%20%7D%0A%7D)%3B%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

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

4 Replies
Highlighted
Solution

Hi 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);
    }
});

 

Highlighted

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! :)

Highlighted
Highlighted

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