how to check if client already exists in remoting api

Discussion in 'General' started by saco721, Jun 7, 2016.

  1. saco721

    saco721 Member

    Hi,
    I have multi-server setup with ispconfig 3.0.5.4p8, and was wondering how to check if a client record alredy exisits using the remoting api, for example :
    Code:
    <?php
    
    require 'soap_config.php';
    
    
    $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.
        $reseller_id = 0; // this id has to be 0 if the client shall not be assigned to admin or if the client is a reseller
        $params = array(
            'company_name' => 'awesomecompany',
            'contact_name' => 'name',
            'customer_no' => '1',
            'vat_id' => '1',
            'street' => 'fleetstreet',
            'zip' => '21337',
            'city' => 'london',
            'state' => 'bavaria',
            'country' => 'GB',
            'telephone' => '123456789',
            'mobile' => '987654321',
            'fax' => '546718293',
            'email' => '[email protected]',
            'internet' => '',
            'icq' => '111111111',
            'notes' => 'awesome',
            'default_mailserver' => 1,
            'web_php_options' => 'no',   
            'ssh_chroot' => 'no',
            'username' => 'guy3',
            'password' => 'brush',
            'language' => 'en',
            'usertheme' => 'default',
            'template_master' => 2,
            'template_additional' => '',
            'created_at' => 0
        );
    
        $affected_rows = $client->client_add($session_id, $reseller_id, $params);
    
        echo "Client: ".$affected_rows."<br>";
       
       
    if ($affected_rows < 1){
        echo "record not added";
    }
    else
    {
        echo "record added";
    }
        if($client->logout($session_id)) {
            echo 'Logged out.<br />';
        }
    
    
    } catch (SoapFault $e) {
        echo $client->__getLastResponse();
        die('SOAP Error: '.$e->getMessage());
    }
    
    ?>
    
    thanks for your time.
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    You can e.g. use the client_get function to search for the client name or company name and when it does not return the client, then the client does not exist. Serches in *_get functions work by passing a array as $primary_id, e.g.:

    $primary_id = array( 'contact_name' => 'name' );
     
  3. saco721

    saco721 Member

    Hi Till,
    thanks for your reply.
     

Share This Page