0

Currently, events are created on the outlook calendar from my portal now I want to apply colors when I create events using graph API

https://graph.microsoft.com/v1.0/me/calendar/events

I also follow Microsoft Documentation like

https://learn.microsoft.com/en-us/graph/api/calendar-post-events?view=graph-rest-1.0&tabs=csharp

but I am unable to find out how I pass color to the graph API when I create an event.Here is the sample code.

                    RestClient restClient = new RestClient();
                    RestRequest restRequest = new RestRequest();

                    restRequest.AddHeader("Authorization", "Bearer " + refresh_tokenObj.outlookTokenViewModel.access_token);
                    restRequest.AddHeader("Content-Type", "application/json");
                    restRequest.AddParameter("application/json", JsonConvert.SerializeObject(calendarEvent), ParameterType.RequestBody);

                    restClient.Options.BaseUrl = new Uri("https://graph.microsoft.com/v1.0/me/calendar/events");
                    var response = restClient.Post(restRequest);

                    if (response.StatusCode == System.Net.HttpStatusCode.Created)
                    {
                        dynamic data = JObject.Parse(response.Content);
                        eventId = data.id;
                        //return RedirectToAction("Index", "Home");
                    }
World News
  • 23
  • 1
  • 4

1 Answers1

1

Events in MS Outlook don't have colours on their own. Instead, you can assign a category to an event and that category has a colour. In the event API, categories property is what you are looking for.

And here is the resource you need to call to get or create new categories: https://learn.microsoft.com/en-us/graph/api/resources/outlookcategory?view=graph-rest-1.0

TLDR: category only has 2 properties: a displayName and color. Note that color is fixed - you can only use 25 default colours and you can't create arbitrary colours of your own.

Samuel
  • 2,430
  • 5
  • 31
  • 41