DISCLAIMER- I am very new to Scriptable and JS in general.
I have managed to get this far into API calls and handling responses with (minimal) challenge, yet all the Google and Stack Overflow’ing that I have done I am still at a loss.
I am trying to parse, or slice, or output a few of my array parameters (namely the 'title'
and 'done'
elements) from the provided response of my API call, this is what I have so far:
Script:
var id= "527"//args.shortcutParameter
const url = 'https://tasks.my-sete.org/api/v1/tasks/';
var test = url+id
var req = new Request(test);
req.method = 'GET';
req.headers ={
'Authorization': 'Bearer my_api_token'
};
var result = await req.loadJSON();
console.log(result);//[0]["id"]);
let stringres= JSON.stringify(result);
let w = new ListWidget();
let input = w.addText(stringres);
Script.setWidget(w);
Script.complete();
Output:
2024-06-06 14:48:03: {"related_tasks":{},"due_date":"0001-01-01T00:00:00Z","reminders":null,"labels":null,"title":"Task to view in Scriptable","position":0,"reactions":null,"index":63,"end_date":"0001-01-01T00:00:00Z","is_favorite":false,"bucket_id":0,"percent_done":0,"updated":"2024-06-06T19:47:57Z","repeat_mode":0,"priority":0,"repeat_after":0,"id":527,"identifier":"#63","done":false,"project_id":3,"cover_image_attachment_id":0,"attachments":null,"assignees":null,"start_date":"0001-01-01T00:00:00Z","hex_color":"","created_by":{"username":"user42","id":1,"created":"2024-06-04T20:09:48Z","updated":"2024-06-05T02:59:28Z","name":""},"done_at":"0001-01-01T00:00:00Z","created":"2024-06-06T19:47:51Z","description":"<p></p>"}
Widget output:
If anyone could assist with this, it would be greatlyappreciated.