How to delete user from _User through Parse REST API

1.5k Views Asked by At

I'm trying to delete one user from _User table of parse.com but I get an error.

I'm sure that the syntax of the request is fine, I'm getting this error:

code: 206
error: "Parse::UserCannotBeAlteredWithoutSessionError"

I think I shouldn't to do log-in to delete users, because I'm doing it on API REST.

$scope.delete = function (id) {
  $http({
     method: "DELETE",
     url: url_users + id,
     headers: {'X-Parse-Application-Id': appId,
               'X-Parse-REST-API-Key': restId}

  }).success(function (data) {
     debugger;
     swal("Deleted!", "All user data has been deleted", "success");
  }).error(function (data) {
    debugger;
     swal("Error!", "An unexpected error ocurred, try again!", "error");
  });
}
2

There are 2 best solutions below

0
On

I haven't tried doing this, but I have these ideas:

  • Make sure your ACL allows this to the public
  • Is it not acceptable to call a cloud code function? This would feel more intuitive to me than using the API in this case. Can you explain why you must use the REST API?
  • If that doesn't work, look at this answer: https://www.parse.com/questions/delete-a-user-rest-api

Basically you might have to pass the Master Key header, which is less than ideal to expose to the public. Is it not accep

1
On

You're trying to remove a user from a different user session to remove. This does not work from the REST API, even if you use the X-Parse-REST-API-Key in the headers. The solution is to use Clode Code Function to delete or update a user from another session.

For more information see the documentation Parse Cloud Code Guide

The following response is the Code Clode Function to delete a user:

Parse User Destroy - Javascript in Cloud Code