Peter Hike
Peter Hike

Reputation: 23

Create Master Category Via Microsoft Graph API

Im Trying to create a new category via an event for outlook. Below is what I have so far.

  using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AdviserBearerToken);
                client.DefaultRequestHeaders.Accep.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                var categoryName = new List<string>();
                categoryName.Add("New Event");

                var startTime = new Time();
                var endTime = new Time();
                startTime.DateTime = "2016-07-15T15:00:00.0000000";
                startTime.TimeZone = "UTC";
                endTime.DateTime = "2016-07-15T15:30:00.0000000";
                endTime.TimeZone = "UTC";

                var eventModel = new EventModelForGraph
                {
                    categories = categoryName,
                    subject = "This is an event",
                    Start = startTime,
                    End = endTime

                };
                var serializedObject = JsonConvert.SerializeObject(eventModel);
                var createBody = new StringContent(serializedObject, System.Text.Encoding.UTF8, "application/json");
                var response = await client.PostAsync("https://graph.microsoft.com/v1.0/me/calendar/events", createBody);

                var responseString = await response.Content.ReadAsStringAsync();
            }

The event shows up in the calendar and the category as the header but it is not listed under the categorize tab which leads me to my question. Is it possible to create such a category using the API?

Upvotes: 2

Views: 927

Answers (2)

awh112
awh112

Reputation: 1484

I know this is an older question, but I was looking into the same thing and figured I'd post an update. This is now possible with the current version of the Graph API. You can see the documentation here from MSDN. You can create categories by sending a POST API request:

POST https://graph.microsoft.com/beta/me/outlook/masterCategories
Content-type: application/json
Content-Length: 70

{
      "displayName":"Project expenses",
      "color":"preset9"
}

After the category is created, you can assign it when you create your event by adding the category's displayName property to the categories collection of the item.

You can find more details about when these API endpoints were added here and more details about categories here.

Upvotes: 1

Jason Johnston
Jason Johnston

Reputation: 17702

No, you cannot add categories to the master category list via the REST API. You cannot add them directly via any API.

However, you CAN modify the list if you're willing to manipulate the XML directly. The gory details are documented in MS-OXOCFG. You can use EWS for example to access the config item.

This would be a great feature to add to the REST API. You should suggest it on UserVoice.

Upvotes: 0

Related Questions