I am developing a custom module, which should do things in hook_nodeapi() only if the node is being created/edited via Services. I couldn't find any data that is available at this point for deciding if the node is via Services or not.

I am aware of a possible solution, using request_uri() and deciding based on that (https://drupal.stackexchange.com/a/8568/1930), but it seems so wrong. Hardcoding the endpoint name is plain wrong. Workaround this by providing an admin interface and depend on configuration?

So, I would rather avoid the above, but couldn't come up with anything else so far. I am curious if others have had similar problems before and if there is a better solution.


The accepted answer should be used, as that is the cleanest solution. Unfortunately, I had to use a different one, which might still be useful to others so I am sharing it here: https://gist.github.com/Temaruk/5884209


I think there's a point in the system not normally telling you this, since we want to avoid any kind of coupling between the systems. Based on that I guess there's no built in way to get the information you want. Strictly speaking, you should probably consider why you are doing what you are doing, as it's not good practice.

Possible methods: You could implement a custom node resource, which hands over node creation to the regular services callback after having done

$node->creator = 'services';

or possibly:

$node_origin = &drupal_static('node_creation_tracker');
$node_origin = 'services';

after which you could retrieve this data with the same method. Implementing a resource is not a complicated process, but requires quite a bit of knowledge about services.

  • Very good point and probably the most "kitten-safe" way of doing it. Unfortunately, I had to go with a different method (updated my question with what I did)... Thanks for the nice solution! – Temaruk Jun 28 '13 at 12:08

You might be able to do something with user roles, eg, have all "real" people assigned a role in addition to just "authenticated user" and then check for that inside of nodeapi() (and then set a field inside the content to reflect that if you need this to have some permanence)

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.