Problem/Motivation
Existing JSON endpoint usually support filtering through parameters in the query string of the JSON file URL.
Proposed resolution
Provide "Query String" filter and contextual filter handlers. The value of the filters are inserted as parameter in the query string of the JSON request.
| Comment | File | Size | Author |
|---|---|---|---|
| #35 | filter_and_contextual-2250191-35.patch | 14.68 KB | discipolo |
| #34 | filter_and_contextual-2250191-34.patch | 13.64 KB | discipolo |
| #32 | filter_and_contextuel-2250191-32.patch | 8.18 KB | discipolo |
| #31 | filter_and_contextuel-2250191-31.patch | 9.34 KB | discipolo |
| #28 | filter_and_contextuel-2250191-28.patch | 13.39 KB | discipolo |
Comments
Comment #1
jmymlr commentedComment #2
pbuyle commentedThe attached patch implement the suggested solution, but applies after my patch for #2250031: Better pagination support
Comment #3
pbuyle commentedComment #4
pbuyle commentedA missing feature is not a bug, reverting issue category.
Comment #5
pbuyle commentedReroll patch to work after latest patch in #2250031: Better pagination support
Comment #6
pbuyle commentedComment #7
tariqinam commentedI have applied provided patch, but it doesnt show any diff on "git diff"
I am on version 7.x-1.0
Comment #8
pbuyle commentedDid you apply the patch from #2250031? The patch is made for the 7.x-1.x branch.
Comment #9
tariqinam commentedI tried applying from #2250031 but it failed for .info file and new handler file. Any way I manually updated that bit. works like charm.
One thing to mention, if api url contain a port number, then it doesn't work. I added that bit just before creating final url in views_json_query_plugin_query_json.inc
Comment #10
pbuyle commentedThanks @tariqinam, the port does indeed needs handling. But this is actually an issue for the patch in #2250031: Better pagination support (I known, multiple patches are confusing and make it hard to work, but I try to keep feature separated, so pagination support can be added even if the architecture of this solution to this issue is still discussed).
Comment #11
tariqinam commentedthanks @mongolito404 , I got one more question. I have an exposed filter (query_string), And results only appear when I pass some value to it. How can I load with a default value.
My second question: Does it work with views page? because for me, it only work with view's block.
might possible if I am doing something wrong.
Comment #12
pbuyle commentedI should work with Views page. I don;t think default value are supported in my patch.
Comment #13
acarist commentedpatch steps not true. error : warning: views_json_query.info has type 100644, expected 100755. i patched manual. please add a patched version.
Comment #14
pbuyle commentedPatch apply fine when used with Drush make:
Try applying the patch for #2246731: Applying Filter Criteria Generates Fatal Error and #2250191: Filter and contextual filter in JSON file URL query string first.
Comment #15
khalor commentedDoesn't apply here either, even after the first 2 patches go through cleanly. It's only the .info file that fails though, everything else goes through.
After manually patching the .info (just those 2 lines to include the new handlers) this works brilliantly, so could skip re-rolling the patch and call this RTBC? Get it committed after #2250031: Better pagination support is resolved?
Comment #16
morganl commentedI've applied the patches in the order mentioned, and I believe I have everything in place, but when I try to add a new "Json: Query String" contextual filter, this error comes up:
Could someone please post a patched working copy of this module? (Or roll this into a new Dev release?) I'd really like to use this functionality.
Thanks!
Comment #17
morganl commentedI was eventually able to get it working using this Drush make file:
Attached is a zip of the fully-patch module for anyone else having trouble with this. Be sure to clear your caches after updating.
Comment #18
cprofessionals commentedFirst thanks for a great module and the updates/new features in the dev release. I see the new feature for applying a filter and giving that parameter a name. I am missing the syntax for referencing the parameter in the "The URL or path to the Json file." Thanks in advance.
Comment #19
cprofessionals commentedThe dev release does not seem to have an updated date on the main project page and still reads "2013-Oct-19" FYI
Comment #20
morganl commentedCProfessionals, the format is
http://www.example.com/endpoint_or_filename_hereThe dev release hasn't been updated in a long time. I'm not sure if/when anyone is working on rolling these patches into the dev release.
Comment #21
morganl commentedComment #22
cprofessionals commentedThanks for the reply. Any simple instructions for my question on #18. How do I reference a parameter in the json query string.
Comment #23
pbuyle commentedThe patch in #2 allow you to define a query parameter for the JSON file URL as a view filter. When doing so, there is no need to set the query parameter in the "URL or path to the Json file" field. The query parameters added as views filters will be added to URL automatically.
Comment #24
cprofessionals commentedI just verified. Brilliant! TOO SIMPLE. thanks for the reply.
I was using a different name in for the filter. Just in case, I want to spell this out for others that may come. If you have a json qwuery that looks like this "http://www.somejsonservice.com/?auth_token=XXXXXXXXXXXXXXXXXXXXXXXXXX&pa... you can replace any of the parameters with with a filter in views. just add a filter and make sure its name matches the parameter you want to make dynamic within views. Then remove the parameter from the query string. This module automatically adds it to the query string. so now it would read: "http://www.somejsonservice.com/?auth_token=XXXXXXXXXXXXXXXXXXXXXXXXXX" and I would have two filters in the view called "heading" and "sort".
Hope this helps someone. and thanks for the great module.
Comment #25
pbuyle commentedFor authorization token, you may want to not store it in the view definition, but rather in a configuration variable. Tis is easily doable with te following snippet.
Comment #26
cprofessionals commentedThanks, or you could put it in as a hidden filter, right?
Comment #27
pbuyle commentedYes you could put it as an hidden filter, but then it won't be easy to store it in a configuration variable.
Comment #28
discipolo commentedgrouped filters werent working as expected. i added this line to the previous patch to make the filters work for me:
Comment #29
discipolo commentedthe patch from #28 also includes all the other patches mentioned in #17
this one here is a reroll of #5 with the oneline addition to set the filter value for grouped filters
Comment #30
discipolo commentedadding grouping functionality to query string filters seems to work fine
Comment #31
discipolo commentedwith the other patch applied for convienience
Comment #32
discipolo commentedand here is the real one
Comment #33
discipolo commentedhad another look at the related issue which hasnt been updated in a year and decided to stick everything in here.
Comment #34
discipolo commentedremoving whitespace
Comment #35
discipolo commentednewer version of patch allows "not empty" condition in grouped exposed filters
Comment #36
skyriter commentedI tried patching with filter_and_contextual-2250191-35.patch and it failed for me:
Here's what was in views_json_query.info.rej
Has anyone been able to patch with the most recent one version?
Comment #37
skyriter commentedThis make file worked for me:
Keep in mind, we keep our contributed modules in a contrib/ folder to easily distinguish them for custom modules, which we keep in a custom/ folder.
Comment #38
skyriter commentedI'm wondering how I can use a query string with this patch, or can I?
I can use
mysite.com/view-url/value1to only bring back a JSON query string which has value1 as a value of the key:value pair, but I can't figure out how to grabmysite.com/view-url/value2without having/value1/value2in a specific order. This also means I can't just use any query key and value or mix up their order. Any thoughts?Comment #39
pbuyle commented@omahane: The patch allow usage of the view filters in the query string. Given the base URL https://example.com/api/data, you can use it to build a URL that looks like https://example.com/api/data?foo=value1 where 'foo' is a filter with the value is 'value1'. You can't use to push the value of a filter in the path part of the URL and build an URL like https://example.com/api/data/value1.
The patch also add support for contextual filter (aka. argument). If I remember correctly, these can be used in the path of the queried URL, the same they can be used in the path of a transitional view: using %n in the URL. So given the https://example.com/api/data/%1 base URL, you can use it to build https://example.com/api/data/value1 as queried URL.
Comment #40
agerard commentedI've just installed and started using Views Json Query in a test cloud install of D7 - not sure if the configuration is part of the problem but I wasn't able to use 'filter criteria' or 'relationships' settings in my test view using json (I got ajax errors, after which the specific block or page becomes unusable). I found this issue and was hoping patches herein might help me do what seems necessary, which is to supply 'filtering' parameters to the url string - I was able to apply patches to the dev module (one snippet manually) and now 'filter criteria' and 'relationships' work and I'm able to add parameters.
Very cool - thanks for this!
Comment #41
sunnygambino commentedYes, confirmed it is working cool!
You have to patch the info file manually and add two extra files. Check patch error file.
Comment #43
marcofernandes commentedMerged manually to dev branch because I already applied #2250031 patch. Looks ok.
Comment #44
jbfelix commentedHello,
I try to build the view for this:
https://remoteapi.com/webservice/api/apikey/XXXXXXXXX/contextual_filter/%/format/json
I would like to embed the view in a node template where the "contextual_filter" would be provided as a field's token.
My problem is that the requested API accept this:
https://remoteapi.com/webservice/api/apikey/XXXXXXXXX/format/json/contextual_filter/xx
But not this format:
https://remoteapi.com/webservice/api/apikey/XXXXXXXXX/format/json?contextual_filter=xx
How to achieve this or is it possible to rewrite ?contextual_filter=xx to /contextual_filter/xx
Thanks
Comment #45
jukka792 commentedHi,
I have a JSON API URL: https://remoteapi.com/webservice/?filter_name_a=xx
What is the exact value which should be in the "Json file field"?
I have tried: "https://remoteapi.com/webservice/" etc. but nothing seems to work so that the contextual filter would be included.
Created a contextual filter with a administrative name "filter_name_a".
Can't get this working, the "Json file field" does not get the contextual filter from the views.
What am I doing wrong?