Search code examples
pythongoogle-appsgoogle-admin-sdkgoogle-api-python-client

Google Apps Admin SDK undelete doesn't work


I've tried using the APIs explorer and in my own python code, but it seems like undelete doesn't work in the API. I have an account in the list of "recently deleted" users in my Google Apps admin console, but no matter what I don in the APIs explorer it won't work. Here's a sample screenshot:

configuration

results

I believe it may have something to do with the orgUnitPath but I'm not sure. I've tried it with '/', '/myorg', and 'myorg' but none of them work. Not really sure what else to try at this point.


Solution

  • You must supply the numeric id attribute of the user for users.undelete() rather than the primary email address. The reason for this is you must deal with scenarios where two accounts with the same address have been created and then deleted in the past 5 days.

    Use users.list(showDeleted=true) to get a list of all accounts that have been deleted in the past 5 days and convert the email address into an id If the primary address isn't enough to go off of (again, 2+ accounts created with that same primary addresss in past 5 days) then you can also look at creationTime and lastLoginTime to determine which is the correct account to undelete.