Closed (works as designed)
Project:
JSON:API
Version:
8.x-1.0-alpha3
Component:
Miscellaneous
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
13 Dec 2016 at 12:34 UTC
Updated:
31 Oct 2018 at 22:33 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
e0ipsoI'm not sure I understand the use case for using the views export along with JSON API. Care to provide more clarification?
Comment #3
e0ipsoComment #4
petiar commentedHi e0ipso,
I need to provide a way to editors to sort articles on the page in the particular taxonomy term. The only way how to achieve that is, I think, to use the draggable views to get sorted list of nodes in particular taxonomy term. Is there any other way how to achieve this?
Comment #5
wim leersI think I understand what's going on.
api_jsonformat.(Note that even Preston So got this wrong in his article at https://dev.acquia.com/blog/decoupled-drupal-with-ember-introducing-embe....)
I think this is a real problem: the REST module makes every installed serialization format available for use on REST resources, even when it's a format that does not really make sense in the REST module.
Shall I create a separate issue for this, or do you want to repurpose this one, Mateu?
Comment #6
janlaureys commented@petiar. I'm not exactly sure what you mean but you can probably do something add a sort parameters to your query like this.
?_format=api_json&sort[][path]=.weight&sort[][direction]=ASC|DESC.
with the being just a identifier that's something relevant or a number or something.
Comment #7
petiar commented@Wim Leers: I do not understand what's the point of your comment. Is it the order in which modules have to be installed or is it something else? What's wrong in Preston's article? Of course I have JSON API module installed and the view created as you described and all formats are returning JSON output, except the JSON API.
@JanLaureys: I would need to do a custom sorting, so editors can have some drag and drop interface where they can sort articles. It is achievable via Draggable Views module, it does even exist for Drupal 8, however, I can't use it if I am not getting the correct JSON output.
Thanks for your time, guys.
Comment #8
e0ipsoI don't think that you will get integration between jsonapi and draggable views. I am not sure if you can do it with any of the formats out there either, but if you succeed please post back.
Comment #9
e0ipsoComment #10
petiar commentedHi @e0ipso,
sorry, but I am opening this again. It does not have to do anything with the Draggable views, that's only a mechanism for sorting which I mentioned to explain what am I doing. The real point of this ticket is, that when using the
api_jsonformat vith views, I am getting empty entities. Compare:with the
The first one is
api_json, the second one justjson. As you can see, it is exporting three entities/nodes, which is correct, but they are empty. It is very simple view.Comment #11
petiar commentedHi there,
as I would like to get this issue solved as soon as possible, I am providing more info. I made a clean install of Drupal 8.2.4, enabled to modules related to REST (HAL, HTTP Basic Authentication, RESTful Web Services, Serialization), installed and enabled JSON API. Generated couple of articles using the drupal console and created a simple view. Still providing empty object where there should be nodes when using JSON API format. As this works alright for other formats, I am considering this as a bug.
Attached you can find all relevant files. There are JSON views output in json and api_json format, yml export of the REST settings and the yml export of the view (the 4.82 KB is the one I uploaded now, use that one, please).
If you want any more information or if I could be of any help, let me know.
Comment #12
e0ipsoI am yet to understand why is that you want to use JSON API with views. What are you trying to accomplish that you can't accomplish with views that you cannot do with JSON API collections?
There is no explicit support for having the
api_jsonformat work with views, because the jsonapi module implements that feature in a completely different way, that we think it's much more flexible.What I think that the problem is, is that views should not offer all formats in their UI, it should exclude
api_json. Unfortunately this is not something that can be fixed in this module, but I'll be glad to review any patches to core in that regard.Comment #13
wim leers#12: please re-read what I wrote in #5. I think that's the big problem here: we let other modules, like the REST module, use the JSON API format. This is wrong/problematic.
Comment #14
petiar commentedHey guys,
I am deeply sorry, the only problem here was the lack of understanding the JSON API concepts. The word
collectionis the answer to my problem(s). I found this link: https://www.drupal.org/node/2803141 and it answers almost all my questions, except the sorting and pagination. Could you, please, specify an example of sorting and pagination GET request? Feel free to close this ticket as "works as designed". Thanks for your effort.Comment #15
petiar commentedGot it, for example:
api/node/article?_format=api_json&sort=-nidwill sort nodes bynid, descending (hence the-) sign.Comment #16
e0ipso@petiar no need for apologies, this will be great documentation for the next person that has those same questions. It will be amazing if you could write what you found confusing in the project documentation: https://www.drupal.org/node/2803093
We will see you in your next issue :-)
Comment #17
wim leersCreated a separate issue for the problem described in #5: #2841027: JSON API format should only be used on JSON API routes, but can currently also be used for REST resources.
Comment #18
alexevh commented@petiar
Your comment works except because I cant use that with limit 1
I want to retrieve the last article of a category so I made this call
http://example.org/jsonapi/node/Tienda?page[limit]=1 and as result I have one article only but is the first
I want the last , If I make this call http://example.org/jsonapi/node/Tienda?sort=-nid I get every single article sorted DESC,
I want both things I want the sorting to be DESC but only one article
Any advice?