How to check user Permission in SharePoint 2013/ Office 365/SharePoint online using REST API’s

Hello SharePointers,

In this blog ,I m going to give script to check user permission in SharePoint 2013/ Office 365/SharePoint online using REST API’s

function getUserWebPermission() {
var hostweburl = decodeURIComponent(getQueryStringParameter(‘SPHostUrl’));
var appweburl = decodeURIComponent(getQueryStringParameter(“SPAppWebUrl”));
var url= appweburl + “/_api/web/doesuserhavepermissions”;

var perm = new SP.BasePermissions();
perm.set(SP.PermissionKind.editListItems);

$.ajax(
{
‘url’: url,
‘method’: ‘POST’,
‘data’: JSON.stringify({
‘permissionMask’: {
‘__metadata’: {
‘type’: ‘SP.BasePermissions’
},
‘High’: perm.$4_1.toString(),
‘Low’: perm.$5_1.toString()
}
}),
‘headers’: {
‘accept’: ‘application/json;odata=verbose’,
‘content-type’: ‘application/json;odata=verbose’,
‘X-RequestDigest’: $(‘#__REQUESTDIGEST’).val()
},
‘success’: function (data) {
var d = data.d.DoesUserHavePermissions;
},
‘error’: function (err) {
alert(JSON.stringify(err));
}
}
);
}

Happy Sharepointing 🙂

Leave a Reply

Your email address will not be published.