Search code examples
phpoutlookexchangewebservicesphp-ews

Get a list of contacts in a distribution list using php-ews API


I am using PHP-EWS to get a list of contact. This list of contact is a distribution list in the Contacts root folder.

Actually I am using this:

$ews = new ExchangeWebServices($server, $username, $password);


$request = new EWSType_FindItemType();

$request->ItemShape = new EWSType_ItemResponseShapeType();
$request->ItemShape->BaseShape = EWSType_DefaultShapeNamesType::ALL_PROPERTIES;

$request->ContactsView = new EWSType_ContactsViewType();
$request->ContactsView->InitialName = 'a';
$request->ContactsView->FinalName = 'z';


$request->ParentFolderIds->DistinguishedFolderId = new EWSType_DistinguishedFolderIdType();
 $request->ParentFolderIds->DistinguishedFolderId->Id = EWSType_DistinguishedFolderIdNameType::CONTACTS;

$request->Traversal = EWSType_ItemQueryTraversalType::SHALLOW;

$response = $ews->FindItem($request);

I am able to get the ID of the Distribution List, but I can't get the emails address in it. How could I get a stdClass Object of it or an array?


Solution

  • In order to get the contacts inside of a contact group, you need to use the ExpandDL operation, passing the item ID of the contact group you want to expand. I'm not familiar enough with the php-ews library to give you sample code, but hopefully this points you in the right direction. See this link for an example of what the SOAP request looks like.