1

I am trying to create tasks in a tasklist from the google app script editor. Looks like I need the id of the tasklist to be able to add the task.

Problem is I can figure out where ti find the tasklist ID

Tanaike
  • 181,128
  • 11
  • 97
  • 165
Sheils
  • 323
  • 2
  • 22

1 Answers1

3

If you want to retrieve the tasklist IDs using Google Apps Script, how about this sample script?

In order to use the sample script, before you run the script, please enable Tasks API at Advanced Google Services and API console as follows.

Enable Tasks API at Advanced Google Services

  • On script editor
    • Resources -> Advanced Google Services
    • Turn on Tasks API v1

Enable Tasks API at API console

  • On script editor
    • Resources -> Cloud Platform project
    • View API console
    • At Getting started, click "Explore and enable APIs".
    • At left side, click Library.
    • At "Search for APIs & services", input "Tasks API". And click "Tasks API".
    • Click Enable button.
    • If API has already been enabled, please don't turn off.

Sample script:

After Tasks API was enabled, please run the following script.

function myFunction() {
  var taskLists = Tasks.Tasklists.list().getItems();
  var res = taskLists.map(function(list) {
    return {
      taskListId: list.getId(),
      listName: list.getTitle(),
    };
  });
  Logger.log(res)
}

Reference:

If this was not the result you want, I apologize.

Tanaike
  • 181,128
  • 11
  • 97
  • 165
  • When I try the code I get the following error:- API call to tasks.tasklists.list failed with error: Project 47833456xxxx is not found and cannot be used for API calls. If it is recently created, enable Tasks API by visiting https://console.developers.google.com/apis/api/tasks.googleapis.com/overview?project=47833456xxxx then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry. (line 150, file "Code"). Line 150 is var taskLists = Tasks.Tasklists.list().getItems() – Sheils Apr 09 '19 at 19:18
  • When I go to the api link I get a fail load error:- There was an error while loading /apis/api/tasks.googleapis.com/overview?project=47833456xxxx. Please try again. – Sheils Apr 09 '19 at 19:21
  • @Sheils Thank you for replying. I apologize for the inconvenience. From your comment, it seems that you try to access to API console by the error message. At first, I would like to confirm. Before you run the script, did you enable Tasks API at API console that I show you at "Enable Tasks API at API console. If you didn't yet, please try to do. – Tanaike Apr 09 '19 at 21:53
  • Hi Tanaike, I did but on closer inspection I noticed that the script was associated with the wrong project id, probably becuase I have multiple gmails account active. It is working fine now that I have fixed the link. Thanks heaps. Cheers – Sheils Apr 10 '19 at 06:37
  • @Sheils Thank you for replying and additional information. I'm glad your issue was resolved. And also I could study from your question. Thank you, too. – Tanaike Apr 10 '19 at 08:49