Hello, I would like to know how to create an email address via ISPConfig 3.2 in PHP. I have seen some things, but it is still "website", not email address only. Thank you,
You can find API usage examples for various functions incl. functions to add email accounts in the remote_client folder of the ISPConfig tar.gz file.
Hello, I have a problem: If I use: HTTPS:// I have: login_failedThe login failed. Username or password wrong. SOAP Error: The login failed. Username or password wrong. If I use: HTTP:// I have: SOAP Error: Bad Request My code is: PHP: $username = 'ID_USER_C4'; $password = 'PASSWORD_USER_C4'; $soap_location = 'http://url_domain.ext:8080/remote/index.php'; $soap_uri = 'http://url_domain.ext:8080/remote/'; $client = new SoapClient(null, array('location' => $soap_location, 'uri' => $soap_uri, 'trace' => 1, 'exceptions' => 1)); try { if($session_id = $client->login($username, $password)) { echo 'Logged successfull. Session ID:'.$session_id.'<br />'; } //* Set the function parameters. $client_id = "4"; // 4 BECAUSE I USE C4 $password0 = $request->GetPost('dvtme__email_mail_password'); $params = array( 'server_id' => 1, 'email' => $request->GetPost('dvtme__email_mail_username').'@my_domain.ext', 'login' => $request->GetPost('dvtme__email_mail_username').'@my_domain.ext', 'password' => $password0, 'name' => $request->GetPost('dvtme__email_mail_username').' by '.$user['pseudo'], 'uid' => 5000, 'gid' => 5000, 'maildir' => '/var/vmail/my_domain.ext/'.$request->GetPost('dvtme__email_mail_username').'', 'quota' => 5242880, 'cc' => '', 'homedir' => '/var/vmail', 'autoresponder' => 'n', 'autoresponder_start_date' => '', 'autoresponder_end_date' => '', 'autoresponder_text' => 'hallo', 'autoresponder_subject' => 'Out of office reply', 'move_junk' => 'n', 'custom_mailfilter' => 'spam', 'postfix' => 'n', 'access' => 'n', 'disableimap' => 'n', 'disablepop3' => 'n', 'disabledeliver' => 'n', 'disablesmtp' => 'n' ); $mailuser_id = $client->mail_user_add($session_id, $client_id, $params); echo "New user: ".$mailuser_id."<br>"; if($client->logout($session_id)) { //echo 'Logged out.<br />'; } } catch (SoapFault $e) { echo $client->__getLastResponse(); die('SOAP Error: '.$e->getMessage()); } What the problem @till ?
You have to use a username and password for a remote user, which you can add under System - Remote Users. You can't use client logins for the API. You also have to grant the correct rights to the needed functions for your remote user. The http error is probably caused because you are using HTTPS for the panel. So use HTTPS with a correct username and password.
The error message says value for purge_trash_days is not Integer. I am too lazy to count fields in that picture, so you have to find yourself which value is for purge_trash_days.
I've spent the last couple days in both client and server-side code in this area, so at this moment my eyes are very familiar with those queries. It looks to me like the fields are really out of line with the data. I'd check to ensure there are no commas or quotes in the source data. Use print_r() to verify your $params. (Or var_dump where it's appropriate.) As noted in an Issue that I posted yesterday, there seems to be an error with API in what it does with the data received. I've been using JSON remoting, not SOAP, but it all goes to the same place, and code that leads to the final INSERT might be corrupting your query in a way similar to what's been happening with mine. If you look at my other threads recently, I've been saying the API doc doesn't tell us everything that we need to pass in these queries. The old doc hasn't been updated with new fields. A couple months ago I kinda took responsibility for updating those docs. I've been writing scripts for each function, both for myself and so that I can update all of those API docs. It's a slow process. For now, verify 100% exactly what you are passing into the $params. Then we can compare that to the INSERT query. If you are passing in the wrong data, of course that will be what is in the INSERT. But if you are passing in X and the INSERT is using Y, then there is a bug ... and that's what I was reporting. Again, you might have found a similar issue that might actually help in the resolution of that Issue. HTH P.S. "successfull" only has one "L".
This might help to get us on the same page. This is what I've been building for myself and publication. Start with a small bit of code common to all API requests: Expand: common.php PHP: <?php$version = "0.4";$base_url = 'https://localhost:8080/remote/json.php?'; // client is running on ISPConfig server, change as required$user = "yyyyyyyyyyy";$psw = "zzzzzzzzzzzzzzzzzzzzzzz";require_once 'common_functions.php';// all functions need a session ID, get it here in this common code$session_id = '"session_id": "' . login($user, $psw) . '"'; Common functions are in one file. Individual API calls are in their own files. Expand: common_functions.php PHP: <?phprequire_once 'HTTP/Request2.php'; // Not using SOAP, requests are JSON.function query_server($id, $body){ global $base_url; // echo "----------"; // echo $body; // echo "----------"; $json = null; $errmsg = ""; $request = new HTTP_Request2(); $request->setBody($body); $request->setMethod(HTTP_Request2::METHOD_POST); $request->setConfig(array( 'follow_redirects' => TRUE, 'ssl_verify_peer' => FALSE, 'ssl_verify_host' => FALSE )); $request->setHeader(array( 'Content-Type' => 'application/json' )); $request->setUrl($base_url . $id); try { $response = $request->send(); if ($response->getStatus() == 200) { $text = $response->getBody(); $json = json_decode($text, $assoc = true); //var_dump($json); // . "\n"; if ($json == null) exit("Unexpected null result"); } else { $errmsg = 'Unexpected HTTP status: ' . $response->getStatus() . ' ' . $response->getReasonPhrase(); } } catch (HTTP_Request2_Exception $e) { $errmsg = 'Error: ' . $e->getMessage(); } if ($errmsg != "") { exit($errmsg); } if ($json["code"] == "remote_fault") exit($json["message"]); return $json;}function login($user, $psw){ return query_server( 'login', '{ "username": "' . $user . '", "password": "' . $psw . '" }' )["response"];} These are $param defaults for mail_user_add functions, maybe others. Change to set your defaults: Expand: mail_user_add_template.php PHP: <?phpfunction getMailUserParams(){// any value with a # should be replaced in each call return array( "_ispconfig_pw_crypted" => 0, "access" => "y", "autoresponder_end_date" => null, "autoresponder_start_date" => null, "autoresponder_subject" => "Out of office reply", "autoresponder_text" => "", "autoresponder" => "n", "backup_copies" => 5, "backup_interval" => "daily", "cc" => "", "custom_mailfilter" => "", "disabledeliver" => "n", "disabledoveadm" => "n", "disableimap" => "n", "disableindexer-worker" => "n", "disablelda" => "n", "disablelmtp" => "n", "disablepop3" => "n", "disablequota-status" => "n", "disablesieve-filter" => "n", "disablesieve" => "n", "disablesmtp" => "n", "email" => "#email", "forward_in_lda" => "n", "greylisting" => "n", "homedir" => "/var/vmail", "login" => "#login", "maildir" => "#maildir", "move_junk" => "y", "name" => "#name", "password" => "#password", "postfix" => "y", "purge_junk_days" => 0, "purge_trash_days" => 0, "quota" => 0, "sender_cc" => "", "server_id" => 1, "sys_userid" => 1, "sys_groupid" => 2, "uid" => 5000, "gid" => 5000, );} Now customize this for each new mail user. Expand: mail_user_add.php PHP: <?phprequire_once '../common.php'; // note file locationsrequire_once './mail_user_add_template.php';function getClientID(){ return 2; // int primary_key, should be retrieved, not hardcoded}// Pass ALL params to the server, more than in the API docs which will get updates soon$params = getMailUserParams();$domain = "example.com"; // call custom functions for this data$username = "foo";$params["email"] = $username . "@" . $domain;$params["login"] = $username . "@" . $domain;$params["password"] = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzz";$params["name"] = $username;$params["maildir"] = "/var/vmail/" . $domain . "/" . $username;$data = json_encode(array( "session_id" => login($user, $psw), "client_id" => getClientID(), "params" => $params));$json_result = query_server( 'mail_user_add', $data);\\var_dump($json_result);\\echo "\n\n";// use your own code here as required. the get/show code is not provided here$id = $json_result["response"]//$user = get_mail_user($id)//show_mail_user($user); Unfortunately with good data, that currently leads to a failed INSERT, similar to the that reported by the OP, but for different reasons. This is the pattern that I'm following. If there's anything wrong with the basic style, please let me know before I publish a whole library of this crap. The code will be enhanced later with OOP, and I'll remove hard-coding, with population of fields abstracted out to user-defined functions. For now, it is what it is.
All cool, TY. Since the tform fields are used to construct queries. What do you think about a routine that runs through the formDef['fields'] to create both current documentation and client routines like getMailUserParams() above? There's a real opportunity with this that wouldn't be possible if the queries weren't generated as they are.