1

Is it possible to edit/customize the default output we get using Services Module ?

For example I want to edit output which I get from this URL : http://example.com/api/node/39

And I want to edit output of this URL : http://example.com/api/user/39

OR is there any way to create a View for single user profile ?

2

Using the Services API this is possible: http://cgit.drupalcode.org/services/tree/docs/services.alter.api.php?h=7.x-3.x

/**
 * Implements hook_services_request_postprocess_alter().
 */
function example_services_request_postprocess_alter($controller, $args, &$result) {
  switch ($controller['callback']) {
    case '_node_resource_retrieve':
      $result->foo = 'bar';
      break;
    case '_user_resource_retrieve':
      $result->bar = 'chew';
      break;
  }
}

You could use the Views JSON module (a sub module of the Views datasource module) to build a View with a User ID contextual filter, and then return the field(s) you want for that particular user.

0

Are you aware of the Services Views module?

It allows you to create a services path and you can control the output with Views.

From the question:

Is there any way to create a View for single user profile ?

From the module:

Executing view via views resource

After enabling "views" resource in your services endpoint you can do GET request to:

http://example.com/<endpoint path>/views/<view name>

This will execute a view and pass results.

Possible arguments:

  • display_id: views display
  • args: array of view arguments
  • filters: array of view filter values
  • offset: views offset
  • limit: limit views number of results
  • format_output: boolean whether we would like to get themed view or data

This module supports Views arguments (args), which are known as 'Contextual filters' in the Views UI. So if you create a contextual filter for the uid, and you pass the args in your request it should work.

Something like http://example.com/rest/views/users?args[uid]=5 or http://example.com/rest/views/users?args[0]=5 probably works.

Please note that this method does not alter the output of the existing services endpoints, but creates a new path.

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.