php ews return more than 1,000 contacts from Exchange Server

514 views Asked by At

How do I bring back all the contacts for one user from Exchange Server 2010 which throttles responses to 1000 using https://github.com/jamesiarmes/php-ews API? I tried paging but I need some example code to get it working.

2

There are 2 answers

0
Nbert. On

Have you tried to use different letters as initials? I thought of something like this:

$request->ContactsView->InitialName = 'A';
$request->ContactsView->FinalName = 'B';

This of would probably not work, if you have more than 1,000 contacts starting with the letter A.

0
Gareth Parker On

I can't provide you with an example for your library (I use my own fork, Garethp/php-ews) that I suggest you check out (It's PSR-2 and PSR-4 compatible with actual updates and maintainence), but they both basically have the same approach: help you write the XML that's sent to the server. So if you want an example, you can take a look at the MSDN pages and try to replicate the XML they have as PHP Objects. Here's what you want sent over

<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <t:RequestServerVersion Version="Exchange2010" />
  </soap:Header>
  <soap:Body>
    <m:FindItem Traversal="Shallow">
      <m:ItemShape>
        <t:BaseShape>AllProperties</t:BaseShape>
      </m:ItemShape>
      <m:IndexedPageItemView MaxEntriesReturned="3" Offset="5" BasePoint="Beginning" />
      <m:SortOrder>
        <t:FieldOrder Order="Ascending">
          <t:FieldURI FieldURI="contacts:DisplayName" />
        </t:FieldOrder>
      </m:SortOrder>
      <m:ParentFolderIds>
        <t:DistinguishedFolderId Id="contacts" />
      </m:ParentFolderIds>
    </m:FindItem>
  </soap:Body>
</soap:Envelope>

Note the <m:IndexedPageItemView MaxEntriesReturned="3" Offset="5" BasePoint="Beginning" />, that's how you look for the next page in a list of results