Remember when I wanted to create a task in To Do from a message in Teams? I used a 'trick' to get the default tasks list without fetching all of them and applying a filter. I just got it confirmed by the To Do team that this is actually a supported method, and not just a trick!
The official documentation currently doesn't yet contain this 'trick', and just states the following for creating a task:
POST /me/todo/lists/{todoTaskListId}/tasks
POST /users/{id|userPrincipalName}/todo/lists/{todoTaskListId}/tasks
and the following ways for getting all tasks in a specific tasks list:
GET /me/todo/lists/{todoTaskListId}/tasks
GET /users/{id|userPrincipalName}/todo/lists/{todoTaskListId}/tasks
In both cases {todoTaskListId}
refer to the id of a specific tasks list, which you either need to know, guess or fetch from:
GET /me/todo/lists
GET /users/{id|userPrincipalName}/todo/lists
This returns all your task lists and you'd need to loop through them, and pick the correct one depending on your own criteria.
In case you'd like to add a task to the default tasks list or fetch all tasks from the default tasks list, the 'trick' is to replace {todoTaskListId}
with just Tasks
!
This results in following Microsoft Graph requests URLs:
POST /me/todo/lists/Tasks/tasks
POST /users/{id|userPrincipalName}/todo/lists/Tasks/tasks
GET /me/todo/lists/Tasks/tasks
GET /users/{id|userPrincipalName}/todo/lists/Tasks/tasks
This works for everyone, regardless of the language of the user, because matching happens on a well known folder in the user mailbox. That folder will always be named Tasks internally, even when the user doesn't have English as the language in Microsoft To Do and it shows a different value in the UI.
I love it when a 'trick' turns official, and helps me simplify my code 😃.