Wednesday, December 2, 2009

Drupal Services Module

We have recently been presented with a requirement to integrate an ERP application with Drupal. The decision was made to use the Services module and the XML/RPC service.

When I went to the documentation there seemed to be very little about how to get information in and out using PHP, and a number of people asking for client examples.

Here is a little test page that I did that will return the results of the echo sample that is on the service website. I decided to use the pear xml_rpc2 library as it seems to be the most straight forward to use.



<? php

// I am using the new pear RPC2 library as it seems the simplest to use
// Go here for more info:
// http://pear.php.net/package/XML_RPC2

require_once 'XML/RPC2/Client.php';

// This is the drupal URL for the services module XMLRPC server
$server = 'http://localhost/~bstewart/points/?q=services/xmlrpc';

// The options we want to pass to the server. Prefix is required. You don't need debug.
// Moreinformation here:
// http://pear.php.net/manual/en/package.webservices.xml-rpc2.client.php

$options = array(
'prefix' => 'echo.',
'debug' => TRUE
);

//// You can create and add $options array to this call for debug and other options related to the call.
$client = XML_RPC2_Client::create($server, $options);
//
//// Execute and get the resulting details
$resp = $client->echo("It Works !!!");
//

// Display the message onscreen
echo $resp[message];

?>
Drupal Technology Blog