I am making a custom "Delete item" button for my list. The issue I am facing is that when the user attempting to delete the item does not have the permission to do so, besides the API failing, I think the server responds with a 401 unauthorized or the response header contains WWW-Authenticate which makes the browser display an authentication prompt besides my custom error handler. My question is, how do I supress that prompt without doing any server-side changes?

Here is my example JavaScript code where I make the REST call:

    url: _spPageContextInfo.webServerRelativeUrl +
        "/_api/web/lists/getbytitle('" + listName + "')/items(" + id + ")/recycle()",
    type: "POST",
    headers: {
        "X-RequestDigest": $("#__REQUESTDIGEST").val(),
    xhrFields: { withCredentials: true },
    success: function(data) {
    error: function(error) {

Thank you very much.

1 Answer 1


I do not think you are going to be able to. The permissions check is going to come first and SharePoint is going to reject it through the page because the user is trying to do an action it is not allowed to do on the client. This for security, and is a page error obviously. I am not sure you are going to be able to get behind that with the asynchronous nature of REST. To get around it, you could hide the delete button based on the current users permission level. That is going to be your be bet in my opinion.

  • Yeah, I did that, specifically, I am checking the permissions the user has on the list and whether he/she created the item or not. If the user is an editor, it has free hand. If not, he/she is allowed to delete only if he/she created the item. It works for now, thanks for the tip. Commented Dec 10, 2019 at 18:33
  • No worries. Good luck to ya. Up vote if helpful :)
    – lazoDev
    Commented Dec 10, 2019 at 19:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.