I am using Drupal 7 to develop a REST API to create an iPhone app. The basic feature for this app user login and logout process. I am using the User module. The authentication process involved is session authentication. JSON is the output format used for the API.

How do I customize the JSON output from the login service? I am getting a bunch of other information which I don't require. I am not sure how to add more tags to the JSON format. Can anyone point me to the files where the information is?

For example, for a wrong username and password I get the following output:

Status 401 Unauthorized - Wrong username or password

["Wrong username or password."]

I would like to change the output to have something like {status: 0, message: 'Wrong username and passowrd'}.

Can anyone help me?

closed as too broad by kiamlaluno Apr 22 '18 at 9:25

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • As an aside, when developing a RESTful API I would always advocate bypassing those provided by Services and writing one's own. That way it is a lot easier to add abstraction to the API. The ones provided by Services are very low level and can be hard to work with. Field values, for example, are in their raw form. – Alfred Armstrong Aug 20 '14 at 10:23

Use this for errors:

 * Implements hook_rest_server_execute_errors_alter().
 * Reformat error output.
function up_coaching_rest_rest_server_execute_errors_alter(&$error_alter_array, $controller, $arguments) {
  $error_alter_array['body_data'] = array(
    'success' => FALSE,
    'error' => $error_alter_array['body_data'],

For success output you need clone needed resources from user resource definition.

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