Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Hi Dheeru

deeptanshu will coordinate with your for your require details. Meanwhile i'm sending you script detail which i'm using for connection.

/**

  • Reports error during API RPC request

    / class ApiRequestException extends Exception {} /*

  • Returns DOM object representing request for information about all available domains
  • @return DOMDocument / /*
  • Reports error during API RPC request */ function parseResponse($response_string) { $xml = new SimpleXMLElement($response_string);

    if (!is_a($xml, 'SimpleXMLElement'))

         throw new ApiRequestException("Cannot parse server response: {$response_string}");
    

    return $xml; }

function curlInit($login, $password,$host) { $curl = curl_init();

  curl_setopt($curl, CURLOPT_URL, $host);

  curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

  curl_setopt($curl, CURLOPT_POST,           true);

  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

  curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);

  curl_setopt($curl, CURLOPT_HTTPHEADER,

         array("HTTP_AUTH_LOGIN: {$login}",

                "HTTP_AUTH_PASSWD: {$password}",

                "HTTP_PRETTY_PRINT: TRUE",

                "Content-Type: application/json'")
  );

  return $curl;

}

/**

  • Performs a Panel API request, returns raw API response text

    *

  • @return string

  • @throws ApiRequestException

    */

function sendRequest($curl, $packet)

{

  curl_setopt($curl, CURLOPT_POSTFIELDS, $packet);

  $result = curl_exec($curl);

  if (curl_errno($curl)) {

         $errmsg  = curl_error($curl);

         $errcode = curl_errno($curl);

         curl_close($curl);

         throw new ApiRequestException($errmsg, $errcode);

  }

  curl_close($curl);

  return $result;

}

function checkResponse(SimpleXMLElement $response)

{

  $resultNode = $response->customer->get->result;

  // check if request was successful

  if ('error' == (string)$resultNode->status)

         throw new ApiRequestException("The Panel API returned an error: " . (string)$resultNode->result->errtext);

}

////*******************************///////

$packet='tenantId=32c4101bce274e0ea49180d387a2f907'; $host = 'http://103.247.97.1:5000/v2.0'; $password = 'znet@123'; $login = 'admin';

$curl = curlInit($host, $login, $password); try {

 print_r($curl);

 echo '<br />';

 $response = sendRequest($curl, $packet);

print_r($response);

} catch (ApiRequestException $e) { print_r($e); }

?>

Please check and update me.

Thanks

Harish