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>
<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
Post a Comment