3

I'm trying to figure out how to pass a filter parameter on a Services rest call. I've got a node of a specific type that I'd like to access through the Services module and rest. I'm testing with FireFox RestClient and I can get all nodes of the particular type by typing

http://localhost/drupal/gpa/node/?parameters[type]=node_type

But, I'd like to be able to get one specific instance of 'node_type' that contains a specific field value. I've taken a look at node_resource.inc, but, I can't seem to make heads or tails of what I need to use as parameters. I've tried several variations that typically return no result, or, all instances of, 'node_type'.

Is it possible to filter the returned results, or, is my approach incorrect?

EDIT: If any C# programmer stumbles across this, I was able to use the Basic HTTP Authentication module to prevent unauthorized access to the view. First, as Tyler indicated, I needed to change the permissions settings. In My case, I chose a Role (Administrator).

1 Answer 1

1

The entity index resources unfortunately cannot be used to filter by field values, they can only filter by entity property values (e.g. node nid, title, type, etc). I think you have two options:

  1. create a custom service resource that uses parameters and a database query (or entity field query) to filter and return what you want
  2. use views_json (a sub module of views_datasource) to create a View with a contextual filter for your field
2
  • Tyler, thanks for the direction. I used #2 above and it worked fine. However, it does seem a bit insecure. Do you know if there is a way to secure the resulting view path so that only an admin can execute it? In actuality, I'm consuming the Rest call from a C# program, so, I'm a bit concerned that anyone can run the query given the path to the view.
    – rrirower
    Commented Jan 10, 2019 at 21:45
  • You're welcome. You can secure the View path just like you do for a regular View. On the View's configuration form, go to Page Settings -> Access, then decide what type of access control you'd like to apply to the path (e.g. Permission, Role, etc). Commented Jan 10, 2019 at 21:49

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.