-1

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!

Phil
  • 157,677
  • 23
  • 242
  • 245
Wysocki
  • 1
  • 1

1 Answers1

0

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"
    }
  });
}
Phil
  • 157,677
  • 23
  • 242
  • 245
  • Thanks for the quick response, Phil, but although it looks like the way to go, now I got a ton of authorization / permission errors! Probably because my scope is set to .../auth/tasks/readonly. I got rid of the /readonly ending but it still crashes with a bang! Unfortunately, oAuth is WAY above my pay grade and I don't really know how I ever got it to do just readonly ! – Wysocki Sep 28 '22 at 22:02
  • I edited the scopes to be just .../auth/tasks and that still works ok to read the task. But then I added your code and I crash with: D:\User Sites\nodejs\googletasks\node_modules\gaxios\build\src\gaxios.js:130 throw new common_1.GaxiosError(`Request failed with status code ${translatedResponse.status}`, opts, translatedResponse); ^ GaxiosError: Insufficient Permission If I rename token.json I'm asked to Authorize by clicking this URL... But when I do I get thru a logon, then GTasks wants to acces your account, then ALLOW just fails to connect! – Wysocki Sep 29 '22 at 19:00