Videos
Hello fellow redditors/taskers. I am trying to get my tasks from todoist api to tasker with HTTP Request. Since the number of tasks varies, my response in %http_data is json array whose size is changing depending on how many tasks I have. To be able to get the task names, their descriptions and due dates I am trying to loop over the response length via java scriptlet. I have an action for HTTP Request and a second action in which I am trying to extract my task information by a statement like below to get the json array.
var jsonarr = JSON.parse(local('http_data')) ;
However, I cannot get it to work. Below you can find what I tried and none of them worked:
var jsonarr = JSON.parse(local('http_data')) ;
var jsonarr = JSON.parse(local('%http_data')) ;
var jsonarr = JSON.parse(http_data) ;
var jsonarr = JSON.parse(%http_data); (this actually producess "unknown token %" error)
var jsonarr = JSON.parse(global('HTTP_DATA1')) ; (I had assigned a variable HTTP_DATA1 to %http_data before executing this in separate action). (EDIT2: When I run this, this actually hangs)
I am getting "unexpected end of json file" no matter what I have tried. If I can get it to work, ultimately, I will loop over jsonarr.length and create my variables dynamically then will pass them over to KLWP.
EDIT: I am using Tasker 6.0.10, mi 9 lite, android 10
Asking for your help and thanks in advance for reading :)
EDIT3: Please see attached comment about the fix.
(solved)
Hey guys, I figured out. Apperantly the local variables are not visible to separate actions somehow. What I mean is this: in my frist action I was retrieving a json array from the website. Then in the second action I was using java scriptlet. But I was trying to fix my code by clicking the 'play' button inside the java scriptlet to test. Seems like that way of testing cannot reach the local variables. When I go 1 level up from java scriptlet to my task page and then click 'play' at the bottom of the screen, only then java scriptlet was able to get the local('http_data') correctly.
Use a flash to see if the correct data is returned
This is how I parse it data = JSON.parse(http_data);