Creating anonymous access links through REST API

Copper Contributor

Hi Guys,


I'm trying to generate an anonymous access link for a document (ideally looking to do for a list item too - as a separate point if anyone knows how).


I'm wanting to run this REST query in a Flow but at the moment i'm just testing in Postman locally.


Can't for the life of me get it working, I keep getting an 'Operation is not valid due to the current state of the object' error.


Anonymous sharing is enabled on the site etc.


This is the REST Query i'm using:


POST /sites/testsite/_api/SP.Web.CreateAnonymousLink HTTP/1.1

Authorization: Bearer
Content-Type: application/json
Accept: application/json;odata=verbose
X-RequestDigest: 0xF881520BE117765765358087E00A4FD6071E1A1E0C6EEBD79E6174B02FCC63A40E2D7891B009EB8FB08DABB99371ACA63DBDF272B2C1660E4DA3ADE847FD6AFD,17 Jan 2018 15:13:13 -0000
Cache-Control: no-cache
Postman-Token: c62b45ae-097e-5c63-a4ef-c5771030f61b

{'url': 'https://tenant/sites/site/Appointment Forms/Appointment form example.docx', 'isEditLink': true}


Originally I didn't have a Request digest - I did a POST to contextinfo and copied the value from here.


Is it just not supported outside of a SharePoint page??


Hoping someone can help shed some light!




1 Reply

I realize this is pretty old, but did you make any progress?  I am having a similar problem, just trying to get it running in Postman.  A query to the search api works fine in another Postman tab, using the same Bearer token.