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
AccountDetailsGet_API
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
<?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>
<?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 reportingerror_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.comparams = 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];?>
Posted on 30/05/2014, in API, XML-RPC and tagged Parallels Automation API, Parallels Automation XML-RPC, XML-RPC. Bookmark the permalink. 7 Comments.
Thanks for this useful post
Where we can find RPC.php ?
LikeLike
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.
LikeLike
Thanks for your fast reply !
Is now solved
LikeLike
Perfect !
LikeLike
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
LikeLike
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 !
LikeLike
Good, you welcome
LikeLike