1

I've stumbled upon some limitations of the services module. I wanted to create the following endpoints:

public/events/
public/events/categories
public/events/resources
public/blogs/

I wanted to place all the above under a single endpoint with path "public/". However, in the hook_services_resources the following is invalid:

/**
 * Implements hook_services_resources().
*/
function kw_api_services_resources() {
  $service_resources = 
   'event/categories' => array(
      'operations' => array(
        'index' => array(

I ended up using two endpoints public/events and public/blogs. Is there a way to get around this? Meaning to user deeper than 1 level URLs.

1 Answer 1

0

Example from the module itself, the child is defined in the relationships:

'events' => array(
  'operations' => array(
    'retrieve' => array(
      'file' => array('type' => 'inc', 'module' => 'services', 'name' => 'resources/node_resource'),
      'callback' => '_node_resource_retrieve',
      'args' => array(
        array(
          'name' => 'nid',
          'optional' => FALSE,
          'source' => array('path' => 0),
          'type' => 'int',
          'description' => 'The nid of the node to get',
        ),
      ),
      'access callback' => '_node_resource_access',
      'access arguments' => array('view'),
      'access arguments append' => TRUE,
    ),
    'create' => array(
      'file' => array('type' => 'inc', 'module' => 'services', 'name' => 'resources/node_resource'),
      'callback' => '_node_resource_create',
      'args' => array(
        array(
          'name' => 'node',
          'optional' => FALSE,
          'source' => 'data',
          'description' => 'The node data to create',
          'type' => 'array',
        ),
      ),
      'access callback' => '_node_resource_access',
      'access arguments' => array('create'),
      'access arguments append' => TRUE,
    ),
    'update' => array(
      'file' => array('type' => 'inc', 'module' => 'services', 'name' => 'resources/node_resource'),
      'callback' => '_node_resource_update',
      'args' => array(
        array(
          'name' => 'nid',
          'optional' => FALSE,
          'source' => array('path' => 0),
          'type' => 'int',
          'description' => 'The nid of the node to get',
        ),
        array(
          'name' => 'node',
          'optional' => FALSE,
          'source' => 'data',
          'description' => 'The node data to update',
          'type' => 'array',
        ),
      ),
      'access callback' => '_node_resource_access',
      'access arguments' => array('update'),
      'access arguments append' => TRUE,
    ),
    'delete' => array(
      'file' => array('type' => 'inc', 'module' => 'services', 'name' => 'resources/node_resource'),
      'callback' => '_node_resource_delete',
      'args' => array(
        array(
          'name' => 'nid',
          'optional' => FALSE,
          'source' => array('path' => 0),
          'type' => 'int',
        ),
      ),
      'access callback' => '_node_resource_access',
      'access arguments' => array('delete'),
      'access arguments append' => TRUE,
    ),
    'index' => array(
      'file' => array('type' => 'inc', 'module' => 'services', 'name' => 'resources/node_resource'),
      'callback' => '_node_resource_index',
      'args' => array(
        array(
          'name' => 'page',
          'optional' => TRUE,
          'type' => 'int',
          'description' => 'The zero-based index of the page to get, defaults to 0.',
          'default value' => 0,
          'source' => array('param' => 'page'),
        ),
        array(
          'name' => 'fields',
          'optional' => TRUE,
          'type' => 'string',
          'description' => 'The fields to get.',
          'default value' => '*',
          'source' => array('param' => 'fields'),
        ),
        array(
          'name' => 'parameters',
          'optional' => TRUE,
          'type' => 'array',
          'description' => 'Parameters array',
          'default value' => array(),
          'source' => array('param' => 'parameters'),
        ),
        array(
          'name' => 'pagesize',
          'optional' => TRUE,
          'type' => 'int',
          'description' => 'Number of records to get per page.',
          'default value' => variable_get('services_node_index_page_size', 20),
          'source' => array('param' => 'pagesize'),
        ),
      ),
      'access arguments' => array('access content'),
    ),
  ),
  'targeted_actions' => array(
    'attach_file' => array(
      'help' => 'Upload and attach file(s) to a node. POST multipart/form-data to node/123/attach_file',
      'file' => array('type' => 'inc', 'module' => 'services', 'name' => 'resources/node_resource'),
      'callback' => '_node_resource_attach_file',
      'access callback' => '_node_resource_access',
      'access arguments' => array('update'),
      'access arguments append' => TRUE,
      'args' => array(
        array(
          'name' => 'nid',
          'optional' => FALSE,
          'source' => array('path' => 0),
          'type' => 'int',
          'description' => 'The nid of the node to attach a file to',
        ),
        array(
          'name' => 'field_name',
          'optional' => FALSE,
          'source' => array('data' => 'field_name'),
          'description' => 'The file parameters',
          'type' => 'string',
        ),
        array(
          'name' => 'attach',
          'optional' => TRUE,
          'source' => array('data' => 'attach'),
          'description' => 'Attach the file(s) to the node. If FALSE, this clears ALL files attached, and attaches the files',
          'type' => 'int',
          'default value' => TRUE,
        ),
        array(
          'name' => 'field_values',
          'optional' => TRUE,
          'source' => array('data' => 'field_values'),
          'description' => 'The extra field values',
          'type' => 'array',
          'default value' => array(),
        ),
      ),
    ),
  ),
  'relationships' => array(
    'resources' => array(
      'file' => array('type' => 'inc', 'module' => 'services', 'name' => 'resources/node_resource'),
      'help'   => t('This method returns files associated with a node.'),
      'access callback' => '_node_resource_access',
      'access arguments' => array('view'),
      'access arguments append' => TRUE,
      'callback' => '_node_resource_load_node_files',
      'args'     => array(
        array(
          'name' => 'nid',
          'optional' => FALSE,
          'source' => array('path' => 0),
          'type' => 'int',
          'description' => 'The nid of the node whose files we are getting',
        ),
        array(
          'name' => 'file_contents',
          'type' => 'int',
          'description'  => t('To return file contents or not.'),
          'source' => array('path' => 2),
          'optional' => TRUE,
          'default value' => TRUE,
        ),
        array(
          'name'         => 'image_styles',
          'type'         => 'int',
          'description'  => t('To return image styles or not.'),
          'source'       => array('path' => 3),
          'optional'     => TRUE,
          'default value' => FALSE,
        ),
      ),
    ),
  ),

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.