0

I have a custom service that I created to do some stuff with users. I want to be able to GET and DELETE users by email address because I may not know the uid.

I have the service set up now. It works through Postman, but through the actual client, it returns a 406 error because of the .com in the email.

How do I pass the email to the service if not through the URL?

This is the definition of the service.

'retrieve' => array(
    'help' => 'Retrieve a user',
    'file' => array(
        'type' => 'inc',
        'module' => 'user_service',
        'name' => 'user_service',
    ),
    'callback' => '_my_user_resource_retrieve',
    'access callback' => '_my_user_resource_access',
    'access arguments' => array('view'),
    'access arguments append' => true,
    'args' => array(
        array(
            'name' => 'email',
            'type' => 'int',
            'description' => 'The email of the user to retrieve.',
            'source' => array('param' => 'email'),
            'optional' => false,
        ),
    ),
),

The callback function is the following.

function _my_user_resource_retrieve($mail) {
  return user_load_by_mail($mail);
}
3
  • 1
    Can you post some code example so that we can help you? Nov 1 '18 at 7:39
  • The code has a double return?
    – Kevin
    Nov 1 '18 at 14:22
  • That was a typo on my part. Nov 1 '18 at 14:24
0

Apparently Params are only for index functions. So you need to implement an index function, something like this from the user_resources.inc file in the Services module:

'index' => array(
    'help' => 'List all users',
    'file' => array('type' => 'inc', 'module' => 'services', 'name' => 'resources/user_resource'),
      'callback' => '_user_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',
          '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_user_index_page_size', 20),
          'source' => array('param' => 'pagesize'),
        ),
        array(
          'name' => 'options',
          'optional' => TRUE,
          'type' => 'array',
          'description' => 'Additional query options.',
          'default value' => array(
            'orderby' => array(
              'created' => 'DESC'
            )
          ),
          'source' => array('param' => 'options'),
        ),
      ),
      'access arguments' => array('access user profiles'),
      'access arguments append' => FALSE,
    ),
  ),

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.