I'm using the script.google.com editor to try to delete tasks from a list as part of a bigger project however I keep getting an error which says
API call to tasks.tasks.delete failed with error: Task not found.
Here's the function I've created to remove a task from a list:
function deleteTask(){
taskid = 'ajM2UDZIZGctaXJnOTJjZg';
tasklist = 'MDk2MzE1ODgxNDkyNDE1NTI3MDA6MDow';
try {
// Call insert method with taskDetails and taskListId to insert Task to specified tasklist.
Tasks.Tasks.remove(taskid, taskListId);
// Print the Task ID of created task.
console.log('Task with ID "%s" was deleted.', taskid);
} catch (err) {
// TODO (developer) - Handle exception from Tasks.move() of Task API
console.log('Failed to move task with an error: %s', err.message);
}
}
The funny thing is, when I use https://developers.google.com/tasks/reference/rest/v1/tasks/delete
It works
able to remove tasks from developer.google.com
Any Ideas of what I might be doing wrong? I know it might be something simple, I'm still new to javascript, it's very frustrating. Any Help would be GREATLY appreciated
I've tried using the following code to grab the parent list ID and taskID. This seems to be working fine
const taskLists = Tasks.Tasklists.list();
// If taskLists are available then print all tasklists.
if (!taskLists.items) {
console.log('No task lists found.');
return;
}
// Print the tasklist title and tasklist id.
for (let i = 0; i < taskLists.items.length; i++) {
const taskList = taskLists.items[i];
//console.log('Task list with title Tasks" and ID "%s" was found.', taskList.title, taskList.id);
console.log(taskList);
}
Modification points:
taskListIdis not declared. So, I think that this might be the reason for your current issue.Tasks.Tasks.removearetasklist: stringandtask: string, respectively. IftaskidandtaskListIdin your showing script are the values of task ID and the task list ID, respectively,Tasks.Tasks.remove(taskid, taskListId);should beTasks.Tasks.remove(taskListId, taskid);. I think that this might be also an issue.When these points are reflected in your script, it becomes as follows.
Modified script:
taskListId, taskIdis removed.Note:
Reference: