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.

customip value not responsive with cpanel PHP XML API

Discussion in 'cPanel Developers' started by jonbarnes, Mar 5, 2012.

  1. jonbarnes

    jonbarnes Registered

    Joined:
    Mar 5, 2012
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Hi I am trying to run a simple api command that creates a new account and assigns it to a specific ip (which is determined elsewhere in the program). I can use the 'createacct' function fine except the 'customip' value seems to be ignored when setting up the new account. As a workaround, I can then submit a 'setsiteip' query that will change the IP but I would like to do this all from the 'createacct' function if possible.

    Here is what I have so far:

    Code:
    $queries=array(
    	"https://www.mysite.com:2087/xml-api/createacct?username=whmacctuser&password=Cr3at1vePa$$w0rd&domain=www.test.com&ip=n", 
    	"https://www.mysite.com:2087/xml-api/setsiteip?domain=www.test.com&ip=12.345.678.910"
    ); //the first query has been automatically setting it to the shared root IP and then I change it to the desired IP address with the second query
    
    foreach($queries as $query){
    	$curl = curl_init();		
    	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0);	
    	curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,0); 	
    	curl_setopt($curl, CURLOPT_HEADER,0);			
    	curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);	
    	$header[0] = "Authorization: Basic " . base64_encode($whmusername.":".$whmpassword) . "\n\r";
    	curl_setopt($curl, CURLOPT_HTTPHEADER, $header);  
    	curl_setopt($curl, CURLOPT_URL, $query);			
    	$result = curl_exec($curl);
    	if ($result == false) {
    		error_log("curl_exec threw error \"" . curl_error($curl) . "\" for $query");	
    	}
    	curl_close($curl);
    	echo $result."<br />";
    }
    
    Instead, I would like to have:
    Code:
    $query="https://www.mysite.com:2087/xml-api/createacct?username=whmacctuser&password=Cr3at1vePa$$w0rd&domain=www.test.com&ip=n&customip=12.345.678.910";
    
    but, as stated above, the 'customip' value seems to be disregarded as the single query above still assigns the shared root IP. I'm new to the API but it seems fairly straightforward and I can't tell why it is not assigning my requested IP.

    Thanks in advance,
    Jon

    p.s. I have checked to make sure all the values work and the IP address exists
     
  2. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    To clarify, is this account being created going to have a dedicated IP or are you trying to explicitly specify a specific shared IP address the account should be created on?
     
  3. Brian

    Brian Well-Known Member

    Joined:
    Dec 1, 2010
    Messages:
    117
    Likes Received:
    2
    Trophy Points:
    18
    Location:
    Texas
    cPanel Access Level:
    Root Administrator
    The issue is likely that you're telling the API "yes and no" at the same time in regards to the dedicated IP with your options.

    The following arguments are being set by your example:

    ip=n
    customip=12.345.678.910

    "customip" has no meaning unless "ip" is set to "y" (yes). You must firstly tell the API you want a dedicated IP (ip=y) and then you can optionally instruct a preferred IP with customip.

    Be aware of two further caveats that may be at play if you resolve that and the problem persists.

    [1] If you're performing this API call as a reseller, you must have the 'add-pkg-ip' ACL privilege (Allow Creation of Packages with a Dedicated IP). Without it, the options are for naught and the shared IP will only ever result.

    [2] If the custom IP you've specified is not considered an open and available IP according to "WHM -> Show IP Address Usage", then WHM will fall back to the shared IP address as opposed to failing the creation.
     
Loading...

Share This Page