Search code examples
calendaroutlookphp-ews

php-ews: Why isn't a calendar event's body a accessible from an event just like other attributes e.g subject/start-time?


For example, To access time and name of Calendar events, we can write:

    $startTime = $event->Start;
    $endTime = $event->End;
    $subject = $event->Subject;

But an event's body is not accessible by doing:

    $body = $event -> Body

Instead we have to create a separate response and look in the event's extended properties.


Solution

  • Good question. I just did some research on this a week or so ago. Basically, EWS has a concept of First Class Properties and Elements. This means that some properties aren't returned by FindItem and some are, most likely to save space. Items can contain over a hundred properties and their children can contain properties and so on and so forth, so to help keep things simple there are some properties that aren't returned in FindItem and some that are. Here's the quote from the documentation

    The set of first-class properties and elements that are returned by the EWS Managed API EmailMessage.Bind method and the EWS GetItem operation is slightly different than the set of first-class properties and elements that is returned by the EWS Managed API ExchangeService.FindItems method and the EWS FindItem operation.

    Note that you cannot extend the FindItems method or the FindItem operation to retrieve additional properties and elements such as ToRecipients, CcRecipients, and BccRecipients. If you need to retrieve those values, use the FindItems method or the FindItem operation to get the item IDs of the emails, and then use the Bind method or the GetItem operation, to retrieve the required properties

    So basically the answer boils down to "Because you EWS won't let you". If you want to know what properties are First Class and what aren't, there's a good page in the documentation with a table to help determine that, located here.

    Finally, might I suggest upgrading the library you're using for your EWS operations? I assume you're using jamesiarmes/php-ews which is the most popular from what I've seen, but I'm maintaining my own fork located at garethp/php-ews which is autoloadable, has a simple access API for some operations and is still under development.