What google api function can I use to write data back to a Google Task?

58 Views Asked by At

Wrote my first node.js to access Google Tasks. I was able to successfully read the notes of a specific task I had set up into a text variable as follows:

function getTask(auth) {
  const service = google.tasks({version: 'v1', auth});
  service.tasks.list({
    tasklist: "MTAxNTxxxxxxxxxxxxxxxxxxxxk6MDow",
  }, (err, res) => {
    if (err) return console.error('The API returned an error for LIST: ' + err);
    const task = res.data.items;
    const text = task.find(c => c.title == "ToDo").notes;
    console.log(text);
  });
} //end getTask()

Now I would like to modify the contents of "text" variable and write it back to Google api. I notice there's a function called setTask() in the api, but I'm not sure how to implement it for this purpose. All the reference material I've pored through didn't really seem to apply to my needs and I'm a real newb with api stuff so be gentle with me!

1

There are 1 best solutions below

2
Phil On

From a quick look at the API docs, you'd want to use the Tasks.patch() method to issue a partial update (ie only certain fields).

const task = res.data.items.find(({ title }) => title === "ToDo");
if (task) {
  service.tasks.patch({
    task: task.id,
    tasklist: "MTAxNTxxxxxxxxxxxxxxxxxxxxk6MDow", // not sure if you need this
    requestBody: {
      notes: "New notes value"
    }
  });
}