ISPCONFIG API - dns_templatezone_add function

Discussion in 'ISPConfig 3 Priority Support' started by pawan, Mar 3, 2021.

Tags:
  1. pawan

    pawan Member

    here is the dns_templatezone_add.php example.
    Code:
    if($session_id = $client->login($username, $password)) {
                    echo 'Logged successfull. Session ID:'.$session_id.'<br />';
            }
            //* Set the function parameters.
            $client_id = 1;
            $template_id = 1;
            $domain = 'test.tld';
            $ip = '192.168.0.100';
            $ns1 = 'ns1.testhoster.tld';
            $ns2 = 'ns2.testhoster.tld';
            $email = 'email.test.tld';
    
            $id = $client->dns_templatezone_add($session_id, $client_id, $template_id, $domain, $ip, $ns1, $ns2, $email);
    
            echo "ID: ".$id."<br>";
    
            if($client->logout($session_id)) {
                    echo 'Logged out.<br />';
            }
    and the request I am sending to the server is like this(post request)
    Code:
    {"session_id":"c1662e64aee1ece4e1832485e269c052","client_id":1,"template_id":"2","domain":"testdomain_xyz","ip":"162_471_141_17","ns1":"ns1_example_com","ns2":"ns2_example_com","email":"info@xyz_com"}    ''
    more details:

    Code:
    Request Body
    Name    Value
    Content Type    'application/x-www-form-urlencoded'
    Raw    '{\"session_id\":\"c1662e64aee1ece4e1832485e269c052\",\"client_id\":1,\"template_id\":\"2\",\"domain\":\"testdomain.xyz\",\"ip\":\"162.471.141.17\",\"ns1\":\"ns1.example.com\",\"ns2\":\"ns2.example.com\",\"email\":\"[email protected]\"}'
    Decoded to Params    [
        '{\"session_id\":\"c1662e64aee1ece4e1832485e269c052\",\"client_id\":1,\"template_id\":\"2\",\"domain\":\"testdomain_xyz\",\"ip\":\"162_471_141_17\",\"ns1\":\"ns1_example_com\",\"ns2\":\"ns2_example_com\",\"email\":\"info@xyz_com\"}' => ''
    ]
    but I am getting a blank response from the server. what I am missing here.
     
    Last edited: Mar 6, 2021
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    The function has no return value.
     
  3. pawan

    pawan Member

    Hi Till,
    okay. but no DNS record is created on the server.
    as well the below code suggests that I should get an id as response.

    echo "ID: ".$id."<br>";

    Code:
    try {
            if($session_id = $client->login($username, $password)) {
                    echo 'Logged successfull. Session ID:'.$session_id.'<br />';
            }
    
            //* Set the function parameters.
            $client_id = 1;
            $template_id = 1;
            $domain = 'test.tld';
            $ip = '192.168.0.100';
            $ns1 = 'ns1.testhoster.tld';
            $ns2 = 'ns2.testhoster.tld';
            $email = 'email.test.tld';
    
            $id = $client->dns_templatezone_add($session_id, $client_id, $template_id, $domain, $ip, $ns1, $ns2, $email);
    
            echo "ID: ".$id."<br>";
    
            if($client->logout($session_id)) {
                    echo 'Logged out.<br />';
            }
    
    } catch (SoapFault $e) {
            echo $client->__getLastResponse();
            die('SOAP Error: '.$e->getMessage());
    }
    any place where I can see the logs, where it is failing?
     
  4. pawan

    pawan Member

    Additional Info:
    I am always getting: logged out
    if I am adding this:

    PHP:
    if($this->restCall('logout',$this->session_id)) {
            return 
    'Logged out.<br />';
    }
    full code for dns_templatezone_add
    PHP:
    public function AddDns($domain){
     
        
    $result $this->restCall('login', array('username' => $this->remote_user'password' => $this->remote_pass'client_login' => false));
     
    if(
    $result) {
        
    $data json_decode($resulttrue);
        if(!
    $data) die("ERROR!\n"); 
        
    $this->session_id $data['response'];
    }
        
    $id $this->restCall('dns_templatezone_add',['session_id' => $this->session_id,
        
    'client_id'=>1,
        
    'template_id'=>2,
        
    'domain'=>$domain,
        
    'ip'=>'162.471.141.17',
        
    'ns1' => 'ns1.example.com',
        
    'ns2' => 'ns2.example.com',
        
    'email' => 'info.xyz.com',
        ]);
        if(
    $id){
         return 
    "ID: ".$id."<br>";
        }
         if(
    $this->restCall('logout',$this->session_id)) {
            return 
    'Logged out.<br />';
    }
    }
    and code for curl call
    PHP:
    private function restCall($method$data) {
     
        
    $remote_url=self::remote_url;
        if(!
    is_array($data)) return;
        
    $json json_encode($data);
     
        
    $curl curl_init();
        
    curl_setopt($curlCURLOPT_POST1);

        if(
    $datacurl_setopt($curlCURLOPT_POSTFIELDS$json);

        
    // needed for self-signed cert
        
    curl_setopt($curlCURLOPT_SSL_VERIFYPEERfalse);
        
    curl_setopt($curlCURLOPT_SSL_VERIFYHOSTfalse);

        
    // end of needed for self-signed cert
        
    curl_setopt($curlCURLOPT_URL$remote_url '?' $method);
        
    curl_setopt($curlCURLOPT_RETURNTRANSFER1); 
        
    $result curl_exec($curl);
        
    curl_close($curl);

        return 
    $result;
    }
    Note: The request is going to the server correctly as for the first request I am getting the session_id
    did I missed something?
     
    Last edited: Mar 6, 2021
  5. pawan

    pawan Member

    I believe I am sending the request correctly.
    as I have added the response from the function to see how it is moving at various steps including
    just before the exit line in the end of function - dns_templatezone_add - I added "response from dns_templatezone_add"
    and I am getting the same response without any other error.
    so I am wondering why the request is not creating the DNS records.
     
  6. till

    till Super Moderator Staff Member ISPConfig Developer

    I've never used that API function and I guess it's not widely used, I'll always create the records one by one using the API.
     
  7. atle

    atle Member HowtoForge Supporter

    Well, I use it, dns_templatezone_add, and find it very very useful.
     
    pawan likes this.
  8. pawan

    pawan Member

    Hi atle,
    So you are saying it is working for you?
    wondering what I have missed here.
     

Share This Page