Hi there.
I've got problem with subscription creation by API call.
I'm net getting response from curl when subscription is created.
With account creation (customer) I'm getting normal response.
Also when I'm trying to create subscription with domain which already exists in panel I'm getting normal response from API.
I will try to reproduce that:
1. making call to create subscription
2. getting empty response (subscription created in plesk panel)
3. trying call again subscritpion creation with the same parameters send previously
4 getting error from API about that domain already exists.
this is my code with deleted IP, and login details
I've got problem with subscription creation by API call.
I'm net getting response from curl when subscription is created.
With account creation (customer) I'm getting normal response.
Also when I'm trying to create subscription with domain which already exists in panel I'm getting normal response from API.
I will try to reproduce that:
1. making call to create subscription
2. getting empty response (subscription created in plesk panel)
3. trying call again subscritpion creation with the same parameters send previously
4 getting error from API about that domain already exists.
this is my code with deleted IP, and login details
class Plesk {
public function _makeRequest($params) {
$headers = array(
'HTTP_AUTH_LOGIN: xxxxxxxx',
'HTTP_AUTH_PASSWD: xxxxxxxxx',
'Content-Type: text/xml'
);
$xml = $this->_arrayToXml($params, new SimpleXMLElement('<packet version="1.6.3.0"></packet>'))
->asXML();
$ch = curl_init ();
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt ($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt ($ch, CURLOPT_URL, 'https://domain.com:8443/enterprise/control/agent.php');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_TIMEOUT, 480);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $xml);
//debug
curl_setopt($ch, CURLOPT_VERBOSE, true);
$result = curl_exec($ch);
if (curl_errno ($ch)) {
echo curl_errno ($ch) . ' - ' . curl_error ($ch);
}
curl_close($ch);
return $this->_parseResponse($result);
}
private function _arrayToXml(array $arr, SimpleXMLElement $xml) {
$numbers = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
foreach ($arr as $k => $v) {
if (is_array($v)) {
$this->_arrayToXml($v, $xml->addChild(str_replace($numbers, '', $k)));
} else {
$xml->addChild(str_replace($numbers, '', $k), $v);
}
}
return $xml;
}
private function _parseResponse($result) {
try {
$xml = simplexml_load_string($result, 'SimpleXMLElement', LIBXML_NOCDATA);
} catch (Exception $e) {
echo 'simpleXmlException: '.$e->getMessage();
}
return $xml;
}
public function toArray(SimpleXMLElement $xml) {
$array = (array)$xml;
foreach ( array_slice($array, 0) as $key => $value ) {
if ( $value instanceof SimpleXMLElement ) {
$array[$key] = empty($value) ? NULL : $this->toArray($value);
}
}
return $array;
}
}
$params = array(
'webspace' => array(
'add'=>array(
'gen_setup'=> array(
'name' => 'test.com',
'ip_address' => 'xxx.xxx.xxx.xxx',
'status' => '0',
),
)
),
);
$plesk= new Plesk;
$result=$plesk->_makeRequest($params);
var_dump($result);