Garethp / php-ews

PHP Exchange Web Services
BSD 3-Clause "New" or "Revised" License
112 stars 46 forks source link

Can the getContacts function also work with Restrictions ? #193

Open PeteKraft opened 4 years ago

PeteKraft commented 4 years ago

I have a database of +20k contacts stored in Public Folders. I can access all the info, but is there a way that I can pull all information from 1 certain contact ?

I have tried this :

$firstPage = $api->getContacts($folder->getFolderId(), array(
    'ContactsView' => array('MaxEntriesReturned' => 1000),
    'IndexedPageItemView' => array ('MaxEntriesReturned' => 10, 'Offset' => 0, 'BasePoint' => 'Beginning'),
    'FolderShape' => array('BaseShape' => array('_' => 'AllProperties')),
    'Restriction' => array('IsEqualTo' => array('Subject' => 'john@doe.com'))
));

Looking at the getContacts, it seems this is not supported.

Might there be a better way to get all info related to one certain person ?

PeteKraft commented 4 years ago

I'm not sure where to look next, I simply can not get this to work. If anybody has any tips, I'd be very greatful.

In brief, I'm working with a Public Folder that holds all the company's contacts. I need to find a way to update certain contacts. I did find the example here, but the example does not search for an existing contact, it just updates the first contact it finds.

If I have an email address, or just a name, how can I perform a search inside a Public Folder to retrieve the ID, so I can use the ID to update the contact ?

Here's my complete code :

require_once '../../common/vendor/autoload.php';

use garethp\ews\API as API;
use garethp\ews\API\Enumeration;
use garethp\ews\API\Type;

// exchange login info
$host = 'xxx';
$username = 'xxx';
$password = 'xxx';

$api = API::withUsernameAndPassword($host, $username, $password);

$folder = $api->getFolderByDisplayName('Clients Folder', Enumeration\DistinguishedFolderIdNameType::PUBLICFOLDERSROOT);

$request = [
    'Traversal' => 'Shallow',
    'ItemShape' => [
        'BaseShape' => 'Default',
    ],
    'ParentFolderIds' => [
        'FolderId' => $folder->getFolderId()->toXmlObject()
    ],
    'IndexedPageItemView' => ['MaxEntriesReturned' => 10, 'Offset' => 0, 'BasePoint' => 'Beginning'],
    'Restriction' => [
        [
            'IsEqualTo' => [
                [
                    'FieldURI' => ['FieldURI' => 'contacts:EmailAddresses'],
                    'FieldURIOrConstant' => ['Constant' => ['Value' => 'john@doe.com']]
                ]
            ]
        ]
    ]
];

$request = Type::buildFromArray($request);

$response = $api->getClient()->FindItem($request);

echo "<pre>";
var_dump($response);
echo "</pre>";

This code just returns every contact it finds, it seems that the restriction is not taken into account.

I also tried with the ResolveNames function, but this only works on local folders, not public folders.

Any help is really, really appreciated.