Create Recurrence To-do Task Using Microsoft Graph API

To-do is one of the services in Microsoft 365 which helps us to list down our priorities in order and to ensure that tasks are accomplished in the correct time. We can access this service from the below link

https://to-do.office.com/

This is part of Microsoft 365, so Microsoft Graph can access these services through API. Let’s see how to view the to-do tasks and how to create a recurrence task using Microsoft Graph API.

We can access the To-do tasks in the hierarchy of To-do => List => Task

Use the below endpoint to access the lists available in To-do services for the current user account,

GET https://graph.microsoft.com/v1.0/me/todo/lists

Tasks are the default list in the To-Do service, we can use the displayName of the List to view it. Use the below endpoint, to access the default list from the To-do service is,

GET https://graph.microsoft.com/v1.0/me/todo/lists/Tasks

Use the below endpoint to access all the tasks items from the default List from the To-do service.

GET https://graph.microsoft.com/v1.0/me/todo/lists/Tasks/tasks

Try the below endpoint to access the tasks items other than the default task list. We should use the task list id instead of the display name. Because todo/lists don’t support display names other than default list.

GET https://graph.microsoft.com/v1.0/me/todo/lists/<Task List Id>/tasks

Create a simple to-do task

To create a to-do item for the task list, use the below endpoint and headers and request body.

Request Endpoint

POST https://graph.microsoft.com/v1.0/me/todo/lists/BBMk../tasks

Request Header:  Content-Type: application/json

Request Body

{
   "title":"Simple test task"
}

In Microsoft Graph Explorer, click the Send request to get the created Task item details.

Create a recurrence to-do task

To create a recurrence to-do task, we should provide the below properties in the request body,

  • Title a string type
  • dueDateTime dateTimeTimeZone
  • recurrence patternedRecurrence

Within dueDateTime property, we must specify the due date value and timezone value

Within recurrence property, we must specify the type of recurrence among below different values,

  • daily
  • weekly
  • absoluteMonthly
  • relativeMonthly
  • absoluteYearly
  • relativeYearly

And also we must specify the date range over which a recurring task repeats.

Request Endpoint

POST https://graph.microsoft.com/v1.0/me/todo/lists/BBMk../tasks

Request Header:  Content-Type: application/json

Request Body

{
    "title": "My recurrence task",
    "dueDateTime": {
        "dateTime": "2021-12-27T18:30:00.0000000",
        "timeZone": "Asia/Kolkata"
    },
    "recurrence": {
        "pattern": {
            "firstDayOfWeek": "sunday",
            "type": "weekly"
        },
        "range": {
            "type": "noEnd",
            "startDate": "2021-12-27",
            "endDate": "0001-01-01",
            "recurrenceTimeZone": "UTC",
            "numberOfOccurrences": 0
        }
    }
}

In Microsoft Graph Explorer, click the Send request to get the created recurrence Task item details as shown below,

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('79b9e183-b208-4faf-9316-b29bab84b266')/todo/lists('BB...BB%3D')/tasks/$entity",
    "@odata.etag": "W/\"JoFhX5P+OEGJY2Z8gbS/sQADB9B3kw==\"",
    "importance": "normal",
    "isReminderOn": false,
    "status": "notStarted",
    "title": "My recurrence task",
    "createdDateTime": "2021-12-27T15:41:16.1252004Z",
    "lastModifiedDateTime": "2021-12-27T15:41:16.4220566Z",
    "id": "BB...BB==",
    "body": {
        "content": "",
        "contentType": "text"
    },
    "dueDateTime": {
        "dateTime": "2021-12-27T00:00:00.0000000",
        "timeZone": "Asia/Kolkata"
    },
    "recurrence": {
        "pattern": {
            "type": "weekly",
            "interval": 1,
            "month": 0,
            "dayOfMonth": 0,
            "daysOfWeek": [
                "monday"
            ],
            "firstDayOfWeek": "sunday",
            "index": "first"
        },
        "range": {
            "type": "noEnd",
            "startDate": "2021-12-27",
            "endDate": "0001-01-01",
            "recurrenceTimeZone": "Asia/Kolkata",
            "numberOfOccurrences": 0
        }
    }
}

Now, we will get the recurrence to-do task created in the current user's to-do service application.