Parallels Automation use XML-RPC via PHP to get data from system

Parallels Automation is shortly OSS/BSS system which you can integrate , automate everything how you want via APS packages , you can find out more from this link.

I’m so new programming and want to start understand how to communicate/manage with 3th party system with REST API , XML-RPC.  Parallels have a XML-RPC to communicate with it externally alsso i expect to learn PHP with this integration.

Lets start ;

You can find out all Parallels Automation documentation from this link.

At the startup please read what is XML-RPC and how is looks like.

I do not have enough experience about PHP but to find out good explanations about PHP Tools please check the book ” Essential PHP Tools: Modules,Extensions and Acceleratiors”

tcpdump , yes, tcpdump its very very important because after long time i discover that sending wrong things and because of this i couldn’t query the Parallels Automation.  My environment is ; code uploaded to linux server which cpanel run on it , use pear and on the console executed command bellow to understand what XML-RPC request i am sending to RPC Server.

tcpdump -nl -s 0 -A -i eth1 -c 500 port 80
You can see that , your request will appear like below, its important because you will see many many XML-RPC request examples with PHP and every example do not work how you expected because of it i wasted almost a day until think to use debug somehow to see what i am sending (very clever yeah :))) )

Screen Shot 2014-05-30 at 14.39.51
Also i learn a lot about PHP , of course its nothing but its good start for me
First before start need to understand what kind of XML-RPC request i will send to Parallels Automation . Open the API pdf from link i already described above and choose one of method , i choose the method below
AccountDetailsGet_API
First need to read example to what kind of request need to send  what response you will get , use curl from cli with such xml file and memory the request and response.
This is the file ;

vahric:Apicall vahricmuhtaryan$ cat accountdetail.xml

<?xml version=”1.0″ encoding=”UTF-8″ ?>

<methodCall>

<methodName>Execute</methodName>

<params>

<param>

<value>

<struct>

<member>

<name>

Server</name>

<value>BM</value>

</member>

<member>

<name>Method</name>

<value>AccountDetailsGet_API</value>

</member>

<member>

<name>Params</name>

<value>

<array>

<data>

<value><i4>1000019</i4></value>

</data>

</array>

</value>

</member>

</struct>

</value>

</param>

</params>

</methodCall>

 

this is the curl command from cli

curl –connect-timeout 10 -d @accountdetail.xml -H ‘Content-type:text/xml’ http://192.168.179.2:5224/RPC2

and this is the result

<?xml version=”1.0″ encoding=”UTF-8″?>

<methodResponse><params><param><value><struct><member><name>Result</name><value><array><data><value><array><data><value><i4>1000019</i4></value><value><i4>1</i4></value><value><string>Son Mohican</string></value><value><string>Son Mohican address 1 </string></value><value><string></string></value><value><string>istanbul</string></value><value><string></string></value><value><string>34349</string></value><value><string>tr</string></value><value><string></string></value><value><string>Vahric</string></value><value><string></string></value><value><string>Muhtaryan</string></value><value><string>vahric@doruk.net.tr</string></value><value><string>90</string></value><value><string>212</string></value><value><string>3269200</string></value><value><string></string></value><value><string></string></value><value><string></string></value><value><string></string></value><value><string></string></value><value><i4>1401023839</i4></value><value><i4>2</i4></value><value><i4>0</i4></value><value><i4>1</i4></value></data></array></value></data></array></value></member></struct></value></param></params></methodResponse>

 

Now we have to prepare same request via PHP to query and get same result  , i explained the command inside the code with //
<?php
// All usable XML-RPC functions are inside RPC.php , please include it in your code
require_once ‘XML/RPC.php’ ;
// its good to activate/increase the level of error reporting
error_reporting(E_ALL);
ini_set(‘display_errors’, true);

//We have to describe RPC server access informations , in this example my RPC Server is 192.168.179.8 and listening 5224, because of related server also work

//for different things generally its url is described RPC2, if you want to know what is RPC2.
$xmlrpc = new XML_RPC_Client( ‘/RPC2’, ‘192.168.179.8’, 5224 );

//Need to construct XML-RPC request, you know some Name and Values we have to set

// <struct><member><name>Server</name><value>BM</value></member>
//struct is kind of value type , you can see the its have something inside <member> tags
//new XML_RPC_Value create values
//”Server” => new XML_RPC_Value(“BM”, “string”) is key and value pair and we are using => because of our value type is struct, means Server is key
// BM is value and its type string
// Important part is Params section  , you will see another array is created because get many value inside and all are under <data> tag but you can see that
//There is no <data> tag described like inside accountdetail.xml because its automatically added to request , read http://xmlrpc.scripting.com

params = array(new XML_RPC_Value(array(

“Server” => new XML_RPC_Value(“BM”, “string”),

“Method” => new XML_RPC_Value(“AccountDetailsGet_API”, “string”),

“Params” => new XML_RPC_Value(

array(

new XML_RPC_Value(1000019, “int”)

), “array”)

),  ‘struct’ ) );

//We almost have same view of accountdetail.xml
//With XML_RPC_Message we %100 construct the accountdetail.xml  file means request , first value Execute is XML-RPC Method, you can see many example

//like XML_RPC_Message(‘system.load’);
$msg = new XML_RPC_Message(‘Execute’,$params);
//Now need to send request to XML-RPC server
$resp = $xmlrpc->send($msg);

//Get the response and out it inside veritable (here i used value as veritable )

$value = $resp->value();

//When you execute the php file you will get response as a object
//object(XML_RPC_Value)#34 (2) {
//                   [“me”]=>
//               array(1) {
//                 [“i4”]=>
//                 string(10) “1401023839”
//               }
//Need to convert object to array to use it
//XML_RPC_decode do it for you
$m = XML_RPC_decode($value);

//You can print it to see
print_r($m);

//I told you I’m so new to programming , try to understand key(s) to access array
//you will see that some subarray will be in the result
//print_r(array_keys($m));

I learned that array key is Result and all values are under the subarray which key is 0 and i tried to access second element which is the name of the account
echo $m[‘Result’][0][2];

?>
Hope this help to who use PA and need to make XML-RPC query and new programers to discover how to make XML-RPC request(s) with PHP
VM

Posted on 30/05/2014, in API, XML-RPC and tagged , , . Bookmark the permalink. 7 Comments.

  1. Thanks for this useful post
    Where we can find RPC.php ?

    • Actually i executed this script on server which installed via cpanel , it could be different location depend on your os and php installation.
      Try to search on you server pls.

  2. Thanks !
    Another issue;
    Works well from perl, but form php they return:
    Call to a member function kindOf() on a non-object in /usr/share/pear/XML/RPC.php on line 1948

  3. Ok Solved,
    When paired values are sent, they need to be “Formatted” with Quotes
    Eg: new XML_RPC_Value(“BM”, “string”)

    PS: Bold/Italic->copy/paste->Doesn’t translate Quotes correctly🙂

    Many Thanks again Vahric !

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: