Delete users via REST-API?


#1

Hi,
is it possible to delete a user via the REST API?

Regards,

Robert


#2

There are a few ways to do this. Let’s say you want to delete the users with ids 10 and 11. First off, you have to be an admin user or a user with a role that grants permission to delete other users.

You can make a separate call for each.

DELETE /rest/system/user/10
DELETE /rest/system/user/11

or

DELETE /rest/system/user?ids=10
DELETE /rest/system/user?ids=11

You can delete both at once.

DELETE /rest/system/user?ids=10,11

You can also delete using a filter string.

DELETE /rest/system/user?filter=id=10 or id=11

I would advise you to escape the filterstring like this if possible.

filter=id%3D10%20or20id%3D11

You can also pass the ids or filter as data in the delete request.

data = JSON.stringify({"ids": "10,11"});
data = JSON.stringify({"ids": [10,11]);
data = JSON.stringify({"record":[{"id": 10},{"id": 11}]});

There are other variants of this but these are the common ones. The database may return an error if that user is is referenced somewhere else, like in records created by that user (created_by_id field). Just something to be aware of.


#3

Thanks for your help!

Is it possible to give the user only the permission to just delete his own user?

Regards,

Robert


#4

The way the system is designed it’s not possible to delete or change the active status of your own user.