It turns out I had to write my own module that provides a menu callback entry. My favorites_api.module
file looks like this:
/**
* Implements hook_menu().
*/
function favorites_api_menu() {
$items['node/%/favorite/%'] = array(
'title' => 'Mark as favorite',
'page callback' => 'favorites_api_toggle_favorite',
'page arguments' => array(1, 3),
'access callback' => 'user_access',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Callback for above menu entry
*/
function favorites_api_toggle_favorite($entity_id, $action) {
$favorites_flag = flag_get_flag('favorites') or die('no "favorites" flag defined');
$favorites_flag->flag($action, $entity_id);
// error handling and return message
// ...
}
Now I can call http://myurl/node/3/favorite/flag
to mark node 3 as favorite and http://myurl/node/3/favorite/unflag
to unmark it.
Having to write a menu entry to create a custom URL action is a bit misleading, though...