I'm using EWS (Exchange Web Services) to access data from my Exchange 2013 test Server. I'm doing this using PHP with the (somewhat dated) php-ews repository: github-jamesiarmes-php-ews and the newer and composer enabled version: github-deakin-php-ews
I can do the basic calls to my Exchange service as described in the wiki from 'jamesiarmes', but ran in to some troubles when I tried to use the GroupBy method: How to: Perform grouped searches by using EWS in Exchange
As you can see in the XML response from the How-to guide, normally the <Groups>
element should contain zero or more <GroupItems>
who would then contain the items (in my case CalendarItems). But what I got back from my test server were <Group>
elements in stead of <GroupItems>
which caused my $response object to be incomplete.
The code I used:
$request = new FindItemType();
$request->Traversal = ItemQueryTraversalType::SHALLOW;
$request->ItemShape = new ItemResponseShapeType();
$request->ItemShape->BaseShape = DefaultShapeNamesType::ALL_PROPERTIES;
// Define the time frame to load calendar items
$request->CalendarView = new CalendarViewType();
$request->CalendarView->StartDate = '2014-01-12T15:18:34+03:00';
$request->CalendarView->EndDate = '2015-01-12T15:18:34+03:00';
// Find events from a certain folders
$request->ParentFolderIds = new NonEmptyArrayOfBaseFolderIdsType();
$request->ParentFolderIds->FolderId = new FolderIdType();
$request->ParentFolderIds->FolderId->Id = $calendarFolderUID;
// Group the events by date
$request->GroupBy = new GroupByType();
$request->GroupBy->Order = 'Ascending';
$request->GroupBy->FieldURI = new FieldURIOrConstantType();
$request->GroupBy->FieldURI->FieldURI = 'calendar:Start';
$request->GroupBy->AggregateOn = new AggregateOnType();
$request->GroupBy->AggregateOn->Aggregate = 'Minimum';
$request->GroupBy->AggregateOn->FieldURI = new FieldURIOrConstantType();
$request->GroupBy->AggregateOn->FieldURI->FieldURI = 'calendar:End';
$response = $this->soapService->FindItem($request);
This is the var_dump()
from $response
:
object(stdClass)#685 (1) {
["ResponseMessages"]=>
object(stdClass)#690 (1) {
["FindItemResponseMessage"]=>
object(stdClass)#714 (3) {
["ResponseCode"]=>
string(7) "NoError"
["ResponseClass"]=>
string(7) "Success"
["RootFolder"]=>
object(stdClass)#715 (3) {
["Groups"]=>
object(stdClass)#716 (0) {
}
["IncludesLastItemInRange"]=>
bool(true)
["TotalItemsInView"]=>
int(4)
}
}
}
}
I managed to collect the XML response using __getLastResponse()
(PHP docs) and found it did get all the wanted items, but in the <Group>
element instead of the <GroupItems>
which cased the SoapClient to return an empty object for the <Groups>
element.
Now I'm wondering where the problem lies:
- Is the How-to Guide outdated? I didn't find any reference to this
<Group>
element in the other documentation from EWS, so I don't think that is the issue. - Is my Exchange server using another XML schema or just plain weird?
- Are the php-ews schemas outdated? Should I fork the 'deakin' repo with an eventual solution?
I already found a way to make it work by adjusting the php-ews schemas, but if the problem is my test server, I don't need to bother making a fork... I'll post my current solution below also.
I would appreciate any input on this....