Active
Project:
Services Views
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
26 Dec 2012 at 04:36 UTC
Updated:
9 Feb 2017 at 08:40 UTC
Jump to comment: Most recent
It's possible I'm missing something obvious, but is there a way to have services views return the field value with the right type? It seems to me that no matter what I do the response value is always a string even when the data is an integer or list (as is the case with a select list of references). For example I would like to get nid as integer rather than a quoted number. I tried all the formatters but all return some type of string. I'm hoping I don't have to write my own formatter, but if I do I wonder if there are any recommendations or suggestions.
Thanks much
Comments
Comment #1
cybertoast commentedIt turns out my understanding of implementing the services module was quite wrong and what I have been doing so far is using the Page display-type and assuming it could be rendered as a service. I actually thing this needs better documentation, which I'm going to submit, but for now this is my updated understanding in case anyone else has this confusion in future.
Services_Views exposes a new "Services" display-type in your view. This resource requires a path, which is appended to your Services Server's endpoint. Say your server is REST running at "/api", the path for your services-views display end-point would be appended to this. So setting path of "my_view" would have a resource that is retrieved via "/api/my_view". Keep in mind that each resource MUST be enabled in your services resources list at /admin/structure/services/list/rest_api/resources after you have defined your Service-View.
If you want fields to be returned in the original entity format, set the Formatter to "Services Raw".
Referenced nodes/entities are returned as a list of targets by default:
Use the "Label" formatter to get the node's title at the very least, which might be more
useful. Enable "link label to the referenced entity" to get the link, which can then
be parsed for the node id in case you want to do something with that.
The best solution might be to go with the "Rendered Entity" formatter and use the Custom View,
which can be set up so that you get the specific fields and formats that you want.
Comment #2
ygerasimov commentedAs another solution to original problem is to use php type field and do type casting there so integer values won't be treated as strings.
Comment #4
bc commentedFor "content" row plugin type, I use this to add pseudo-field values and also to apply the correct type to certain fields:
I'm still trying to figure out how to do the same for fields row_plugin...
Comment #5
abaier commentedI cannot find "Services Raw" as formatter in the views ui. Could somebody maybe tell me where to activate this option? I am using Services Views 7.x-1.1.
Thanks in advance.