How to delete an account?
cecco opened this issue · comments
Hi,
I'm trying to delete an account (I have successfully created one).
I'm using:
$api = \Zimbra\Admin\AdminFactory::instance('https:/xx.xx.xx.xx:7071/service/admin/soap');
$api->auth('admin@domain', 'password');
$account = new \Zimbra\Struct\AccountSelector(\Zimbra\Enum\AccountBy::NAME(), 'user@domain');
$api->deleteAccount($account);
I got in zimbra mailbox.log:
SoapEngine - handler exception com.zimbra.cs.account.AccountServiceException: no such account: <?xml version="1.0"?>
<account by="name">user@domain</account>
I understand deleteAccount need a user id, but how can i get it from api?
Thank you, your job is great!
Francesco
Hi Francesco,
For deleting account, you need a user zimbra id.
You can get it by getAccount method from api.
For example:
$api = \Zimbra\Admin\AdminFactory::instance('https:/xx.xx.xx.xx:7071/service/admin/soap');
$api->auth('admin@domain', 'password');
$account = new \Zimbra\Struct\AccountSelector(\Zimbra\Enum\AccountBy::NAME(), 'user@domain');
$accountInfo = $api->getAccount($account);
$api->deleteAccount($accountInfo->id);
Thank you for your reply. but i got errors if use your code:
PHP message: PHP Catchable fatal error: Argument 3 passed to Zimbra\Admin\Request\GetAccount::__construct() must be of the type array, null given, called in /usr/share/nginx/html/vendor/zimbra-api/soap-api/src/Zimbra/Admin/Base.php on line 1433 and defined in /usr/share/nginx/html/vendor/zimbra-api/soap-api/src/Zimbra/Admin/Request/GetAccount.php on line 38
If I change the second-last line to
$accountInfo = $api->getAccount($account,null,array());
I get:
PHP message: PHP Fatal error: Uncaught exception 'RuntimeException' with message 'Property id is not defined.' in /usr/share/nginx/html/vendor/zimbra-api/soap-api/src/Zimbra/Soap/Response.php:63 Stack trace: #0 /usr/share/nginx/html/test-zimbra.php(17): Zimbra\Soap\Response->__get('id') #1 {main} thrown in /usr/share/nginx/html/vendor/zimbra-api/soap-api/src/Zimbra/Soap/Response.php on line 63
Thank You
Hi Francesco,
All of api methods return an object corresponding to response xml of zimbra soap api.
So you can reference zimbra soap api document at https://files.zimbra.com/docs/soap_api/8.6.0/api-reference/index.html
This is example code i was tested successfully:
$api = \Zimbra\Admin\AdminFactory::instance('https:/xx.xx.xx.xx:7071/service/admin/soap');
$api->auth('admin@domain', 'password');
$account = new \Zimbra\Struct\AccountSelector(\Zimbra\Enum\AccountBy::NAME(), 'user@domain');
$response = $api->getAccount($account, null, array());
$api->deleteAccount($response->account->id);