Website Design and Mobile Application Development in Austin, Texas

Passing Date Values to Drupal’s REST Service Views


Passing Date Values to Drupal’s REST Service Views

We had a situation recently with a Drupal installation that we have been working on.  We were building a REST service on a Drupal installation using the Drupal Service Views module.  We built a view that allows an AngularJS client to perform listing and searching on a Drupal installation that contains inventory objects.  The client in this case is building a site that will allow their sales people the ability to review inventory that is available for sale

Everything was going great with the filtering until we got to the piece where a sales person can filter all inventory based on a date that the item was made available.  In our service view, we had created a filter on the date field with the machine id of ‘field_expected_date_of_return_value’.  When we attempted to send a series of GET requests to the server with a value for the field, we would get a 500 server error.  The urls that didn’t work for us were:

http://domain.com/rest/views/inventory_list?field_expected_date_of_return_value_1=2010-01-01
http://domain.com/rest/views/inventory_list?field_expected_date_of_return_value_1=01/01/2010
http://domain.com/rest/views/inventory_list?field_expected_date_of_return_value_1[min]=01/01/2010
...

Each of these calls would result in an error in the apache logs:

PHP Fatal error:  Cannot create references to/from string offsets nor overloaded objects in /var/www/html/includes/common.inc on line 6703

In the end, after stepping through the code to look at what common.inc was expecting, we found that our format was incorrect.  I did some google searching and didn’t see anyone mention this issue, so hopefully this post will help someone out.  This is the correct format of the url.  Note: In our case, our date granularity is set to month, day, and year on the field, so we had to provide all three values.  You must pass a multidemensional array with the value/month, value/year, and value/day properties.

http://domain.com/rest/views/inventory_list?field_expected_date_of_return_value_1[value][month]=1&field_expected_date_of_return_value_1[value][year]=2013&field_expected_date_of_return_value_1[value][day]=1
0
Posted on May 6th, by Peter in Tutorials.

Leave a Reply

Your email address will not be published. Required fields are marked *