Error encountered when creating event in Microsoft Graph explorer for c#
Error message:
StatusCode: 403, ReasonPhrase: 'Forbidden',
Codes :
- private static async Task<bool> CreateAppointmentAsync(HttpClient httpClient, EventModel eventModel)
- {
- var stringContent = JsonConvert.SerializeObject(eventModel);
- string URL = GraphResource + GraphVersion + "/me/calendar/events";
- var response = await httpClient.PostAsync(URL,
- new StringContent(stringContent, Encoding.UTF8, "application/json"));
-
-
- return response.IsSuccessStatusCode;
- }
- Event model
- public class EventModel
- {
- public string subject { get; set; }
- public Start start { get; set; }
- public End end { get; set; }
- public List<Attendees> Attendees { get; set; }
- }
- public class Start
- {
- public DateTime dateTime { get; set; }
- public string timeZone { get; set; }
- }
- public class End
- {
- public DateTime dateTime { get; set; }
- public string timeZone { get; set; }
- }
- public class Attendees
- {
- public EmailAddress emailAddress { get; set; }
- public string type { get; set; }
- }