Service Tasks
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Le service Tasks vous permet d'utiliser l'API Google Tasks dans Apps Script. Cette API permet aux utilisateurs de gérer leurs tâches dans Gmail.
Référence
Pour obtenir des informations détaillées sur ce service, consultez la documentation de référence de l'API Tasks.
Comme tous les services avancés d'Apps Script, le service Tasks utilise les mêmes objets, méthodes et paramètres que l'API publique. Pour en savoir plus, consultez Déterminer les signatures de méthode.
Pour signaler des problèmes et obtenir de l'aide, consultez le guide d'assistance Tasks.
Exemple d'application
L'exemple d'application Web Simple Tasks montre comment utiliser le service Tasks pour les opérations de lecture et d'écriture. Vous pouvez consulter le code source complet sur notre dépôt GitHub.
Exemple de code
L'exemple de code ci-dessous utilise la version 1 de l'API.
Lister les listes de tâches
Cet exemple liste les listes de tâches de votre compte.
Répertorier les tâches
Cet exemple liste les tâches d'une liste de tâches donnée.
Ajouter une tâche
Cet exemple ajoute une tâche à une liste de tâches.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/08/31 (UTC).
[null,null,["Dernière mise à jour le 2025/08/31 (UTC)."],[[["\u003cp\u003eThe Tasks service in Apps Script enables you to manage tasks in Gmail using the Google Tasks API.\u003c/p\u003e\n"],["\u003cp\u003eThis advanced service requires enabling before use and utilizes the same structure as the public Tasks API.\u003c/p\u003e\n"],["\u003cp\u003eSample code is provided to demonstrate common operations like listing task lists, listing tasks within a list, and adding new tasks.\u003c/p\u003e\n"],["\u003cp\u003eA simple tasks web application showcases read and write operations with the Tasks service and is available with full source code on GitHub.\u003c/p\u003e\n"],["\u003cp\u003eSupport and further information regarding the Tasks service can be found in the Tasks support guide and reference documentation.\u003c/p\u003e\n"]]],[],null,["# Tasks Service\n\nThe Tasks service allows you to use the\n[Google Tasks API](/tasks) in Apps Script. This API\ngives users the ability to manage their tasks in Gmail.\n| **Note:** This is an advanced service that must be [enabled before use](/apps-script/guides/services/advanced).\n\nReference\n---------\n\nFor detailed information on this service, see the\n[reference documentation](/tasks/v1/reference) for the Tasks API.\nLike all advanced services in Apps Script, the Tasks service uses the same\nobjects, methods, and parameters as the public API. For more information, see [How method signatures are determined](/apps-script/guides/services/advanced#how_method_signatures_are_determined).\n\nTo report issues and find other support, see the\n[Tasks support guide](/tasks/support).\n\nSample application\n------------------\n\nThe sample web application Simple Tasks demonstrates how to use the Tasks\nservice for both read and write operations. You can view the full source code\non our\n[GitHub repository](https://github.com/googleworkspace/apps-script-samples/tree/main/tasks/simpleTasks).\n\n[](https://github.com/googleworkspace/apps-script-samples/tree/main/tasks/simpleTasks)\n\nSample code\n-----------\n\nThe sample code below uses [version 1](/tasks/v1/reference) of\nthe API.\n\n### List task lists\n\nThis sample lists the task lists in your account. \nadvanced/tasks.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/tasks.gs) \n\n```javascript\n/**\n * Lists the titles and IDs of tasksList.\n * @see https://developers.google.com/tasks/reference/rest/v1/tasklists/list\n */\nfunction listTaskLists() {\n try {\n // Returns all the authenticated user's task lists.\n const taskLists = Tasks.Tasklists.list();\n // If taskLists are available then print all tasklists.\n if (!taskLists.items) {\n console.log('No task lists found.');\n return;\n }\n // Print the tasklist title and tasklist id.\n for (let i = 0; i \u003c taskLists.items.length; i++) {\n const taskList = taskLists.items[i];\n console.log('Task list with title \"%s\" and ID \"%s\" was found.', taskList.title, taskList.id);\n }\n } catch (err) {\n // TODO (developer) - Handle exception from Task API\n console.log('Failed with an error %s ', err.message);\n }\n}\n```\n\n### List tasks\n\nThis sample lists the tasks within a given task list. \nadvanced/tasks.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/tasks.gs) \n\n```javascript\n/**\n * Lists task items for a provided tasklist ID.\n * @param {string} taskListId The tasklist ID.\n * @see https://developers.google.com/tasks/reference/rest/v1/tasks/list\n */\nfunction listTasks(taskListId) {\n try {\n // List the task items of specified tasklist using taskList id.\n const tasks = Tasks.Tasks.list(taskListId);\n // If tasks are available then print all task of given tasklists.\n if (!tasks.items) {\n console.log('No tasks found.');\n return;\n }\n // Print the task title and task id of specified tasklist.\n for (let i = 0; i \u003c tasks.items.length; i++) {\n const task = tasks.items[i];\n console.log('Task with title \"%s\" and ID \"%s\" was found.', task.title, task.id);\n }\n } catch (err) {\n // TODO (developer) - Handle exception from Task API\n console.log('Failed with an error %s', err.message);\n }\n}\n```\n\n### Add task\n\nThis sample adds a new task to a task list. \nadvanced/tasks.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/tasks.gs) \n\n```javascript\n/**\n * Adds a task to a tasklist.\n * @param {string} taskListId The tasklist to add to.\n * @see https://developers.google.com/tasks/reference/rest/v1/tasks/insert\n */\nfunction addTask(taskListId) {\n // Task details with title and notes for inserting new task\n let task = {\n title: 'Pick up dry cleaning',\n notes: 'Remember to get this done!'\n };\n try {\n // Call insert method with taskDetails and taskListId to insert Task to specified tasklist.\n task = Tasks.Tasks.insert(task, taskListId);\n // Print the Task ID of created task.\n console.log('Task with ID \"%s\" was created.', task.id);\n } catch (err) {\n // TODO (developer) - Handle exception from Tasks.insert() of Task API\n console.log('Failed with an error %s', err.message);\n }\n}\n```"]]