I'm triying to setup a simple API to retrieve nodes and act on them.
The default retrieve and index actions work fine, but when triying to define a custom targeted action i can't get it to work and receive 404 errors when posting.
I currently have this:
/api/movie/ -> List all nodes
/api/movie/794 -> Gets node id 794
I need to do certain actions, like getting/generating the movie url, or "buy" the movie, so i'm triying to create the following:
/api/movie/794/play
/api/movie/794/buy
This is my code:

'targeted_actions'=>array(
            'buy' => array(
                'help' => 'Buy a movie',
                'file' => array('file' => 'inc', 'module' => 'api400'),
                'callback' => '_api400_buy',
                'access arguments' => array('view'),
                'access arguments append' => TRUE,
                'args' => array(
                    array(
                        'name' => 'id',
                        'type' => 'int',
                        'description' => 'The id of the movie to buy',
                        'source' => array('path' => '0'),
                        'optional' => FALSE,
                    ),
                    array(
                        'name' => 'test',
                        'type' => 'string',
                        'description' => 'Currency Code',
                        'source' => array( 'path' => 1 ),
                        'optional' => TRUE,
                    ),
                ),
            ),
            'play' => array(
                'help' => 'Play a movie',
                'file' => array('file' => 'inc', 'module' => 'api400'),
                'callback' => '_api400_play',
                'access arguments' => array('view'),
                'access arguments append' => TRUE,
                'args' => array(
                    array(
                        'name' => 'id',
                        'type' => 'int',
                        'description' => 'The id of the movie to play',
                        'source' => array('path' => '0'),
                        'optional' => FALSE,
                    ),
                ),
            )
        ),

and for the "retrieve" action:

      'retrieve' => array(
        'help' => 'Retrieves a movie',
        'file' => array('file' => 'inc', 'module' => 'api400'),
        'callback' => '_api400_retrieve',
        'access callback' => '_api400_access',
        'access arguments' => array('view'),
        'access arguments append' => TRUE,
        'args' => array(
          array(
            'name' => 'id',
            'type' => 'int',
            'description' => 'The id of the movie to get',
            'source' => array('path' => '0'),
            'optional' => FALSE,
          )
        ),
      ),

When posting to /movie/794/play i'm getting a 404 error (Could not find the controller)
And there's nothing relevant in the system logs.

Thanks for your time

Comments

ygerasimov’s picture

Can you try to change your path position to integer value? i.e. 'path' => 0, instead of 'path' => '0'.

I will check the code and make sure we do conversion to integer. But if it is not in place, this might help.

ygerasimov’s picture

Status: Active » Fixed

Committed some code to convert 'path' position to integer.

Status: Fixed » Closed (fixed)

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