Rest API - Get all Active Domains

Discussion in 'Developers' Forum' started by Daniel Nielsen, May 9, 2018.

  1. Daniel Nielsen

    Daniel Nielsen New Member

    Hi,
    I've been walking around the API files, but can't seem to find an endpoint for my needs...
    I would like to get a list with all ACTIVE domains on the server.

    I've tried using the 'sites_web_domain_get' in a while-sentence:
    PHP:
    $c=1;
        while(
    $domain_record restcall('sites_web_domain_get',array('session_id'=>$session_id'primary_id'=>$c'active'=>1))) {
            if(
    $domain_record) {
                
    $domain_record json_decode($domain_record,true);
                
    // if(count($domain_record['response']) > 0) {
                
    if($domain_record['response'] !== NULL) {
                    print 
    $c.":\t\t".$domain_record['response']['domain']."<br>";
                    print 
    '<pre>';
                    
    print_r($domain_record['response']);
                    print 
    '<pre>';
                    print 
    '<hr>';
                }
            }
            if(
    $c == 500) exit;
            
    $c++;
        }
    But I think there must be a better way to do this?
     
  2. ztk.me

    ztk.me ISPConfig Developer ISPConfig Developer

    yeah, I'd vote for that feature aswell, getting a list of websites + filter would be soooo damn helpful.
    I happened to just make a direct dabase call for getting some data out :( But maybe something changed meanwhile? Or planned at least for like 3.2.42 release?
     
  3. till

    till Super Moderator Staff Member ISPConfig Developer

    There is already an API endpoint to return all active domains:

    $all_active_domains = $client->sites_web_domain_get($session_id, array('active' => 1));
     
    ztk.me likes this.
  4. till

    till Super Moderator Staff Member ISPConfig Developer

    That's available for too, all _get functions of the API allow filtering for all available columns. Simply pass an array as primary_id which contains your filter. See my example above for filtering active domains.

    Example, return all domains that contain 'tom' in their name:

    $tom_domains = $client->sites_web_domain_get($session_id, array('domain' => '%tom%'));
     
    Last edited: May 9, 2018
    Jesse Norell and ztk.me like this.
  5. Daniel Nielsen

    Daniel Nielsen New Member

    I wonder... Why does my output include both active AND inactive domains?
     
  6. till

    till Super Moderator Staff Member ISPConfig Developer

    Actually, active is a 'y'/'n' column. I did not look that up and used your value, so the correct call is:

    $all_active_domains = $client->sites_web_domain_get($session_id, array('active' => 'y'));
     
  7. Daniel Nielsen

    Daniel Nielsen New Member

    Hmm... it doesn't matter if I use 'y' or 1 it still outputs all domains
     
  8. Daniel Nielsen

    Daniel Nielsen New Member

    Is there any difference between using SOAP or REST?
     
  9. till

    till Super Moderator Staff Member ISPConfig Developer

    The REST API is a wrapper for the SOAP api, so they basically do the same. But you might try to use the SOAp call I posted as my guess is that your REST call is different as active = y is a sub-array passed instead or primary ID in the soap call and as far as I see, you pas primary_id = 1 instead.
     
  10. Daniel Nielsen

    Daniel Nielsen New Member

    Can you provide me with a basic example of a SOAP connection?
     
  11. till

    till Super Moderator Staff Member ISPConfig Developer

    You can find plenty of SOAP api examples in the remote_client folder of the ISPConfig tar.gz file.
     

Share This Page