0

I'm just trying to create custom rest service action but I can't get it. I have created end_point called "testing". Whenever I try to post the data it shows access denied for authenticated user. Where I'm going wrong?

The steps I followed:

I can't get the name. What I expecting is the post call must return the username "abc" according to my below function.

function my_module_service_services_resources() {        
    return array(
      'test' => array(
         'actions' => array(
            'username' => array(
              'check' => array(
                'help' => 'Checks username for uniqueness',
               'callback' => 'test_module_username_check',
               'access callback' => 'my_module_service_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 test_module_username_check($username) {
    return $username;
  }


  function my_module_service_access() {
    return true;
  }
  • Make sure Session authentication checkbox is checked on your service endpoint, and flush all the caches. That should fix it. – tyler.frankenstein May 10 '16 at 20:17
  • Thanks for the reply. Yes @tyler. I have checked the session authenticated. – user15837 May 11 '16 at 5:53
0

After debugging the action method of user/login (default in services module), I found where I went wrong. In my code, I added extra array called check inside username. When I remove that array everything is going well. Here the updated code

function my_module_service_services_resources() {        
    return array(
      'test' => array(
         'actions' => array(
            'username' => array(
              'help' => 'Checks username for uniqueness',
              'callback' => 'test_module_username_check',
              'access callback' => 'my_module_service_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 test_module_username_check($username) {
    return $username;
  }


  function my_module_service_access() {
    return true;
  }

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.