API Help

Discussion in 'Installation/Configuration' started by sjau, Mar 19, 2015.

  1. sjau

    sjau Local Meanie Moderator

    Hi there

    I'm currently trying to write a little script that makes use of the Horde API. There is a howto published here - https://www.howtoforge.com/how-to-create-remote-api-scripts-for-ispconfig-3 - hoever I have an issue with it.

    The main issue I have is the section regarding the $params. In the howto it says "Above the function line you will see the creation of the function's array.". However I can't seem to find that example array at all.

    Specifically I'm trying to update the IP address of an A record.
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    Did you check out the example files in the remote_client folder f the ispconfig tar.gz file? There are examples for nearly all functions in that folder.
     
  3. sjau

    sjau Local Meanie Moderator

    There are example files? oO

    Thx, will do so :)
     
  4. sjau

    sjau Local Meanie Moderator

    Hmmm, still no luck:

    Code:
    <?php
    
    $username = 'xxx';
    $password = 'yyy';
    
    $soap_location = 'https://ispc.domain.tld:8080/remote/index.php';
    $soap_uri = 'https://ispc.domain.tld:8080/remote/';
    
    
    // Get current IP
    $curIP = file_get_contents('http://domain.tld/ip.php');
    if(!filter_var($curIP, FILTER_VALIDATE_IP)) {
       echo "Not a valid IP address!"; exit;
    } else {
        echo "valid IP<br>\n";
    }
    
    
    $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 />';
        }
    
        //* Parameters
        $id = 289;
        $client_id = 26;
    
    
        //* Get the dns record
        $dns_record = $client->dns_a_get($session_id, $id);
    
        //* Change active to inactive
        $dns_record['active'] = 'y';
        $dns_record['data'] = $curIP;
        $dns_record['sysuserid'] = 19;
        $dns_record['sys_groupid'] = 19;
    
        $affected_rows = $client->dns_a_update($session_id, $client_id, $id, $dns_record);
    
        echo "Number of records that have been changed in the database: ".$affected_rows."<br>";
    
        if($client->logout($session_id)) {
            echo 'Logged out.<br />';
        }
    
    
    } catch (SoapFault $e) {
        echo $client->__getLastResponse();
        die('SOAP Error: '.$e->getMessage());
    }
    
    ?>
    
    And I get this result:

    The sql query seems to fail because sys_userid and sys_groupid have no values. However I did add them as params yet it still remains the same.

    Basically I wish to make dyn IP updater....
     
  5. till

    till Super Moderator Staff Member ISPConfig Developer

    The sys_userid and sys_groupid values get calculated automatically based on the $client_id that you assign to the function. Does client 26 really exist?
     
  6. sjau

    sjau Local Meanie Moderator

    ah... that is the issue.... should be 16 ;)
     
  7. sjau

    sjau Local Meanie Moderator

    Ok, fixed the client_id now it works :)
     

Share This Page