Get domain id from api

Discussion in 'ISPConfig 3 Priority Support' started by tr909192, Nov 7, 2017.

  1. tr909192

    tr909192 Member HowtoForge Supporter

    Dear,

    i'm working on api system of ispconfig (specifically on the domain-dns section). What's the method in order to grab the domain_id of a domain starting from the domain itself? I'm searching something like:

    $domain_id=get_domain_id($domain_name);

    Due that all the calls of the dns are made always starting from the domain_id instead the domain name itself.
    Exist something like that?

    ty
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    The domain_id is not used by the dns system in ISPConfig. doman_id is a variable of the domain limit module only, so querying the dns system for it makes not much sense as it cannot provide that answer and this ID is nt useful for DNS management in ISPConfig anyway. What you can get is the primary ID of the zone that is used by the whole dns system and as reference for the dns records.

    The command is:

    $zone = $client->dns_zone_get($session_id, array('origin' => 'yourdomain.tld.'));
     
    Jesse Norell likes this.
  3. tr909192

    tr909192 Member HowtoForge Supporter

    thank's till but diving into the code i'll get:

    //* Set the function parameters.
    $id = 1;

    $dns_record = $client->dns_zone_get($session_id, $id);

    so this one drive me crazy to understand what id was related to...
     
  4. Croydon

    Croydon ISPConfig Developer ISPConfig Developer

    This is the primary id (database) of the dns zone. To get the zone by domain you have to use
    PHP:
    $domain 'mydomain.com';
    $dns_record $client->dns_zone_get($session_id, array('origin' => $domain));
     
  5. tr909192

    tr909192 Member HowtoForge Supporter

    Sorry to re-open but something to me is not totally clear.

    With:
    $zone_id = $client->dns_zone_get($session_id, array('origin' => 'yourdomain.tld.'));
    i'll get the id of the zone. that's fine.

    But from there if I use that id in order to query what NS record are set on a specific zone, return always empty result:

    $dns_record = $client->dns_ns_get($session_id, $zone_id);

    return empty array (but this zone has two ns records).

    I'm wrong something?
     
  6. Croydon

    Croydon ISPConfig Developer ISPConfig Developer

    The dns_zone_get does not return the id. It returns the record.
     
  7. Croydon

    Croydon ISPConfig Developer ISPConfig Developer

    If you want the ID you have to use $client->dns_zone_get_id($session_id, $origin);
     
    Jesse Norell likes this.
  8. tr909192

    tr909192 Member HowtoForge Supporter

    yes, sure.
    the complete code was:

    $domain_info = $client->dns_zone_get($session_id, array('origin' => 'mydomain.com.'));
    $zone_id=$domain_info[0]['id'];
    $dns_record = $client->dns_a_get($session_id, $zone_id);
    var_dump($dns_record); // empty

    wrong?
     
  9. Croydon

    Croydon ISPConfig Developer ISPConfig Developer

    And to query the ns, you are again using the wrong settings, the second parameter is the primary ID of the zone_ns record, NOT of the zone itself. So you have to give a search array there, too:
    PHP:
    $domain 'mydomain.com';
    $dns_record_id $client->dns_zone_get_id($session_id$domain);
    $dns_ns $client->dns_ns_get($session_id, array('zone' => $dns_record_id));
     
    Jesse Norell likes this.
  10. tr909192

    tr909192 Member HowtoForge Supporter

    Ok now, every is working. And really thank you for your help Croydon.
    But honestly archive that starting from the documentation included on the remoteAPI directory of the ispconfig could be pretty hard...

    ty
     
    Last edited: Nov 7, 2017

Share This Page