Danton Heuer
Danton Heuer

Reputation: 416

How to get and set custom sorting order on MS To-Do using GraphAPI

Requirement Explanation

I'm developing a company dashboard, wish MS To-Do is part of as a widget, and there is no value if I can't sync task sorting order between tools such as MS To-Do, Outlook, or To-Do mobile applications.

Outlook Tasks REST API

As seen on Outlook Task REST API documentation, I could do that, but that will be deprecated later this year (source). Both Outlook Web and MS To-Do online seem to be using that API for interacting with MS To-Do (Outlook Tasks).

Outlook API for to-do

So the sorting order can be fetched and patched through the field "OrderDateTime".

Fetch example (GET):

Fetch

Reordering Example (PATCH):

Payload with OrderDateTime

GraphAPI To-Do

The main idea is to get the custom sorting order to listing and patching endpoints of GraphAPI, which currently seems not to be working.

Postman failing to order by Same OData "orderBy" used by Outlook API:

Postman failing to order by Same OData "orderBy" used by Outlook API

Has anyone had a similar issue w/ MS To-Do and GraphAPI?

Question similar to: How to order tasks by importance in microsoft todo task graph API?, but more detailed on different APIs and less confusing in "importance" as this is also a field from To-Do as "High", "Normal" and "Low" order (3 states) only.

Upvotes: 3

Views: 927

Answers (2)

user3151902
user3151902

Reputation: 3176

This does not answer your question directly, because, as already mentioned, this functionality is currently not available in Microsoft Graph.

However, I suspect that there are people willing to use an API other than Microsoft Graph to get the data, so I wrote a short blog post about this, because it's not properly documented anywhere (the API is officially deprecated).

Using the Outlook API is currently the only way to access this data, but from a data model perspective, the APIs are very similar (you can use IDs from the Outlook API to query Microsoft Graph, and the other way around). Therefore, I believe using the Outlook API for ordering/sorting now and switching to Microsoft Graph once it's available, is a good approach.


Basically, what you need to do is manually adjust your app registration's Manifest and add this object to the "requiredResourceAccess" array:

{
  "resourceAppId": "00000002-0000-0ff1-ce00-000000000000",
  "resourceAccess": [
    {
      "id": "6b49b74d-642f-4417-a6b4-820576845707",
      "type": "Scope"
    }
  ]
}

This will result in the "Office 365 Exchange Online" / "Tasks.ReadWrite" permissions being added to the app registration.

Then you can get the data, including the "OrderDateTime" field, like this:

curl -v https://outlook.office.com/todob2/api/v1/taskfolders \
    -H "Authorization: Bearer ABC[...]"

To update the field, use e.g.

curl -v https://outlook.office.com/todob2/api/v1/taskfolders/AbCdEf== \
    -H "Authorization: Bearer ABC[...]" \
    -X PATCH \
    -H "x-anchormailbox: CID:1234ABCD4321ABCD" \
    -H "Content-Type: application/json" \
    -d '{"OrderDateTime": "2023-04-09T07:00:00Z"}'

(The value for the x-anchormailbox header is derived from the x-target-resource-metadata response header)

Upvotes: 1

Danton Heuer
Danton Heuer

Reputation: 416

As of 29-04-2022, this functionality is not available in MS GrahAPI for To-Do application.

As per my communication with Microsoft, this is not planned at least until Q3.

Thanks for reaching out and apologies for the issue you have faced. Ordering of tasks is in our backlog, but it is currently not planned till CY22Q3. I would appreciate if you could add this feature asks in Microsoft 365 Developer Platform - Microsoft Tech Community as it would help us in prioritizing it.

Following above email recommendation, I've opened the feature request - if you are facing same issue as me, and require Microsoft to work on this, please thumbs up item below - so they can notice task, and prioritize it.

https://techcommunity.microsoft.com/t5/microsoft-365-developer-platform/to-do-graphapi-to-include-orderdatetime-field-custom-ordering-of/idi-p/3298392#M940

Upvotes: 1

Related Questions