hook_menu access argument returns 3 instead of data I am trying to access an api that I wrote, with an access that is limited to administrators only.

My code is:

mymodule_menu() {
/**
 * Create api callback to return list of users in a give site
*/
  $items['api/v1/userslist'] = array(
    'type' =&gt; MENU_CALLBACK,
    'page callback' =&gt; 'mymodule_api_userslist',
    'access arguments' =&gt; array('administer permissions'),
    'delivery callback' =&gt; 'mymodule_json',
  );

  return $items;


this just return the value "3" for no reason.

If I remove access argument and put         'access callback'   =&gt; TRUE,
everything is working. So it is a problem with the permission.

Any ideas?

function mymodule_json($data) {
  if (isset($data['error'])) {
    drupal_add_http_header('Status', '400 Bad Request');
  }

  echo drupal_json_output($data);
}
Your delivery callback is not right. The default delivery callback is drupal_deliver_html_page($page_callback_result).

From that page:


  $page_callback_result: The result of a page callback. Can be one of:
  
  
  NULL: to indicate no content.
  An integer menu status constant: to indicate an error condition.
  A string of HTML content.
  A renderable array of content.
  


So there is no such thing as $data['error']. You are probably encoding the error code 3. 

In the default callback they catch integers as errors:

// Menu status constants are integers; page content is a string or array.
if (is_int($page_callback_result)) {
  ...
}


You might want to do the same:

function mymodule_json($data) {
  if (is_int($data)) {
    drupal_add_http_header('Status', '400 Bad Request');
  }

  echo drupal_json_output($data);
}