I am trying to use the ToDo Task feature of graph api v1.0 to create a task using the following code
var result = graphServiceClient.Users[outlookUserId].Todo.Lists[listid].Tasks.Request().AddAsync(todoTask).Result;
However, I am getting the following the error:
Code: invalidRequest Message: A type named 'microsoft.toDo.todoTask' could not be resolved by the model. When a model is available, each type name must resolve to a valid type. Inner error: Code: InvalidModel AdditionalData: date: 2020-11-25T09:41:04 request-id: 39794548-8f63-443e-a8bc-76ad6091dc8d client-request-id: 39794548-8f63-443e-a8bc-76ad6091dc8d ClientRequestId: 39794548-8f63-443e-a8bc-76ad6091dc8d
To resolve above, I had set the odatatype of todoTask to null, but got another exception:
Code: invalidRequest Message: A type named 'microsoft.toDo.dateTimeTimeZone' could not be resolved by the model. When a model is available, each type name must resolve to a valid type. Inner error: Code: InvalidModel AdditionalData: date: 2020-11-25T09:43:27 request-id: 0780add8-3f17-40c5-a92b-e9e62ad08bf8 client-request-id: 0780add8-3f17-40c5-a92b-e9e62ad08bf8 ClientRequestId: 0780add8-3f17-40c5-a92b-e9e62ad08bf8
To resolve above I set the odatatype of all data members of todoTask of type DateTimeZone to null, but then getting the following exception:
Code: invalidRequest Message: A type named 'microsoft.toDo.itemBody' could not be resolved by the model. When a model is available, each type name must resolve to a valid type. Inner error: Code: InvalidModel AdditionalData: date: 2020-11-25T09:46:11 request-id: 5bafbcab-5090-47b5-ac8e-8c96ec1d6592 client-request-id: 5bafbcab-5090-47b5-ac8e-8c96ec1d6592 ClientRequestId: 5bafbcab-5090-47b5-ac8e-8c96ec1d6592
To resolve above, I set the odatatype of todoTask body to null, but now I am getting following exception which I am unable to resolve:
Code: generalException Message: Internal Server Error Inner error: AdditionalData: date: 2020-11-25T09:48:23 request-id: f5d52f43-c0b4-425e-83ec-652fadb7abf9 client-request-id: f5d52f43-c0b4-425e-83ec-652fadb7abf9 ClientRequestId: f5d52f43-c0b4-425e-83ec-652fadb7abf9
For our application, we need to create task and sync to outlook and since, this will go into production, we cannot use the beta version. Can anybody please help me in saving the task.
UPDATE:
Here is the code of how I am setting the TodoTask object:
var todoTask = new TodoTask();
todoTask.Title = "Subject";
todoTask.DueDateTime = new DateTimeTimeZone() { DateTime = dueDate.Date.ToString()};
todoTask.Status = TaskStatus.NotStarted;
todoTask.Importance = Importance.Normal;
todoTask.Body = new ItemBody
{
Content = "Test",
ContentType = BodyType.Text
};
todoTask.IsReminderOn = true;
todoTask.ReminderDateTime = new DateTimeTimeZone() {
DateTime = reminderTime.Value.ToString() };
todoTask.Extensions = new TodoTaskExtensionsCollectionPage();
todoTask.Extensions.Add(new OpenTypeExtension{
ExtensionName = "TestProperty",
AdditionalData = new Dictionary<string,object>{{"MyProp","MyValue"}}});
After you set the odatatype to null, you also need to set the TimeZone
property for DueDateTime
and ReminderDateTime
.
For example:
var todoTask = new TodoTask();
todoTask.Title = "Subject2";
todoTask.ODataType = null;
DateTime dueDate = DateTime.UtcNow.Date;
DateTime reminderTime = DateTime.UtcNow.Date;
todoTask.DueDateTime = new DateTimeTimeZone() {
TimeZone = "UTC",
ODataType = null,
DateTime = dueDate.Date.ToString()
};
todoTask.Status = TaskStatus.NotStarted;
todoTask.Importance = Importance.Normal;
todoTask.Body = new ItemBody
{
ODataType = null,
Content = "Test",
ContentType = BodyType.Text
};
todoTask.IsReminderOn = true;
todoTask.ReminderDateTime = new DateTimeTimeZone()
{
TimeZone = "UTC",
ODataType = null,
DateTime = reminderTime.Date.ToString()
};
todoTask.Extensions = new TodoTaskExtensionsCollectionPage();
todoTask.Extensions.Add(new OpenTypeExtension
{
ExtensionName = "TestProperty",
AdditionalData = new Dictionary<string, object> { { "MyProp", "MyValue" } }
});