How to get node content of more than one node with a single call?

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
Macs's picture

Dear service group members, i am just starting with the drupal service module, hence my question might seem a bit stupid to some of you. However, I (re)searched the web and the group discussions but I wasn't able to find a solution that helped me further. I am using the REST server to retrieve a json with node information from services 6.x-3.0

I am fiddling around with the following problem:
When I do "http://mysite.com/api/node/11" i am getting a json with information that is on that node specific node such as the 'body' and in my case some location information, image and so forth
When I do "http://mysite.com/api/node" i am getting information about all nodes including title, node id and so forth but not the content that is on the nodes such as body, location, image like in the call for a single node id

My question is:
is there a way to retrieve node information such as body, location, images of more than one node or all nodes with a single call?

i greatly appreciate any suggestions

Comments

Try using a view

waldmanm's picture

If you define a view with Style:Unformatted and Row Style:Node, Services views.get method will return the entire node object for each node. Some fields are returned in some unexpected structures, e.g., cck fields, so just dump what you get and study it, or Google for more info.
The important point is to use the Node role style, not Fields. I use the Unformatted overall style since it's not going to be presented by Drupal anyways.

Micah

Thanks micah

Macs's picture

Thanks a lot micah for your quick reply. In my search for an solution I indeed came a cross that option (see: http://www.jefflinwood.com/2010/08/using-drupals-views-as-a-json-web-ser...
To be honest i am not sure whether i understood how to actually load a view using the REST Server. I was a bit unsure about how the GET url should look like since as mentioned in the link above that the view is not really an endpoint.
thanks a lot for your tip about the styles

I'm not familiar with the

waldmanm's picture

I'm not familiar with the REST server (I'm using amfphp) but I suggest you try the instructions in the post you listed with a simple view that takes no arguments. That would simplify your initial testing.

Also, try to call views.get from the services browse page (admin/build/services) with the view name of the view you defined, to see that this part works.

One other note: there are some fields for which the views module needs to do some extra DB queries and those will not be included in the returned node objects. For example, if I recall correctly, a cck field which can appear multiple times in a node will not be returned. You'll see it in the view in Drupal but not in services. For some information I ended up writing my own services methods, which is not that difficult either and gives you total control over what data you return and how. But if views works for your needs, it's certainly easier and faster.

still stuck

Macs's picture

Thanks a lot waldmanm,
i tried, however, somehow i cannot get it to work. first of all at the service browse page I was not able to see a views.get method (is that still applicable in services 3?). I added a new service, the endpoint i assigned to http://mydomain.com/services, i set the server to REST, responseformatter to json, at the resource tab i selected views.
i also created a simple view (without arguments) with view style:Unformatted and row style:Node and called it "view1"

now i tried all kinds of GET urls to get the json without success

http://mydomain.com/services/views/view1 for instance returns "null"

does anybody have any suggestion about how the url should look like? unfortunately there is hardly any documentation about how to work with views and services

Services

Group organizers

Group categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: