1

We use Drupal 7 and the Service (Version 3) module. First we created a view using a date with a "between operator" as a filter, which works fine. Then we added a service view as .json format inn which we try to pass that date operator in the query string of it, but we cannot get that to work.

The query string we are using looks similar to this example:

http://example.com/drupal/api(endpoint)/sampleview.json?field_invoice_date_value<='2013-12-31'&field_invoice_date_value>='2013-11-31'

To produce the output of the view in format, we used the (amazing!) Services Views module. We added the service view path to the services resource. As mentioned above, the date filtering is working fine in the view (as confirmed by our testing of the view, without using JSON). But if we try using JSON then the between operator for the date is for unknown reasons not (yet) working.

Below are 5 screenshots to further explain what we're trying to implement (and what we got to work so far).

1. Service View

enter image description here

2. Date filter

enter image description here

3. View output

enter image description here

4. Adding service view as service resource

enter image description here

5. JSON query string variations

http://web.com/drupal/api[endpoint name]/chart(view service pathname).json?field_invoice_date_value>=2013-11-01&field_invoice_date_value_1<=2013-12-31

The above string is NOT working, note the filter in it like so:

"field_invoice_date_value>=2013-11-01&field_invoice_date_value_1<=2013-12-31"

Other filters are working correctly, like this one:

http://web.com/drupal/api[endpoint name]/chart(view service pathname).json?facility_name_value='test'

Since we need the JSON output using that 'between date', we also tried this variation, which is NOT working either:

http://web.com/drupal/api[endpoint name]/chart(view service pathname).json?field_invoice_date_value='20131210--20131213'

When testing with the string above, we received the following error message too:

"Cannot create references to/from string offsets nor overloaded objects in common.inc on line 6579"

My question: Please let me know how to implement the date between operator in a JSON query string, or any other ideas you have to further debug this issue.

4
  • 1
    Hello. "is not working properly" is most useless, and yet most common problem definition in IT. Please avoid it, and instead specify what you expected, and what you got.
    – Mołot
    Commented Jan 4, 2014 at 16:13
  • I guess we need more input from your side, as Molot suggested you should have added the code used to make it more clear.Are you using services_views module?
    – arpitr
    Commented Jan 4, 2014 at 17:41
  • Thank you for comments. Sorry for short description. Actually not working properly means the output value not getting the correct way.Filtering not taken if we use ">=" in the query sting.
    – suramya
    Commented Jan 6, 2014 at 7:25
  • I have edited the question. Please check and let me know
    – suramya
    Commented Jan 6, 2014 at 8:28

2 Answers 2

0

OK, below is what appears to be the solution for it ... We need to pass the query string as follows (all string, sorry for the formatting ...):

http://web.com/drupal/api[endpoint name]/chart(view service pathname).json?field_invoice_date_value[min][year]=2013&field_invoice_date_value[min][month]=12&field_invoice_date_value[min][day]=1&field_invoice_date_value[max][year]=2014&field_invoice_date_value[max][month]=1&field_invoice_date_value[max][day]=1

Things to notice in what is shown above:

  1. No (more) <= or >= (can't use that in such JSON string).
  2. Use notations like [min][month], [max][day], etc. instead (rather self explaining ... if you know about this syntax of course).

Done, works as designed ...

1
  • How can I use the same thing in content post date
    – Shabir A.
    Commented Oct 16, 2015 at 15:31
0

I was having the same exact problem, I solved it by creating a views using views datasource module. I created json display for my view and used post date in contextual filters. I also enabled Views Contextual Range Filter module.

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.