Argument list for remote calls using API key in call

Events happening in the community are now at Drupal community events on www.drupal.org.
pkrecker's picture

Regarding Services v. 1.3.2.12 (from tag at head of services.module, not sure which version of whole module I'm on).

I'm trying to hack the incomplete module http://drupal.org/project/casetracker_services which provides a client interface to the Case Tracker module via the Services module. It implements API keys, but only works when the API keys checkbox is disabled (along with the sessid checkbox) in the Services settings. Namely, the problem is that the developer designed it to use API keys, but generates the remote calls without including the necessary key information (they key is passed in the URL instead).

So, my question is, what is the argument list for remote calls using just the API key but no sessid? I looked at the documentation at http://drupal.org/node/109782 which was basically useless. From the source code I can find that I need an API key (presumably copied from the Services control panel), the domain name (client or server?), a time stamp (return from time()?), and a nonce (how to generate??).

So is the argument list for the call to xmlrpc() of the format (url,action,API key, domain name, timestamp, nonce, function-specific arguments)? If so, how, in particular, should the timestamp and nonce be generated?

Thanks,
Patrick

Comments

Short example

wulff's picture

One of my modules implements hook_service() to provide the method 'module.method' via XML-RPC.

<?php
function module_service() {
  return array
    array(
     
'#method' => 'module.method',
     
'#callback' => 'module_method',
     
'#args' => array(
        array(
         
'#name' => 'Foo',
         
'#type' => 'string',
         
'#optional' => FALSE,
         
'#description' => t('Description of argument.'),
        )
      ),
     
'#return' => 'array',
     
'#help' => t('Returns an array of data.'),
    )
  );
}

function
module_method($arg) {
  return array(
   
'arg' => $arg,
   
'foo' => 'bar',
  );
}
?>

To call this method, I first create an API key at 'admin/build/services/keys' (make sure to include the domain name).

Now I can use the API key to create a hash and call the method via XML-RPC (in this case using the Drupal xmlrpc() function).

<?php
$api_key
= '80295e7a571adef0ffffb22e68230cf0';
$method  = 'module.method';

// generate services hash
$timestamp = time();
$nonce = user_password();
$hash = hash_hmac('sha256', $timestamp .';'. $_SERVER['HTTP_HOST'] .';'. $nonce .';'. $method, $api_key);

// get result using xmlrpc
$result = xmlrpc('http://example.com/services/xmlrpc', $method, $hash, $_SERVER['HTTP_HOST'], "$timestamp", $nonce, session_id(), 'argument');
?>

Services

Group organizers

Group categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: