Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
SparkOut
- Posts: 2943
- Joined: Sun Sep 23, 2007 4:58 pm
Post
by SparkOut » Mon Aug 23, 2021 5:19 pm
OK another quick rearrangement after messing around with the direct GET query string.
This works on Android for me, built with Community Edition 9.6.3 (on Windows)
Code: Select all
put "filters=%7B%22" & "postcode" & "%22%3A%22" & "2103" & "%22%7D" into tFilter
put "https://data.nsw.gov.au/data/api/3/action/datastore_search?resource_id=2776dbb8-f807-4fb2-b1ed-184a6fc2c8aa&limit=1&fields=postcode,lga_name19,notification_date,likely_source_of_infection&" & tFilter into tQuery
put url (tQuery) into myJSONVar
answer information "JSON Data Returned: " & myJSONVar
-
wlaughto
- Posts: 30
- Joined: Fri Apr 07, 2017 5:06 am
Post
by wlaughto » Tue Aug 24, 2021 3:31 am
SparkOut wrote: ↑Mon Aug 23, 2021 4:59 pm
Now I have seen on a computer rather than phone, I can spot that you are using json data in the GET url.
This I think must be a limitation of the libUrl equivalent on Android.
I have made a few quick trials with urlEncoded filters and substituting html entities but not successfully. Is there a method in the API that you can submit the GET string with filters defined as name=value pairs rather than json?
This may well be the case, however I do not understand why it works with Indy and not Community. My view, it is a defect and as such I will raise a bug request.
In the meantime, I have worked out another way to access the data. The api also provides an SQL access path, so I have gone down that path to get the data I need.
For interest, this is what it ended up as:
Code: Select all
put "2103" into tPC -- comment this variable would normally be supplied by UI
if tPC = "ALL" then
put empty into tPCFilter
else
put "and%20postcode%20=%20%27" into tPCFilter
put tPC after tPCFilter
put "%27" after tPCFilter
end if
put "https://data.nsw.gov.au/data/api/3/action/datastore_search_sql?sql=SELECT%20postcode,%20lga_name19,%20notification_date,%20likely_source_of_infection%20from%20%222776dbb8-f807-4fb2-b1ed-184a6fc2c8aa%22%20WHERE%20lga_name19%20%3C%3E%20%27null%27%20" into tQuery
put tPCFilter after tQuery
put "ORDER%20BY%20notification_date,postcode" after tQuery
answer information "JSON Query: " & tQuery
put url (tQuery) into myJSONVar
put the result into theError
if theError is empty then
answer information "No error found in https query"
else
answer information "An error occurred:" && theError & "." -- this does not seem to work
end if
-
SparkOut
- Posts: 2943
- Joined: Sun Sep 23, 2007 4:58 pm
Post
by SparkOut » Tue Aug 24, 2021 7:24 am
Did you try the code I showed which worked for me on Android built with LC Community?
-
wlaughto
- Posts: 30
- Joined: Fri Apr 07, 2017 5:06 am
Post
by wlaughto » Tue Aug 24, 2021 8:40 am
SparkOut wrote: ↑Tue Aug 24, 2021 7:24 am
Did you try the code I showed which worked for me on Android built with LC Community?
I assume you are referring to:
Code: Select all
get url (tQuery)
answer the result
Yes I did, but did not work.
I also tried:-
Code: Select all
put "filters=%7B%22" & "postcode" & "%22%3A%22" & "2103" & "%22%7D" into tFilter
put "https://data.nsw.gov.au/data/api/3/action/datastore_search?resource_id=2776dbb8-f807-4fb2-b1ed-184a6fc2c8aa&limit=1&fields=postcode,lga_name19,notification_date,likely_source_of_infection&" & tFilter into tQuery
put url (tQuery) into myJSONVar
answer information "JSON Data Returned: " & myJSONVar
however this does not work either, infact it is an incorrect construct for the query. I did plug in your 'filter' to the correct query and this did not work either. I'll keep playing with it to see if I can get this to work.
-
SparkOut
- Posts: 2943
- Joined: Sun Sep 23, 2007 4:58 pm
Post
by SparkOut » Tue Aug 24, 2021 9:47 am
That code works for me. The order of parameters should not matter, moving the filter to the end just made it easier to adjust, and focus on the part of the query when "answering" while testing. It's certainly a valid construction.
-
wlaughto
- Posts: 30
- Joined: Fri Apr 07, 2017 5:06 am
Post
by wlaughto » Tue Aug 24, 2021 10:33 am
SparkOut wrote: ↑Tue Aug 24, 2021 9:47 am
That code works for me. The order of parameters should not matter, moving the filter to the end just made it easier to adjust, and focus on the part of the query when "answering" while testing. It's certainly a valid construction.
My apologies, yes it did work - fat fingers.
Still doesn't explain why this (my original code) works fine on Indy and not Community in an emulator!
Thanks for your persistence.
I have logged a bug request anyway. See if anything come of it.
-
wlaughto
- Posts: 30
- Joined: Fri Apr 07, 2017 5:06 am
Post
by wlaughto » Fri Oct 01, 2021 5:20 am
So to close this off, yes it was a bug recognised by Livecode folks, but because Community version is no longer, will not be fixed!