The purpose of this article is to give a basic example of how to use the CDP Server's built in API via PHP. The API will accept XML-RPC call. Details of XML-RPC can be found (http://www.xmlrpc.com/) It is assumed that you have some understanding of how the specification works.
The client used in this tutorial is PHPXMLRPC. The client library is written in PHP and can be downloaded here: http://phpxmlrpc.sourceforge.net/. Simply download, un-tar and place the 'xmlrpc.inc' in your "include path". By default this is usually (include_path='.:/usr/share/pear:/usr/share/php') unless you have configured otherwise. You can also check/modify the location in your 'php.ini' configuration file.
Let's begin by creating a new client instance (xmlrpc_client) and specifying the necessary URL of the CDP Server along with login credential:
Once this is done, the script is ready to send the remote call (xmlrpcmsg). For the sake of simplicity, the 'user.addBasicUser' method is being called. Full API documentation is available on the wiki.
The "xmlrpcmsg" method expects ($methodName, $parameterArray) so the string values must be declared as "new xmlrpcval" values and placed in an array:
Finally, let's send our new message:
The client receives the response ($reply) as an object. The response needs to be "cleaned" before it can be printed. Different XML-RPC clients for PHP will handle this differently so please refer to the appropriate documentation for your client. The code to check for (and print) error messages or printing a successful response (new user's UID) is:
Additional Notes: The project was created as a webpage. The script (addBasicUser.php) includes neccessary HTML to capture form inputs and is available for download (To access, click the 'Tools' button in the top right corner).