The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Using xml api functions to check if a domain already exists

Discussion in 'cPanel Developers' started by sachintaware, Feb 1, 2013.

  1. sachintaware

    sachintaware Member

    Joined:
    Jan 29, 2013
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    Hello
    I am using the xml-api for cpanel-WHM to get details.I want to check if a domain already exists before a new one is created.
    I came across the
    Code:
    listaccts()
    function and tried to implement it.This has two optional parameters
    PHP:
    searchType and searchString
    .But if I have to check if a domain exists it returns true even if some part of the string matches the search string.I want the entire string to be checked and validated.So I thought of getting all the results using
    Code:
    listaccts()
    and then search if the domain already exists or not.This is my code
    PHP:
    $result$xmlapi->listaccts();
    $json json_encode($result);
    $array json_decode($json,TRUE);
    echo 
    "<br/><b>Account list is</b> <pre>";
        
    print_r($array);
    echo 
    "</pre>";
    Now,the page outputs all the accounts with details of each account,but i want to check only the domain name of all accounts.I tried to use
    Code:
    $array['domain']
    etc but did not get only the domain names of all accounts.How can I get only the domain names of all accounts and then check for the existing one?
    Thank you for your time.
     
    #1 sachintaware, Feb 1, 2013
    Last edited: Feb 1, 2013
  2. sachintaware

    sachintaware Member

    Joined:
    Jan 29, 2013
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    I am still stuck on it.Any help would be appreciated!
     
  3. KostonConsulting

    KostonConsulting Well-Known Member

    Joined:
    Jun 17, 2010
    Messages:
    255
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    San Francisco, CA
    cPanel Access Level:
    Root Administrator
    The 'search' parameter allows for regular expressions so you can force a strict match:


    If you want to match just domain.com and not *domain.com, you can use this:

    ^domain.com$

    It's probably easiest to test your regex via URL:

    https://domain.com:2087/xml-api/listaccts?searchtype=domain&search=^domain.com$

    Here's a primer on perl regular expressions that may prove useful:

     
Loading...

Share This Page