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" } }
});
Related
Using the Microsoft Teams Portal, I created a Group that came with Assignments and the Notebook tab. I want to create a similar Group programmatically.
I am using the Nuget Microsoft.Graph.Beta 4.0.1-preview to create Team for a School Classroom programmatically on Microsoft Teams.
However I noticed that the team created does not have the Assignments tab nor the Notebook.
Then I compared with a Team I created on the teams portal and found that the Team created manually on the Teams portal have this creationOptions on the class Group
"creationOptions": ["classAssignments", "ExchangeProvisioningFlags:2509"]
But on the group created by API it does not contain that.
The API also does not have the field creationOptions
How to add that information when creating it using the API?
Or
How can I add those options after the Team is created?
I also tried this:
var grupo = await graphClient.Groups.Request().AddAsync(new Group()
{
DisplayName = "Turma Dialética 2021",
Description = "Grupo da Turma Dialética 2021",
MailNickname = "f958e37c-f093-4177-8de4-2f86bfaba624",
MailEnabled = false,
SecurityEnabled = false,
GroupTypes = new string[] { "Unified" },
Visibility = "HiddenMembership",//
AdditionalData = new Dictionary<string, object>()
{
{"creationOptions", new List<string> { "classAssignments", "ExchangeProvisioningFlags:2509" } }
}
}
);
Which sends this JSON payload
{
"description": "Grupo da Turma Dialética 2021",
"displayName": "Turma Dialética 2021",
"groupTypes": [
"Unified"
],
"mailEnabled": false,
"mailNickname": "f958e37c-f093-4177-8de4-2f86bfaba624",
"securityEnabled": false,
"visibility": "HiddenMembership",
"#odata.type": "microsoft.graph.group",
"creationOptions": [
"classAssignments",
"ExchangeProvisioningFlags:2509"
]
}
But when I add this AdditionalData, then this Exception happens:
Microsoft.Graph.ServiceException: 'Code: Request_BadRequest Message: A value without a type name was found and no expected type is available. When the model is specified, each value in the payload must have a type which can be either specified in the payload, explicitly by the caller or implicitly inferred from the parent value. Inner error: AdditionalData: date: 2021-04-08T21:14:22 request-id: d3a0b0d3-5940-46d8-8188-56a1eaf5d350 client-request-id: d3a0b0d3-5940-46d8-8188-56a1eaf5d350`
If I add an # symbol in front of the word creationOptions. e.g. "#creationOptions" then no error when creating the Group, but then when I try to create the Team from this Group:
var team = new Microsoft.Graph.Team()
{
MemberSettings = new TeamMemberSettings()
{
AllowCreateUpdateChannels = false
},
MessagingSettings = new TeamMessagingSettings()
{
AllowUserEditMessages = false,
AllowUserDeleteMessages = false
},
FunSettings = new TeamFunSettings()
{
AllowGiphy = false
}
,
AdditionalData = new Dictionary<string, object>()
{
{"template#odata.bind", "https://graph.microsoft.com/v1.0/teamsTemplates('standard')"},
{"group#odata.bind", "https://graph.microsoft.com/v1.0/groups('" + grupo.Id + "')"}
}
};
graphClient.Teams.Request().AddAsync(team);
This error occurs:
Microsoft.Graph.ServiceException: 'Code: NotFound
Message: Failed to execute Templates backend request CreateTeamFromGroupWithTemplateRequest. Request Url: https://teams.microsoft.com/fabric/amer/templates/api/groups/9ee04411-993b-45f9-8d72-63343f703105/team, Request Method: PUT, Response Status Code: NotFound, Response Headers: Strict-Transport-Security: max-age=2592000
x-operationid: e922312859272d4ea8573cef70e37163
x-telemetryid: 00-e922312859272d4ea8573cef70e37163-0b5da564c6209441-00
X-MSEdge-Ref: Ref A: 34D331F1C0454DA7AE8CD7497D0558A7 Ref B: DM2EDGE1008 Ref C: 2021-04-09T15:16:22Z
Date: Fri, 09 Apr 2021 15:16:23 GMT
, ErrorMessage : {"errors":[{"message":"Failed to execute GetGroupAsync.","errorCode":"Unknown"}],"operationId":"e922312859272d4ea8573cef70e37163"}
Inner error:
AdditionalData:
date: 2021-04-09T15:16:24
request-id: d5ef1a33-d6d9-4d30-b9c5-83a7a477a1b5
client-request-id: d5ef1a33-d6d9-4d30-b9c5-83a7a477a1b5
ClientRequestId: d5ef1a33-d6d9-4d30-b9c5-83a7a477a1b5
'
You need to bind the correct template when POSTing to the /teams endpoint.
The educationClass template should create the right primitives in Teams and also set up the correct options under the hood in the Group.
From the POST /teams doc page:
POST https://graph.microsoft.com/beta/teams
Content-Type: application/json
{
"template#odata.bind": "https://graph.microsoft.com/beta/teamsTemplates('educationClass')",
"displayName": "My Class Team",
"description": "My Class Team’s Description"
}
The property doesn't appear to be defined in the metadata hence why it's not available in the SDK.
However, if you look at the definition for entity which group inherits from (via directory object), you'll find the additionalData property.
Setting the information there with something like the code snippet below should allow you to pass the desired information to the service.
AdditionalData = new Dictionary<string, object>()
{
{"#creationOptions", new List<string> { "classAssignments", "ExchangeProvisioningFlags:2509" } }
}
The # sign in front of the key is because this property is an instance annotation.
I have an error occurring that I can't seem to find anything about. When I run my code I get the following error. I am not setting oDataType so I assume this is something done by the api itself.
ServiceException: Code: RequestBodyRead Message: The property 'oDataType' does not exist on type microsoft.graph.itemBody'. Make sure to only use property names that are defined by the type or mark the type as open type.
My code is mostly copied from microsoft samples.
var confidentialClientApplication = ConfidentialClientApplicationBuilder
.Create(clientId)
.WithTenantId(tenantId)
.WithClientSecret(clientSecret)
.WithAuthority(new Uri(authority))
.Build();
ClientCredentialProvider authenticationProvider = new ClientCredentialProvider(confidentialClientApplication);
client = new GraphServiceClient(authenticationProvider);
var message = new Microsoft.Graph.Message()
{
Subject = "Test email",
Body = new ItemBody
{
ContentType = BodyType.Text,
Content = "Test email."
},
HasAttachments = false,
ToRecipients = new List<Recipient>()
{
new Recipient
{
EmailAddress = new EmailAddress
{
Address = "myemail#mydomain.com"
}
}
}
};
var saveToSentItems = false;
await client.Users[userID].SendMail(message, saveToSentItems).Request().PostAsync();
Any help would be greatly appreciated.
Thank you
I suspect, you're using a older library/build. I remember the related issue and it's fixed last year itself.
Please update it with the latest one , try testing the same and let us know if you can still repro the issue or not.
I want to create a specific class of assignments.
At Graph Explorer,
https://graph.microsoft.com/beta/education/classes/{classId}/assignments
This request works well.
But in my C# code,
var assignInfo = new EducationAssignment
{
DisplayName = "test",
DueDateTime = DateTimeOffset.Parse("2020-09-20T18:00:00Z"),
Instructions = new EducationItemBody
{
ContentType = BodyType.Html,
Content = "hi"
},
Status = EducationAssignmentStatus.Draft,
AllowStudentsToAddResourcesToSubmission = true,
AssignTo = new EducationAssignmentClassRecipient
{
},
Grading = new EducationAssignmentPointsGradeType()
{
MaxPoints = 100
},
CreatedDateTime = DateTimeOffset.Parse("2020-09-20T12:00:00Z"),
AssignDateTime = DateTimeOffset.Parse("2020-09-20T13:00:00Z"),
AssignedDateTime = DateTimeOffset.Parse("2020-09-20T13:00:00Z"),
CloseDateTime = null,
AllowLateSubmissions = true
};
await graphClient.Education.Classes[pClassId].Assignments
.Request()
.AddAsync(assignInfo);
It occured error:
{"Code: 20132\r\nMessage: The content of the request is invalid. Common causes are an invalid Content-Type header or no content in the body.\r\nInner error:\r\n\tAdditionalData:\r\n\tdate: 2020-09-20T07:25:14\r\n\trequest-id: d2181119-9116-4f1d-9ed4-d007e2e406d0\r\n\tclient-request-id: d2181119-9116-4f1d-9ed4-d007e2e406d0\r\nClientRequestId: d2181119-9116-4f1d-9ed4-d007e2e406d0\r\n"}
Why is this happening? I've been thinking and trying all day.
I tried
await graphClient.Education.Classes[pClassId].Assignments
.Request()
.Header("Content-Type", "application/json")
.AddAsync(assignInfo);
But there was the same error.
If only the displayname element was requested, the results were the same.
The Permissions has been dealt with.
EduAssignments.ReadWriteBasic, EduAssignments.ReadWrite.. etc
And the dll(NuGet pakage) is also prepared in beta version.
I referred to this document.
I'm desperate for help..
Thanks.
adding this assignInfo.ODataType = null; fixes the problem.
Could someone please help what does this error means
is it some connection issue?
operation performed on onpremise tfs server
here i am using TFS personal access token to do authorize operations.
Here is a code snippet creating a Bug work item in DevOps using HttpClient library, for your reference:
public class CreateBug
{
readonly string _uri;
readonly string _personalAccessToken;
readonly string _project;
public CreateBug()
{
_uri = "https://xxx.visualstudio.com";
_personalAccessToken = "xxx";
_project = "xxxxx";
}
public WorkItem CreateBugUsingClientLib()
{
Uri uri = new Uri(_uri);
string personalAccessToken = _personalAccessToken;
string project = _project;
VssBasicCredential credentials = new VssBasicCredential("", _personalAccessToken);
JsonPatchDocument patchDocument = new JsonPatchDocument();
//add fields and thier values to your patch document
patchDocument.Add(
new JsonPatchOperation()
{
Operation = Operation.Add,
Path = "/fields/System.Title",
Value = "Authorization Errors"
}
);
patchDocument.Add(
new JsonPatchOperation()
{
Operation = Operation.Add,
Path = "/fields/Microsoft.VSTS.Common.Priority",
Value = "1"
}
);
VssConnection connection = new VssConnection(uri, credentials);
WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient<WorkItemTrackingHttpClient>();
try
{
WorkItem result = workItemTrackingHttpClient.CreateWorkItemAsync(patchDocument, project, "Bug").Result;
Console.WriteLine("Bug Successfully Created: Bug #{0}", result.Id);
return result;
}
catch (AggregateException ex)
{
Console.WriteLine("Error creating bug: {0}", ex.InnerException.Message);
return null;
}
}
}
Due to error message text was having encoding issue, was not able to figure out the issue, Did debug on server and found out TTFS url with collection was not forming properly hence it was giving "page not found" error message, after that we fixed it by updating the tfs api url.
I want to create calendar (outlook) events via the microsoft graph api and set some specific response options.
In the (windows) Outlook client I am able to enable/disable
Request Response
Allow new Time Proposals
Allow Forwarding
In the documentation I can only find properties to enable/disable "Request Response" https://learn.microsoft.com/en-us/graph/api/user-post-events? but not the later ones.
The question is how to enable/disable Time Proposals and Forwarding?
I tried setting the sensitivity to "personal", "private" and "confidential" but it didn't help.
You can do that through the extended property DoNotForward. This has the following property definition:
PropertySet: 00020329-0000-0000-C000-000000000046
Name: DoNotForward
Type: Boolean
Here is an example I wrote for this.
Allow time proposal is:
PropertySet:00062002-0000-0000-C000-000000000046
Name: AppointmentNotAllowPropose
Type: Boolean
Using the ms-graph-sdk for dotnet the following code works:
var e = new Event()
{
Subject = "subject",
Start = new DateTimeTimeZone()
{
DateTime = dateTimeTimestamp1,
TimeZone = "Europe/Berlin"
},
End = new DateTimeTimeZone()
{
DateTime = dateTimeTimestamp2,
TimeZone = "Europe/Berlin"
},
SingleValueExtendedProperties = new EventSingleValueExtendedPropertiesCollectionPage()
{
new SingleValueLegacyExtendedProperty
{
Id = "Boolean {00020329-0000-0000-C000-000000000046} Name DoNotForward",
Value = "true"
},
new SingleValueLegacyExtendedProperty
{
Id = "Boolean {00062002-0000-0000-C000-000000000046} Id 0x825A",
Value = "true"
}
}
};
The AppointmentNotAllowPropose is referenced here by id, as setting the value by it's name somehow does not have an effect.