Apoorv
Apoorv

Reputation: 2043

How to assign Room to an Event for meeting using Microsoft Graph API in a UWP App

I am calling the API for creating a meeting on a fixed date & time. I am using Microsoft Graph API for this. Here is the URL

var url = "https://graph.microsoft.com/v1.0/me/events";

I have taken care of the Authentication part and my code does the following thing to send the JSON response to the API

  private async void sendInvites_Click(object sender, RoutedEventArgs e)
    {
        var httpClient = new System.Net.Http.HttpClient();
        System.Net.Http.HttpResponseMessage response;
        var url = "https://graph.microsoft.com/v1.0/me/events";
        CIBC.Models.SendMeetingInvites.RootObject obj = new CIBC.Models.SendMeetingInvites.RootObject();
        CIBC.Models.SendMeetingInvites.Location loc = new CIBC.Models.SendMeetingInvites.Location();
        loc.displayName = GlobalVariables.MeetingRoomName;
        //loc.RoomEmailAddress = GlobalVariables.meetingRoomEmailID.ToString();

        obj.subject = "Maths";
        CIBC.Models.SendMeetingInvites.Body body = new CIBC.Models.SendMeetingInvites.Body();
        body.content = "Its a booking for follow up meeting";
        body.contentType = "HTML";
        obj.body = body;

        List<CIBC.Models.SendMeetingInvites.Attendee> attens = new List<Models.SendMeetingInvites.Attendee>();
        for(int i=0;i<GlobalVariables.NumberOfParticipant.Count;i++)
        {
            CIBC.Models.SendMeetingInvites.EmailAddress email = new CIBC.Models.SendMeetingInvites.EmailAddress();
            CIBC.Models.SendMeetingInvites.Attendee atten = new CIBC.Models.SendMeetingInvites.Attendee();
            email.address = GlobalVariables.NumberOfParticipant[i].ParticipantADdress;
            atten.emailAddress = email;
            atten.type = "Required";
            attens.Add(atten);
        }
        CIBC.Models.SendMeetingInvites.Start start = new CIBC.Models.SendMeetingInvites.Start();
        start.dateTime = GlobalVariables.sendMeetingInviteStartDate;
        start.timeZone = "UTC";
        obj.start = start;


        CIBC.Models.SendMeetingInvites.End end = new CIBC.Models.SendMeetingInvites.End();
        end.dateTime = GlobalVariables.sendMeetingInviteEndTime;
        end.timeZone = "UTC";
        obj.end = end;
        obj.attendees = attens;
        obj.location = loc;

        string postBody = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
      //  var postBody1 = "{'Subject':'Testing Organizer - 12','Location':{'DisplayName':'Some place'}," +
      //"'Start': {'DateTime': '2016-07-15T15:00:00.0000000', 'TimeZone':'UTC'}," +
      //"'End': {'DateTime': '2016-07-15T15:30:00.0000000', 'TimeZone':'UTC'}," +
      //"'Body':{'Content': 'This is a test of Grap API.', 'ContentType':'Text'}," +
      //"'IsOrganizer':'False','Organizer':{'EmailAddress': " + "{'Address':'[email protected]'} }}";

        // var requestString = @"{"subject":"My event","start":{"dateTime":"2017-09-25T07:44:27.448Z","timeZone":"UTC"},"end":{"dateTime":"2017-10-02T07:44:27.448Z","timeZone":"UTC"}}"";

        var request = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Post, url);
            //Add the token in Authorization header
            request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer",GlobalVariables.Token);
        request.Content = new StringContent(postBody, UTF8Encoding.UTF8, "application/json");
        response = await httpClient.SendAsync(request);
            if (response.IsSuccessStatusCode)
        { }
               // return await response.Content.ReadAsStringAsync();
            else
        {

        }
                //return "";
        }

Here is the class file that I am using to pass to the HTTPResponse Message

namespace CIBC.Models.SendMeetingInvites
{

    public class Body
    {
        public string contentType { get; set; }
        public string content { 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 Location
    {
        public string displayName { get; set; }
        //public string RoomEmailAddress { get; set; }
    }

    public class EmailAddress
    {
        public string address { get; set; }
        public string name { get; set; }
    }

    public class Attendee
    {
        public EmailAddress emailAddress { get; set; }
        public string type { get; set; }
    }

    public class RootObject
    {
        public string subject { get; set; }
        public Body body { get; set; }
        public Start start { get; set; }
        public End end { get; set; }
        public Location location { get; set; }
        public List<Attendee> attendees { get; set; }
    }
}

My requirement is to send a meeting invite to all the users and also mentioning the Room Details like Name& Email ID of the room.

I tried adding a RoomEmail address in the Request as under The Location class

public string RoomEmailAddress { get; set; }

When I tested this using Microsoft Graph Explorer website , i got the error message

{ "error": { "code": "RequestBodyRead", "message": "The property 'RoomEmailAddress' does not exist on type 'Microsoft.OutlookServices.Location'. Make sure to only use property names that are defined by the type or mark the type as open type.", "innerError": { "request-id": "1883d87d-a5d6-4357-a699-7c112da0e56b", "date": "2017-09-26T12:03:50" } } }

How do I make sure that whenever I create a meeting request , I can assign a room to it?

Currently I am just able to pass DisplayName while sending the Request to the URL. Once I remove the Email Address property (I added myself ), the code returns Success.

Any workarounds so that I can send the room email address also so that the room also receives a copy of the meeting invite ?

Upvotes: 3

Views: 1912

Answers (1)

Jason Johnston
Jason Johnston

Reputation: 17702

Add the room as an attendee with "type": "Resource". Then add the room's display name in the location property.

Upvotes: 5

Related Questions