php-ews icon indicating copy to clipboard operation
php-ews copied to clipboard

How to take all events for all accounts

Open jlardinois opened this issue 8 years ago • 12 comments

Version (e.g. 1.0, dev-master): PHP version: 7.0 Microsoft Exchange version: 2016

Description of problem: In the example "event/find.php", I get the events of the account linked to the "username" and "password". I would like to get the events of all my accounts. Can you tell me if this is possible and how?

Thanks

jlardinois avatar Feb 08 '17 15:02 jlardinois

same question https://github.com/jamesiarmes/php-ews/issues/406. But Im still waiting for answers. By the way, in my opinion you may need a "master-username", that only has read-only right.

talalong avatar Feb 08 '17 21:02 talalong

Hello, I have an account administrator who can read other accounts but how to choose the account I want to read?

jlardinois avatar Feb 09 '17 06:02 jlardinois

If you have an account with impersonation privileges, you can use impersonation to get the events for other users, but you will need to make a separate request for each account. You can use the setImpersonation() method on the client to utilize impersonation.

jamesiarmes avatar Feb 09 '17 23:02 jamesiarmes

Perfect, it works

$ei = new ExchangeImpersonationType(); $sid = new ConnectingSIDType(); $sid->PrimarySmtpAddress = '[email protected]'; $ei->ConnectingSID = $sid; $client = new Client($host, $username, $password, $version); $client->setTimezone($timezone); $client->setImpersonation($ei);

But I have 200 accounts and I would like to have the event list of these on a specific day. As I have to return the headers each time, it takes 20 seconds.

Is there a way to reduce time ?

If I share all my calendars with an administrator account, can you list the shared events ?

jlardinois avatar Feb 10 '17 06:02 jlardinois

If the administrator is an attendee on each of the events, you should be able to get all events just using their account. You won't be able to update the events this way, though.

You may also be able to use delegation here, if the administrator is a delegate for each of the accounts. I haven't really worked with delegates, so I won't be of much help here, but you can find more information at https://msdn.microsoft.com/en-us/library/office/dn641956(v=exchg.150).aspx.

jamesiarmes avatar Feb 10 '17 15:02 jamesiarmes

Can I get alls events, that take place in a conference room using this below code?

$client = new Client($host, $username, $password, $version);
$client->setCurlOptions(array(CURLOPT_SSL_VERIFYPEER => false));

$email_room = "[email protected]";
$ei = new ExchangeImpersonationType();
$sid = new ConnectingSIDType();
$sid->PrimarySmtpAddress = $email_room;
$ei->ConnectingSID = $sid;

$start_date = new DateTime('l j 00:00:00');
$end_date = new DateTime('December 31 23:59:59');

$timezone = 'Central Europe Standard Time';
$client->setTimezone($timezone);
$client->setImpersonation($ei);

$request = new FindItemType();
$request->Traversal = ItemQueryTraversalType::SHALLOW;
$request->ItemShape = new ItemResponseShapeType();
$request->ItemShape->BaseShape = DefaultShapeNamesType::ALL_PROPERTIES;

$request->CalendarView = new CalendarViewType();
$request->CalendarView->StartDate = $start_date->format('c');
$request->CalendarView->EndDate = $end_date->format('c');

$request->ParentFolderIds = new NonEmptyArrayOfBaseFolderIdsType();
$request->ParentFolderIds->DistinguishedFolderId = new DistinguishedFolderIdType();
$request->ParentFolderIds->DistinguishedFolderId->Id = DistinguishedFolderIdNameType::CALENDAR;

$request->ParentFolderIds->DistinguishedFolderId->Mailbox = new stdClass();
$request->ParentFolderIds->DistinguishedFolderId->Mailbox->EmailAddress = $email_room;
$response = $client->FindItem($request);
var_dump($response);

talalong avatar Feb 14 '17 14:02 talalong

In order to get the events for a particular room, you need to set the mailbox on your parent folder id:

$folder_id = new DistinguishedFolderIdType();
$folder_id->Id = DistinguishedFolderIdNameType::CALENDAR;
$folder_id->Mailbox = new EmailAddressType();
$folder_id->Mailbox->EmailAddress = '[email protected]';

$request->ParentFolderIds->DistinguishedFolderId[] = $folder_id;

The user you are authorizing as must have at least reviewer rights to the room's mailbox in order to access its events.

jamesiarmes avatar Feb 14 '17 15:02 jamesiarmes

Yes I have access rights to room's mailbox, so that's why I am able to get all of its events using outlook, but not via ews. I don't know why I got this error:

[a:ErrorImpersonateUserDenied] The account is not authorized to accept the identity of the requested user.

talalong avatar Feb 15 '17 15:02 talalong

That means the account your authorizing as does not have permission to impersonate the user you're attempted to impersonate as. If you're trying to impersonate as a room, that won't work; you need to use the method I described above.

jamesiarmes avatar Feb 15 '17 15:02 jamesiarmes

KeyWord: impersonate you are the best. I had to escape $client->setImpersonation($ei). It works now. Thank you.

talalong avatar Feb 15 '17 16:02 talalong

@jlardinois Has your issue here been resolved?

jamesiarmes avatar Feb 15 '17 16:02 jamesiarmes

Hi Guys,

Thanks for the above inputs. I was also trying to pull events from meeting rooms to which the exchange admin provided impersonation rights.

Two questions :

  1. How can I get the meeting room location , that is the meeting room name ? "event/find.php" does pull the meeting events subject (title), start and end times, but not the location/meeting room name.
  2. Can we pull events from a meeting room calendar using a master account that has delegation rights to the meeting room calendar? We are trying to looking for a solution where we need not specify the target room mailbox smtp address. In the case of impersonation, we will need to specify the target room mailbox smtp address.

chandurajan avatar Dec 24 '20 07:12 chandurajan