I have a view that accepts a contextual filter in order to return the correct results. I'm using Services 3 and Drupal 7. I'm able to create an endpoint, and retrieve the view via services. But it seems like there is no way to pass the contextual filter, because services_views only has a retrieve method (which uses GET). Does anyone know if this is possible, and if so how it can be done?
This is an already answered question, but for others browsing here in the future, I would recommend using and taking a look at the documentation at Services Views. It spells out how to pass contextual filters along with a bunch of other possible arguments, and it has a demo video and shows examples.
If you have to use multiple value in your contextual filter, I suggest doing the following :
- Create your Contextual filter (in my case : nid)
- Click on "Provide a default value" and set the type as PHP Contextual Filter expect a string with multiple value separated by a + or a comma.
return str_replace("|", "+", $_GET['nid']);
- In the "More" section, check "Allow multiple values".
Now when calling your service, provide your contextual filters that way : .../my_service?nid=1|2|3
I was able to get a contextual filter with Drupal Services by: 1) enabling the 'Views Contextual Filter Query' module (https://drupal.org/project/views_contextual_filter_query) 2) passing the contextual filter through the URL as a querystring.
In the contextual filter, you will have to select 'WHEN THE FILTER VALUE IS NOT AVAILABLE' -> 'Query Parameter from the URL. You will then be able to add the parameter name which you will use in the URL. This also allows you to use the + and | characters for selecting multiple filter criteria.