Joe Healy
Joe Healy

Reputation: 5817

Create Graph Event with Room as location using C# and Microsoft.Graph nuget

Not sure how to do the location with a room in C# and Microsoft.Graph.

I want to create an event that would put the event in a room. I now the room’s email - [email protected] . The code I am trying is as follows using Microsoft.Graph.

        Microsoft.Graph.PhysicalAddress address = new Microsoft.Graph.PhysicalAddress();
        Microsoft.Graph.Location loc = new Location();
        loc.Address = address;
        loc.DisplayName = "Rainier conf room";
        loc.LocationEmailAddress = rainier;

        var newEvent = new Event();
        newEvent.Subject = subject + DateTime.Now.ToLongDateString();
        newEvent.Location = loc;
        newEvent.Attendees = attendees;
        newEvent.Body = eventBody;
        newEvent.Start = eventStartTime;
        newEvent.End = eventEndTime;

        Microsoft.Graph.Event createdEvent = null;
        try
        {
            // graphclient is passed into this method
            // var graphClient = AuthenticationHelper.GetAuthenticatedClient();
            // var graphClient = devfish.Graph.AuthenticationHelper.MyGraphClient;

            createdEvent = await graphClient.Me.Events.Request().AddAsync(newEvent);

The payload I am sending up SHOULD look something like this, but what it doesn’t look like is below. Outlook doesn’t treat it as a “room”. Thanks…

PAYLOAD WE WANT - note the odatatype and microsoft.graph.physicaladdress ...

{
  "subject": "Test meeting",
  "body": {
    "contentType": "HTML",
    "content": "Does this work (note the dates are in the past)?"
  },
  "start": {
      "dateTime": "2017-12-01T12:00:00",
      "timeZone": "Pacific Standard Time"
  },
  "end": {
      "dateTime": "2017-12-01T14:00:00",
      "timeZone": "Pacific Standard Time"
  },
  "location":{
    "address": {"@odata.type": "microsoft.graph.physicalAddress"},
    "displayName": "Rainier conf room"
  },
  "attendees": [
    {
      "emailAddress": {
        "address":"[email protected]",
        "name": "Joe"
      },
      "type": "required"
    },
    {
      "emailAddress": {
        "address":"[email protected]",
        "name": "Rainier"
      },
      "type": "Resource"
    }
  ]
}

But instead up payload looks like this when created with C# graph.

{
    "subject": "23: 42:39: BASKETBALL IS OUR SUBJECT FOR TODAYTuesday, January 9, 2018",
    "body": {
        "contentType": "text",
        "content": "Status updates, blocking issues, and next steps"
    },
    "start": {
        "dateTime": "2017-12-01T19:30:00.0000000",
        "timeZone": "UTC"
    },
    "end": {
        "dateTime": "2017-12-01T20:00:00.0000000",
        "timeZone": "UTC"
    },
    "location": {
        "displayName": "Rainier conf room",
        "locationEmailAddress": "[email protected]",
        "address": {}
    },
    "attendees": [
        {
            "type": "required",
            "emailAddress": {
                "address": "[email protected]"
            }
        },
        {
            "type": "required",
            "emailAddress": {
                "address": "[email protected]"
            }
        },
        {
            "type": "resource",
            "emailAddress": {
                "address": "[email protected]"
            }
        }
    ]
}

Thanks for any help.

Upvotes: 1

Views: 1054

Answers (1)

Michael Mainer
Michael Mainer

Reputation: 3475

To get the payload you want, you'll need to:

  1. Remove loc.LocationEmailAddress = rainier;
  2. Add the key-value "@odata.type", "microsoft.graph.physicalAddress" to location.AdditionalData. We had someone else recently ask for automatic @odata.type generation so this is an additional data point for that.
  3. Add the name property to the room emailAddress object.

Upvotes: 1

Related Questions