I'm in the process of migrating our old ColdFusion app which returned data via JSON. I have installed the JSON Server and have set up a views that limits on a taxonomy term.
I can play around with the form on '/admin/build/services/browse/views.get' and get back the views and data that I want, however when I try and use the same variables from a JSON request, I can't get the same results. Specifically I can't get the services to pay attention to the 'fields' and 'args' arguments
$.post('/services/json', {'method':'views.get','view_name':'place_sets','fields':'nid'}, function(d,r) { console.info(d); }, 'json')
returns an array of null objects.
If I take away the value from fields, i get actual results.
$.post('/services/json', {'method':'views.get','view_name':'place_sets','fields':''}, function(d,r) { console.info(d); }, 'json')
I also am not able to pass in the taxonomy term i want in 'args' to limit the datasets.
So for whatever reason, I can't seem to use 'args' or 'fields', but other fields available, namely 'limit' and 'offset' do work properly.
If you can help AT ALL, it would be much appreciated. I have been searching this site for the past two weeks and trawling IRC with no luck or hints of a direction I should take.
Comments
Followup
Well, I've started to fix the problems in JSON_server so that it is working. Basically, fields and args require arrays and JSON_server was not handling that fact. I've changed it so it'll process arguments based on the type that they are.
I can now limit which fields are being returned. However, I still can't pass in an argument in the 'args' field without getting a blank dataset.
I'm using the 'views.get' service and my view takes a single argument based on a Taxonomy term.
Here is the array that is being passed into $result = services_method_call($method['#method'], $args);
If the the third element, args[2], is blank, it will return a dataset, however, to make this useful, it needs to be able to filter properly. This behaviour works properly in my view as seen in a web-browser.
/places/ shows all. A blank argument in the JSON request shows all of the buildings. GOOD.
/places/academic shows the (currently) 3 tagged buildings I have. The JSON request returns 0 results. BAD.
('places' here is the path to my view method which I'm calling in via Services)
If anyone can point me in the direction of resolving this issue, I'd be very grateful.
On a whim, I added a print_r(
On a whim, I added a print_r( $args ) to services_method_call in services/services.module and recieved the following array:
Apart from the offset and limit fields being different, what I'm passing in looks to be the same that is handled by the Drupal browser preview of the views.get service-the Services module at least.
/admin/build/services/browse/views.get
I was hoping to find some kind of transformation that was munging the 'args' field to be handled properly, but doesn't seem like it's happening, which makes my problem even more aggravating.
Hopefully, I won't have to dig too much deeper.
(I am new to Drupal, so I may be doing something non-Drupally).
solved
Fixed by changing 'fields' to 'fields[]' and 'args' to 'args[]' on JSON post. Also, if you specify specific fields, it must contain the field you're searching on as well.
That last one was a forehead slapper. And I learned a little Drupal along the way.