Using xml api functions to check if a domain already exists

sachintaware

Member
Jan 29, 2013
8
0
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.
 
Last edited:

KostonConsulting

Well-Known Member
Verifed Vendor
Jun 17, 2010
255
1
68
San Francisco, CA
cPanel Access Level
Root Administrator
I want the entire string to be checked and validated
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: