Our Drupal system has the Services module enabled and is able to return nodes as json using the following url format


But I want to retrieve a node using the URL alias I set in the URL path settings tab. I hoped the following would work


But it does not. Is there a way to configure Drupal/Services to fetch nodes by that URL rather than the node id?

2 Answers 2


In Service Module API, Some hooks are presents to help you. You need to alter or add your own implementation of this service.

The second link is a file where you have the default service implementation. You can try to alter this configuration with your own by using "hook_services_resources_alter".

I can't test but you can try and custom this snippet :

function YOUR_MODULE_services_resources_alter(&$resources, &$endpoint) {
    $['node']['operations']['retrieve']['callback'] = '_your_retreive_method';
    $['node']['operations']['retrieve']['args']     = array(
        'name' => 'node_alias',
        'optional' => FALSE,
        'source' => array('path' => 0), // Put your path index here
        'type' => 'string',
        'description' => 'The alias node to get',

function _your_retreive_method($node_alias){
    // transform your alias to nid
    $path   = drupal_get_normal_path($node_alias);    
    if($path !== $node_alias && ctype_digit($nid = str_replace('node/','',$path))){
        return _node_resource_retrieve($nid);
    return false;

Links :

  • Thanks - this helped get me started. Unfortunately it doesn't work with multi-part aliases, which is a pretty serious limitation. (my-alias will work but not about-us/my-alias.) I've remedied this by converting the slashes on the client end and then reverting them in my callback function. I would rather send the alias as a parameter in a query, but couldn't implement it successfully. Nov 3, 2015 at 17:21
  • 1
    Here's a gist that handles multi-part aliases, provided the slashes are converted in the request: gist.github.com/laradevitt/6ab86bf7ebbd3215b20b Nov 3, 2015 at 17:39

Payou's answer worked for me with some additions. In the YOUR_MODULE_services_resources_alter function I also needed to specify a custom access function:

  $resources['node']['operations']['retrieve']['access callback'] = '_YOUR_MODULE_node_resource_access';
  $resources['node']['operations']['retrieve']['access arguments append'] = TRUE;

And add the access function:

function _YOUR_MODULE_node_resource_access($op, $node_alias)
  $path = drupal_get_normal_path($node_alias[0]);
  if ($path !== $node_alias && ctype_digit($nid = str_replace('node/', '', $path))) {
    return _node_resource_access($op, array($nid));
  return services_error(t('Content could not be found.'), 404);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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