The 'note resource' example does a fine job of demonstrating a CRUD pattern implementation, but I do not see any examples for how to implement a targeted action nor a relationship. I only see one comment added by a french developer mentioning a gotcha about targeted action implementations on this page:
http://drupal.org/node/783254 (the 'Working with REST server' page)

any other examples to be found?

(Working in Services 3.0-beta2 in D6)

Comments

bsenftner’s picture

Added info:

I love the examples given in notes.js, such as:

 var noteapi = {
    'apiPath': '/js-api/note'
  };

  // REST functions.
  noteapi.create = function (note, callback) {
    $.ajax({
      type: "POST",
      url: this.apiPath,
      data: JSON.stringify(note),
      dataType: 'json',
      contentType: 'application/json',
      success: callback
    });
  };

  noteapi.retreive = function (id, callback) {
    $.ajax({
      type: "GET",
      url: this.apiPath + '/' + id,
      dataType: 'json',
      success: callback
    });
  };

What would the equivalent to call a targeted action? (I've located the resource definitions in 'user_resource.inc', which give examples of defining a targeted action, but I still don't know how to call a targeted action, like how notes.js demonstrates calling each of the CRUD operations.)

kylebrowning’s picture

Status: Active » Fixed

You call a targeted action by POST to the url, comments resource has a great example of this

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

chmhalford’s picture

This issue is almost a year old, but it was the first result on Google when I tried searching for "drupal services targeted actions". After a bit more Googling, I found this page: http://artclutch.com/sites/all/modules/services/tests/services_test_resource/services_test_resource.module

The targeted action example on there is as follows:

function services_test_resource_services_resources() {
  return array(
    'services_test' => array(
      'retrieve' => array(
        'callback' => '_services_test_resource_retrieve',
        'args' => array(
          array(
            'name' => 'arg1',
            'optional' => FALSE,
            'source' => array('path' => 0),
            'type' => 'int',
            'description' => 'Test argument 1.',
          ),
        ),
        'access callback' => '_services_test_resource_access',
        'access arguments' => array('view'),
        'access arguments append' => TRUE,
      ),
      'actions' => array(
        'action_retrieve' => array(
          'access callback' => '_services_test_resource_access',
          'access arguments' => array('view'),
          'access arguments append' => TRUE,
          'callback' => '_services_test_resource_action_retrieve',
          'args' => array(
            array(
              'name' => 'arg1',
              'optional' => FALSE,
              'source' => array('path' => 0),
              'type' => 'int',
              'description' => 'Test argument 1.',
            ),
          ),
        ),
      ),
      'targeted_actions' => array(
        'test' => array(
          'access callback' => '_services_test_resource_access',
          'access arguments' => array('view'),
          'access arguments append' => TRUE,
          'callback' => '_services_test_resource_targeted_action_test',
          'args' => array(
            array(
              'name' => 'arg1',
              'optional' => FALSE,
              'source' => array('path' => 0),
              'type' => 'int',
              'description' => 'Test argument 1.',
            ),
          ),
        ),
      ),
    ),
  );
}
bsenftner’s picture

I guess I should have updated my post here. I figured it out a while a go, and posted at my personal site an example demonstrating all CRUD + Relationship + Action operations:
http://www.blakesenftner.com/Services-3-examples

generalredneck’s picture

Version: 6.x-3.0-beta2 » 8.x-4.x-dev
Issue summary: View changes

I know this is an old thread, but it's the first thing that comes up via Google. A great example is also the Node service resource. Take a look at the following: http://cgit.drupalcode.org/services/tree/resources/node_resource.inc?h=7...

generalredneck’s picture

Version: 8.x-4.x-dev » 7.x-3.x-dev