I've declared a related resource using the services relationships method (using the comments.resource as a basis). The use case is for pulling a summary weather report from a weather site. Both the site and the summary are resources, though a summary only makes sense in the context of a site. The service appears in the browser, but submitting via the services browser gives a 404 Not found. Ditto for calling the service via curl.

A curl call to http://example.com/api/v2/site/100105/summary/2010/01.xml actually invokes the correct handler, passing correct arguments but the service already returns a 404 even before the _weather_services_site_summary_index() method is invoked.

Where should I look to understand why the service definition is sufficient to show the correct data in the services browser but not to actually invoke the service?

function weather_services_service_resource() {
  return array(
    'site' => array(
      '#retrieve' => array(
        '#callback' => '_weather_services_site_retrieve',
        '#file' => array('file' => 'inc', 'module' => 'weather_services'),
        '#args' => array(
          array(
            '#name' => 'number',
            '#optional' => FALSE,
            '#source' => array('path' => 0),
            '#type' => 'int',
            '#description' => t('The site number of the Site to get'),
          ),
        ),
        '#access arguments' => array('view weather reports'),
        '#access arguments append' => TRUE,
      ),

      '#index' => array(
        '#callback' => '_weather_services_site_index',
        '#file' => array('file' => 'inc', 'module' => 'weather_services'),
        '#args' => array(),
        '#access arguments' => array('access content'),
        '#access arguments append' => TRUE,
      ),

      // Map to summary weather reports
      '#relationships' => array('summary' => _weather_services_summary_resource()),
    ), // /site resource

//snipped

function weather_services_summary_resource() {
  return array(
    '#file' => array('file' => 'inc', 'module' => 'weather_services'),
    '#callback' => 'weather_services_site_summary_index',
    '#args' => array(
      array(
        '#name' => 'year',
        '#optional' => TRUE,
        '#source' => array('path' => 2), // in context of site/{site_no}/summary/[year]/[month]
        '#type' => 'int',
        '#description' => 'Year of report',
      ),
      array(
        '#name' => 'month',
        '#optional' => TRUE,
        '#source' => array('path' => 3),
        '#type' => 'int',
        '#description' => 'Month of report',
      ),
    ),
    //'#access callback' => '_comment_resource_node_comments_access',
    '#access arguments' => array('access content'), // @todo: fix - make access weather reports
    '#access arguments append' => TRUE,
  );
}

Comments

clockworkrobot’s picture

I'm also getting nothing back from the service when I invoke a very similar request. Did you ever resolve this issue?

RESOLVED:

In my case, I was getting no return values in the actual service because my model which formatted output was being fed an array by my callback function, but the model was expecting an object. By casting the array values from the callback to an object the service now performs correctly for me.