An input string format problem occurred while creating the Event

Yan Leo 5 Reputation points
2024-03-21T07:18:30.7866667+00:00

I have an application utilizing the Microsoft.Graph DLL version 5.39.0. The functionality to list events was working smoothly. However, encountering an issue occurred when attempting to create an event, leading to failure while executing the following code:

 var result=await _userClient.Me.Events.PostAsync(requestBody, (requestConfiguration) =>
 {
     requestConfiguration.Headers.Add("Prefer", "outlook.timezone=\"China Standard Time\"");
 });


Error:
User's image

User's image My code (request body):

public static async Task<Event?> CreateEventAsync()
{
    var requestBody = new Event
    {
        Subject = "Quick discussion",
        Body = new ItemBody
        {
            ContentType = BodyType.Text,
            Content = "Book meeting",
        },
        Start = new DateTimeTimeZone
        {
            DateTime = "2024-03-22T14:00:00.0000000",
            TimeZone = "China Standard Time",
        },
        End = new DateTimeTimeZone
        {
            DateTime = "2024-03-22T14:30:00.0000000",
            TimeZone = "China Standard Time",
        },
        Location = new Location
        {
            DisplayName = "Room Uranus",
        },
        Attendees = new List<Attendee>
        {
            new Attendee
            {
                EmailAddress = new EmailAddress
                {
                    Address = "xxxx@user.com",
                    Name = "Room Uranus",
                },
                Type = AttendeeType.Required,
            }
        },
        AllowNewTimeProposals = true
    };
    var result=await _userClient.Me.Events.PostAsync(requestBody, (requestConfiguration) =>
    {
        requestConfiguration.Headers.Add("Prefer", "outlook.timezone=\"China Standard Time\"");
    });
    return result;
}

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,451 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,648 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yan Leo 5 Reputation points
    2024-03-21T09:09:23.3+00:00

    I resolved this issue by updating the permissions in the configuration file. Previously, the permission was set to calendar.read, but after changing it to calendar.readwrite, I successfully created the event. I think the error message is quite unclear; theoretically, it should indicate insufficient permissions.

    1 person found this answer helpful.
    0 comments No comments