client_add api function issues

Discussion in 'General' started by pyte, Sep 13, 2022.

  1. pyte

    pyte Well-Known Member HowtoForge Supporter

    Hi,
    my script is breaking again and i can't figure out why. So here is the code in questing:

    PHP:
    try {
        
    $cr $GLOBALS['client']->client_get_by_username($GLOBALS['session_id'], $client_id);
        
    $id $GLOBALS['client']->client_get($GLOBALS['session_id'], $cr['client_id']);
    } catch (
    SoapFault $e) {
        print(
    " ==> Adding Client - {$params['contact_name']} | ID: {$params['customer_no']}\n");
        try {
            echo 
    "[DBG] Adding Client:\n";
            
    print_r($params);
            
    $GLOBALS['client']->client_add($GLOBALS['session_id'], $reseller_id$params);
        } catch (
    SoapFault $l) {
            print(
    "ERROR: {$e}\n");
        }
        continue;
    }
    Background: We first try to get client data by username, as the username within ISPConfig is the customer number that we use internally. If this fails we know that this customer is missing in ISPConfig and we need to add them, but it errors with the following error message:
    Here are the contents of the $parms Array:
    Code:
    Array
    (
        [company_name] => Customer Name XYZ
        [contact_firstname] => Name
        [contact_name] => Surname
        [customer_no] => 117259
        [street] => Stree Name 12
        [zip] => 000000
        [city] => CityName
        [state] => DE
        [country] => DEU
        [telephone] => 00000000
        [fax] => -
        [email] => [email protected]
        [internet] => Unbekannt
        [limit_client] => 0
        [parent_client_id] => 0
        [username] => 117259
        [password] =>
        [language] => de
        [usertheme] => default
        [created_at] => 0
    )
    
    Any ideas what is causing the error? It confuses me that the error says "no_client_found" as i am trying to add a new one.
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    I guess the $reseller_id that you pass to the function is invalid. It has to be either 0 or a valid reseller ID.
     
  3. pyte

    pyte Well-Known Member HowtoForge Supporter

    Well i've just checked that. The variable "$reseller_id" is set to '1' which is indeed the correct reseller_id. I've just changed the line to:
    $GLOBALS['client']->client_add($GLOBALS['session_id'], 1, $params);

    But the error persists. I have a working script that does exactly this but for my demo instance, which is older than the new setup. The reseller_id there is 299. Here is the code:
    PHP:
     $params = array(
       
    'company_name' => trim($tmp_company_name),
       
    'contact_firstname' => trim($tmp_contact_firstname),
       
    'contact_name' => trim($tmp_contact_name),
       
    'customer_no' => $row['customer_no'],
       
    'vat_id' => '',
       
    'street' => $tmp_street,
       
    'zip' => $tmp_zip,
       
    'city' => $tmp_city,
       
    'state' => 'DE',
       
    'country' => $tmp_country,
       
    'telephone' => $tmp_telephone,
       
    'mobile' => '',
       
    'fax' => $tmp_fax,
       
    'email' => $tmp_email,
       
    'internet' => $tmp_internet,
       
    'icq' => '',
       
    'notes' => '',
       
    'default_mailserver' => 1,
       
    'limit_maildomain' => -1,
       
    'limit_mailbox' => -1,
       
    'limit_mailalias' => -1,
       
    'limit_mailaliasdomain' => -1,
       
    'limit_mailforward' => -1,
       
    'limit_mailcatchall' => -1,
       
    'limit_mailrouting' => 0,
       
    'limit_mailfilter' => -1,
       
    'limit_fetchmail' => -1,
       
    'limit_mailquota' => -1,
       
    'limit_spamfilter_wblist' => 0,
       
    'limit_spamfilter_user' => 0,
       
    'limit_spamfilter_policy' => 1,
       
    'default_webserver' => 1,
       
    'limit_web_ip' => '',
       
    'limit_web_domain' => 1,
       
    'limit_web_quota' => -1,
       
    'web_php_options' => 'no,fast-cgi,cgi,mod,suphp',
       
    'limit_web_subdomain' => -1,
       
    'limit_web_aliasdomain' => -1,
       
    'limit_ftp_user' => -1,
       
    'limit_shell_user' => 0,
       
    'ssh_chroot' => 'no,jailkit,ssh-chroot',
       
    'limit_webdav_user' => 0,
       
    'default_dnsserver' => 1,
       
    'limit_dns_zone' => -1,
       
    'limit_dns_slave_zone' => -1,
       
    'limit_dns_record' => -1,
       
    'default_dbserver' => 1,
       
    'limit_database' => -1,
       
    'limit_cron' => 0,
       
    'limit_cron_type' => 'url',
       
    'limit_cron_frequency' => 5,
       
    'limit_traffic_quota' => -1,
       
    'limit_client' => 0,
       
    'parent_client_id' => 0,
       
    'username' => $row['customer_no'],
       
    'password' => 'XXXXXXXXXXXXXXXXXXXX',
       
    'language' => 'de',
       
    'usertheme' => 'default',
       
    'template_master' => 1,
       
    'template_additional' => '',
       
    'created_at' => 0
      
    );

      
    $client_id $row['customer_no'];

      try {
       
    $cr $GLOBALS['client']->client_get_by_username($GLOBALS['session_id'], $client_id);
       
    $id $GLOBALS['client']->client_get($GLOBALS['session_id'], $cr['client_id']);
      } catch (
    SoapFault $e) {
       print(
    " ==> Adding Client - {$params['contact_name']} | ID: {$params['customer_no']}\n");
       try {
        
    $GLOBALS['client']->client_add($GLOBALS['session_id'], 299$params);
        echo 
    "Kunde:" $row['company_name'];
       } catch (
    SoapFault $l) {
        
    // do nothing
       
    }

       continue;
      }
    Any ideas? Am i blind, as i looks identical to me but the demo one works just fine?
     
  4. pyte

    pyte Well-Known Member HowtoForge Supporter

    Well...
    I was sure this was working a few month back and it was! It was just a different file name. However now i am even more confused:


    PHP:
     $params = array(
                        
    'company_name' => trim($tmp_company_name),
                        
    'contact_firstname' => trim($tmp_contact_firstname),
                        
    'contact_name' => trim($tmp_contact_name),
                        
    'customer_no' => $row['customer_no'],
                        
    'street' => $tmp_street,
                        
    'zip' => $tmp_zip,
                        
    'city' => $tmp_city,
                        
    'state' => 'DE',
                        
    'country' => $tmp_country,
                        
    'telephone' => $tmp_telephone,
                        
    'fax' => $tmp_fax,
                        
    'email' => $tmp_email,
                        
    'internet' => $tmp_internet,
                        
    'web_php_options' => 'no,fast-cgi,cgi,mod,suphp',
                        
    'ssh_chroot' => 'no,jailkit,ssh-chroot',
                        
    'limit_cron' => 0,
                        
    'limit_cron_type' => 'url',
                        
    'limit_cron_frequency' => 5,
                        
    'limit_client' => 0
                        
    'parent_client_id' => 0,
                        
    'username' => $row['customer_no'],
                        
    'password' => '',
                        
    'language' => 'de',
                        
    'usertheme' => 'default',
                        
    'template_master' => 1,
                        
    'template_additional' => '',
                        
    'created_at' => 0
                    
    );

                    
    $client_id $row['customer_no'];

                    try {
                            
    $cr $GLOBALS['client']->client_get_by_username($GLOBALS['session_id'], $client_id);
                            
    $id $GLOBALS['client']->client_get($GLOBALS['session_id'], $cr['client_id']);
                    } catch (
    SoapFault $e) {
                            print(
    " ==> Adding Client - {$params['contact_name']} | ID: {$params['customer_no']}\n");
                            try {
                                    print(
    "Trying to add client...");
                                    
    $GLOBALS['client']->client_add($GLOBALS['session_id'], 1$params);
                            } catch (
    SoapFault $ee) {
                                print(
    "ERROR: {$ee}\n");

                            }

                            continue;
                    }
    What is the difference here that causes the issue? The Params Array doesn't seem to be related as i just tested it.
    The problem is solved however this is bugging me, any idea?
     
  5. till

    till Super Moderator Staff Member ISPConfig Developer

    The error is not related to params, as I mentioned above, it is probably about the reseller_id.
     
  6. pyte

    pyte Well-Known Member HowtoForge Supporter

    Can't seem to figure it out, even if i change the line
    Code:
    $GLOBALS['client']->client_add($GLOBALS['session_id'], $reseller_id, $params);
    to
    Code:
    $GLOBALS['client']->client_add($GLOBALS['session_id'], 1, $params);
    in the script that was not working i still dosen't work. But works in the other ones.

    But like i said let's close this. The solution in Post #4 works. Thank you for the hints :)
     

Share This Page