restore deleted user

Hello! I made a REST API call to DELETE a user and the deletion was successful.

1) Is there a way to undelete or restore the deleted user?

2) Are there any time limits before which the deleted user has to be restored?

3) If undelete is not possible, is there a way to transfer the user's data (like leads, opportunities, etc.,) to some other user or an Admin?

I tried making a POST call sending the same details of a deleted user (like id, user_name, first and last_names), but it resulted in an HTTP 500 status. The response payload read something like 'Database failure. Please refer to sugarcrm.log for details.' Is this expected or a bug?

Parents
  • Hello,

    If you have deleted Users using the REST API then you can restore it. Basically when you delete any record using REST API or SugarCRM interface it will not delete record from the database. It just mark deleted flag to true. 

    So, to restore your deleted record go to the users table of CRM database and updated value in the deleted field to '0' for desired user record.

    As SugarCRM do not delete record permanently you can restore it at any time there is no time limit to restore.

    Regarding the error with code 500, please check your php log. there might be some error in execution.

    Hope this will helps you!

    Thanks

  • Hi admin guy,

    I'm not sure wether the standard SugarCRM REST API v10 lets you update the "deleted" field of any record, as I think that when you try to 'GET' the user for instance by ID, the API would through a 404 error or something like this, indicating that the user hasn't been found in the system.

    However, you could create your custom endpoint, receiving as a parameter for instance the username (or the user ID, as desired), and then performing an SQL query in order to look for the given user in the database, and then UPDATE it using again an SQL query.

    Knowing that, you can create your custom endpoint and then perform an SQL query (SELECT) to fetch the user in the database, and then if found perform the UPDATE query in order to bring it back to life... something like:

    UPDATE users SET deleted = 0 WHERE user_name = "jon.doe"

    You also must take into account that if you've got enabled for your instance the Prune Database on 1st Month  scheduler, then your users will be always deleted on 1st of every month and then you won't be able to restore them.

    Hope this helps.

    Regards,

    David.

  • Thanks David. So we confirm that there's no in-built REST endpoint to restore a deleted user because of the fact that GET the record by ID will be a 404.

    Also, we don't want to create any custom endpoints, as it involves building the endpoint and interacting with Databases ourselves. We expect the SugarCRM as a Service Provider to expose that feature. I also believe that creating a custom endpoint will enable it only for that SugarCRM instance and not for all customers who have SugarCRM.

Reply
  • Thanks David. So we confirm that there's no in-built REST endpoint to restore a deleted user because of the fact that GET the record by ID will be a 404.

    Also, we don't want to create any custom endpoints, as it involves building the endpoint and interacting with Databases ourselves. We expect the SugarCRM as a Service Provider to expose that feature. I also believe that creating a custom endpoint will enable it only for that SugarCRM instance and not for all customers who have SugarCRM.

Children
  • So yes, I checked it and I guess there are no in-built REST endpoints to restore a deleted user.

    I don't know if SugarCRM is planning to create their own one, probably not because as I see it, the SugarCRM REST API provides a great variety of endpoints which allow you to perform the same actions that you can perform though the Sugar UI. This is retrieve data, create records, delete and update... so maybe this is the reason why there are no in-built REST endpoints to perform this task. You just can't restore a deleted user through the UI.

    So if you want to accomplish this task, you should create it yourself, os ask anyone else to do it for you. There's also one advantage: if you create this endpoint and make it generic, you could create an installable package that you can install in several SugarCRM instances and use the endpoint in any of them.

    Regards,

    David.