5

The resource "username" appears but my action does not appear in the list in services admin. Response to a POST is HTTP/1.1 404 Not found: Could not find resource username.

I replaced my module name with "module" here:

function module_services_resources() {
  return array(
    'username' => array(
      'check' => array(
        'help' => 'Checks username for uniqueness',
//       'file' => array('file' => 'inc', 'module' => 'noteresource'),
       'callback' => '_module_username_check',
       'access callback' => '_module_resource_access',
        'access arguments' => array('view'),
        'access arguments append' => TRUE,
        'args' => array(
          array(
            'name' => 'username',
            'type' => 'string',
            'description' => 'The username to check',
            'source' => 'data',
            'optional' => FALSE,
          ),
        ),
      )
    )
  );
}


function _module_resource_access($op, $args) {
  return TRUE;
}


function _module_username_check($data) {

  $username = $data->username;

  $user = db_fetch_object(db_query("SELECT uid FROM users WHERE name=':username'", array(":username" => $username)));

  return $user;
}
5

Actions outside the normal CRUD roster must be wrapped in an array under the key 'actions'

function module_services_resources() {
  return array(
    'actions' => array(
      'username' => array(
...
  • For future readers (I don't know older versions, but) service 3.x provides both actions and targeted_actions to achieve this task. The former are performed directly on the resource type, the latter on a individual resource. So take care of this when choosing (read docs/services.services.api.php to get further info about this). – Pierpaolo Cira Jan 13 '17 at 13:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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