如何在UWP应用程序中使用Microsoft Graph API将会议室分配给会议

时间:2017-09-26 12:23:31

标签: c# uwp microsoft-graph office365api

我正在调用API以在meeting上创建fixed date & time。我正在使用Microsoft Graph API。这是URL

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

我已经处理了身份验证部分,我的代码会执行以下操作来将JSON响应发送到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':'organizer@some.com'} }}";

        // 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 "";
        }

以下是我用来传递给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; }
    }
}

我的要求是向所有用户发送会议邀请,并提及Room Details like Name& Email ID of the room

我尝试在Location

下的请求中添加RoomEmail地址
public string RoomEmailAddress { get; set; }

当我使用Microsoft Graph Explorer网站测试时,我收到了错误消息

  

{       “错误”:{           “code”:“RequestBodyRead”,           “message”:“属性'RoomEmailAddress'在类型'Microsoft.OutlookServices.Location'上不存在。请确保仅使用   由类型定义的属性名称或将类型标记为打开   类型。”,           “innerError”:{               “request-id”:“1883d87d-a5d6-4357-a699-7c112da0e56b”,               “日期”:“2017-09-26T12:03:50”           }       }}

如何确保每当我创建meeting request时,我都可以为其分配room

目前我只能在将DisplayName发送到Request时传递URL。 删除Email Address property (I added myself )后,代码会返回Success

任何解决方法,以便我也可以发送room email address,以便会议室也收到meeting invite的副本?

1 个答案:

答案 0 :(得分:3)

"type": "Resource"作为与会者添加会议室。然后在location属性中添加会议室的显示名称。