Leveraging XML-RPC services with the Services module

So back in August I was working with [[Transmitting nodes between Drupal sites]], basically using the method outlined in Chapter 19 of Pro Drupal Development.

Among the comments concerning my reinventing the wheel were several excellent suggestions, as is common in the Drupal community. One of them mentioned the Services module.

So back in August I was working with [[Transmitting nodes between Drupal sites]], basically using the method outlined in Chapter 19 of Pro Drupal Development.

Among the comments concerning my reinventing the wheel were several excellent suggestions, as is common in the Drupal community. One of them mentioned the Services module.

Well, these days I am implementing a veritable bevy of babel sites, who like nothing better than to yak, yak, yak to each other. One custom newspaper production system, built on Drupal, wants to spit out the published issue to the publications website. Another job site wants personnel people to be able to create job searches on an in-house intranet, only to have these shouted up to the internet job site, where job searchers can apply for these jobs, if they would be so good as to publish their resumes in their searchable profiles; only to have these job applications shouted back down to the intranet.

Since it’s getting rather noisy, I decided we need to bring in the old "don’t invent the wheel, re-use and generalize" paradigm, namely, use the services module so I can painlessly migrate to REST, or SOAP, or what-have-you.

So a couple of months ago I started playing around with it in my not so spare time, and I just wanted to publish a couple of little hurdles to jump over, maybe save some other poor soul some time.

Basically, it is pretty simple and works as advertised:

How to use the Services module with XML-RPC.

  1. Install and enable modules
    1. Services
    2. XMLRPC Server
    3. Node service
    4. System service
    5. Taxonomy service
    6. User service
    7. Views service
  2. Set permissions
    1. Allow anonymous user to access services module from access control
  3. Configure
    1. Remove key or session requeriments from service configuration
    2. Hmmmm. Groovy example in Drupal Handbook talks about api key and all that (see http://drupal.org/node/132809 )… Maybe I am missing something; but if you don’t remove these requirements, I got error messages no matter what I did (used all kinds of different clients to no avail, but maybe I was doing something wrong).
      The module maintainer confirms this (not that I was doing something wrong, but that you have to remove api key and session requirements as well as allow anonymous users access to services; see http://drupal.org/node/210670 )

  4. Assuming there is a nice node/29637, in the Drupal site running Services and the XMLRPC server, from another site, say with the devel module installed, type the following into an execute PHP box and hit Enter:

    $node = xmlrpc('http://empleos.mentor/services/xmlrpc', 'node.load', 29637, array());
    if (xmlrpc_error()) {
    $error_num = xmlrpc_errno();
    $error = xmlrpc_error();
    print_r ($error);
    }
    print_r($node);

    Notice the need for the not so optional second parameter, the fields specifier: to get all fields from the node.load service, you need to specify an empty array as second argument (nid as first) to avoid an error message complaining about a missing second argument.

  5. You should be rewarded with something like the following:

    Array
    (
    [nid] => 29637
    [vid] => 29741
    [type] => story
    [status] => 1
    [created] => 1203440236
    [changed] => 1203440236
    [comment] => 2
    [promote] => 0
    [sticky] => 0
    [revision_timestamp] => 1203440236
    [title] => Welcome to Drupal Sandbox
    [body] =>

    This is the Drupal Sandbox! Enjoy!

    [teaser] => This is the Drupal Sandbox! Enjoy!

    [log] =>
    [format] => 1
    [uid] => 2
    [name] => victorkane
    [picture] =>
    [data] => a:4:{s:7:"contact";i:0;s:14:"tinymce_status";s:4:"true";s:14:"picture_delete";s:0:"";s:14:"picture_upload";s:0:"";}
    [0] =>
    [last_comment_timestamp] => 1203440236
    [last_comment_name] =>
    [comment_count] => 0
    [taxonomy] => Array
    (
    )

    [files] => Array
    (
    )

    [body_value] => This is the Drupal Sandbox! Enjoy!

    )

  6. Now to see about adding some kind of security, and checking out the other services
  7. Then to see about checking out the other protocols, like REST and SOAP