Generate anonymous access link to a file using REST API

How to Generate anonymous access link to a file using REST API

<script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        test();
    });


function test()
{
  var ctx = SP.ClientContext.get_current();

      var url = _spPageContextInfo.webAbsoluteUrl + "/_api/SP.Web.CreateAnonymousLink";
         
          $.ajax({
              'url': url,
              'method': 'POST',
              'data': JSON.stringify({
                 'url': _spPageContextInfo.webAbsoluteUrl + '/Migrated%20Lib/Software.docx',
                 '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(JSON.stringify(err));
               }
          });
         }

</script>


Comments

Popular posts from this blog

How to Customize exported excel's cell background color in Datatables

Clear DataTable on button click

Upload multiple attachments to SharePoint List Item using REST API jQuery, along with People Picker Column