Access denied for user anonymous while accessing custom table data I am trying to fetch custom table result anonymously with services but I am getting 

&lt;?xml version="1.0" encoding="utf-8"?&gt;


Access denied for user anonymous

My Code are as follow :

    function custom_data_services_resources() {
  return array(
    'getdata' =&gt; array(
      'retrieve' =&gt; array(
        'help' =&gt; 'Retrieves a data',
        'file' =&gt; array('file' =&gt; 'inc', 'module' =&gt; 'custom_data'),
        'callback' =&gt; '_get_data',
        'access callback' =&gt; TRUE,
        'args' =&gt; array(
          array(
            'name' =&gt; 'id',
            'type' =&gt; 'int',
            'description' =&gt; 'The id of the note to get',
            'source' =&gt; array('path' =&gt; '0'),
            'optional' =&gt; FALSE,
          ),
        ),
      ),
      'index' =&gt; array(
        'help' =&gt; 'Retrieves a listing of notes',
        'file' =&gt; array('file' =&gt; 'inc', 'module' =&gt; 'custom_data'),
        'callback' =&gt; '_get_data',
        'access callback' =&gt; TRUE,
        'args' =&gt; array(
          array(
            'name' =&gt; 'page',
            'type' =&gt; 'int',
            'description' =&gt; '',
            'source' =&gt; array(
              'param' =&gt; 'page',
            ),
            'optional' =&gt; TRUE,
            'default value' =&gt; 0,
          ),
          array(
            'name' =&gt; 'parameters',
            'type' =&gt; 'array',
            'description' =&gt; '',
            'source' =&gt; 'param',
            'optional' =&gt; TRUE,
            'default value' =&gt; array(),
          ),
        ),
      ),
    ),
  );
}


I tried with "X-CSRF-Token" also But no luck :(

Any help appreciated
Following up with an answer from our comments...

Here's an example custom service resource:

custom_data.module

function custom_data_services_resources() {
  $resources = array(
    'custom_data_resources' =&gt; array(
      'actions' =&gt; array(
        'getdata' =&gt; array(
          'help' =&gt; t('Gets custom data.'),
          'file' =&gt; array(
            'type' =&gt; 'inc',
            'module' =&gt; 'custom_data',
            'name' =&gt; 'custom_data.resource',
          ),
          'callback' =&gt; 'custom_data_getdata',
          'args' =&gt; array(
            array(
              'name' =&gt; 'data',
              'type' =&gt; 'array',
              'description' =&gt; 'The data dude.',
              'source' =&gt; 'data',
              'optional' =&gt; FALSE,
            )
          ),
          'access callback' =&gt; 'custom_data_access',
          'access callback file' =&gt; array(
            'type' =&gt; 'inc',
            'module' =&gt; 'custom_data',
            'name' =&gt; 'custom_data.resource',
          ),
          'access arguments' =&gt; array('access user profiles'),
          'access arguments append' =&gt; TRUE,
        ),
      ),
    ),
  );
  return $resources;
}


custom_data.resource.inc

function custom_data_getdata($data) {
  return array('foo' =&gt; $data['bar']);
}

function custom_data_access($permission) {
  return user_access($permission);
}


After that, just enable the custom resource under your endpoint's configuration and clear all of Drupal's caches. Then you can make a POST to:

?q=[my-endpoint]/custom_data_resources/getdata.json

If you need to send along custom arguments, I usually recommend a single array parameter, that way you can easily expand upon it and send as many variables/properties you need along with the payload:

{ "bar": 123 }

Which will then return to you:

{ "foo": 123 }

Don't forget to attach a header to your request with a name of X-CSRF-Token and value retrieved from: ?q=services/session/token