0

I am working with Google Tasks, using the PHP library: https://developers.google.com/tasks/v1/reference/tasks

I am trying to insert a task with a custom ID.

I found this topic: Setting id to task using Google Task API returns 400 invalid value

which points to this topic: Google tasks update error

They suggest to send the Task ID with the Task title. I think I have done that.

This is the code info from the Google API reference

$task = new Task();
$task->setTitle('New Task');
$task->setNotes('Please complete me');
$task->setDue(new TaskDateTime('2010-10-15T12:00:00.000Z'));

$result = $service->insertTasks('@default', $task);
echo $result->getId();

This is my code, I got setID() from the library itself.

$taskNew = new Google_Service_Tasks_Task();
$taskNew->setId('2013');
$taskNew->setTitle('Notify');
$taskNew->setDue(new TaskDateTime('2018-10-27T00:00:00.000Z'));

$results3 = $service->tasks->insert('.....', $taskNew);

I keep getting an error and it refuses to make the task.

Using this API tool: https://developers.google.com/apis-explorer/#p/tasks/v1/tasks.tasks.insert

I can insert tasks successfully, so long as the system makes the ID. The Google Task API will insert the task, but assign its own ID. If I specify a custom ID, then I get a 400 error "Invalid value".

I am making tasks to correspond to events saved in my program's database. I need to be able to find the task that matches a database event when I need to make changes to the due date or completed. The reason I want to set my own ID, is so I can find the specific task and make changes.

I could add a new field to the database with the ID that google generates. But I would prefer to not have to change the database and the rest of the program as well.

Thanks so much for any help, - Jon

Jon
  • 21
  • 4
  • Is it ever possible to have two or more tasks associated with the same db entry? If so, then a table associating your db row IDs with the relevant Google task ID is the best solution. This won't change anything about how other parts use the source db rows. – tehhowch Dec 07 '18 at 03:49

1 Answers1

0

Task Id is the read-only parameter. I solved this question by using a prefix for the task`s Title. For example: "[my_id] Task Title".

Miroslav
  • 31
  • 4