1

I have a mobile app, which calls a legacy system's HTTP REST interface. Now I replaced the legacy system with Drupal and Services module. I forgot setting field machine name to match mobile app client, however, there is no chance to modify the mobile app. So, as I asked in the title: is there a way to change the fields' names of the JSON generated by Services module?

1

You can use hook_services_request_postprocess_alter(): http://cgit.drupalcode.org/services/tree/docs/services.alter.api.php?h=7.x-3.x

For example, say you wanted to replace the node title property with nodeTitle when a node is being retrieved, you can do so like this:

/**
 * Implements hook_services_request_postprocess_alter().
 */
function my_module_services_request_postprocess_alter($controller, $args, &$result) {
  if ($controller['callback'] == '_node_resource_retrieve') {
    $result->nodeTitle = $result->title;
    unset($result->title);
  }
}
  • 1
    If using Services Views module, we can "set custom value key" in the field output configuration form to make it. – fishfree Oct 20 '16 at 2:20

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.