jamesiarmes / php-ews

PHP Exchange Web Services
http://jamesarmes.com/php-ews/
MIT License
567 stars 302 forks source link

Unable to Cancel item...ErrorCalendarIsNotOrganizer: User must be an organizer for CancelCalendarItem action #542

Open robp2175 opened 5 years ago

robp2175 commented 5 years ago

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

Description of problem: When trying to cancel an event, I am getting this error "ErrorCalendarIsNotOrganizer: User must be an organizer for CancelCalendarItem action"

Example request:


use \jamesiarmes\PhpEws\Client;
use \jamesiarmes\PhpEws\Request\CreateItemType;
use \jamesiarmes\PhpEws\ArrayType\NonEmptyArrayOfAllItemsType;
use \jamesiarmes\PhpEws\Enumeration\MessageDispositionType;
use \jamesiarmes\PhpEws\Enumeration\ResponseClassType;
use \jamesiarmes\PhpEws\Type\CancelCalendarItemType;
use \jamesiarmes\PhpEws\Type\ItemIdType;
// Replace these values with those of the event you wish to cancel.
$event_id = 'AAMkAGExYjQ5YjAwLTlkZjEtNDM4ZC04ZTE5LT28904zYWU3NTMyNwBGAAAAAADyWoBA9saWRZHq6hrI2pbBBwCWBmIqwrICRa7HO4qAshD3AAAAAAENAACWBmIqwrICRa7HO4qAshD3AAFdMjqWAAA=';
$change_key = 'DwAAABYAAACWBmIqwrICRa7HO4qAshD3AAFdNdZz';
// Set connection information.
$host = 'exchange.domain.edu';
$username = 'events@emcc.edu';
$password = 'password';

$version = Client::VERSION_2013;
$client = new Client($host, $username, $password, $version);
$request = new CreateItemType();
$request->MessageDisposition = MessageDispositionType::SEND_AND_SAVE_COPY;
$request->Items = new NonEmptyArrayOfAllItemsType();
$cancellation = new CancelCalendarItemType();
$cancellation->ReferenceItemId = new ItemIdType();
$cancellation->ReferenceItemId->Id = $event_id;
$cancellation->ReferenceItemId->ChangeKey = $change_key;
$request->Items->CancelCalendarItem[] = $cancellation;
$response = $client->CreateItem($request);
// Iterate over the results, printing any error messages.
$response_messages = $response->ResponseMessages->CreateItemResponseMessage;
foreach ($response_messages as $response_message) {
    // Make sure the request succeeded.
    if ($response_message->ResponseClass != ResponseClassType::SUCCESS) {
        $code = $response_message->ResponseCode;
        $message = $response_message->MessageText;
        echo       "Cancellation failed to create with \"$code: $message\"\n";
        continue;
    }
}

Example response:

Cancellation failed to create with "ErrorCalendarIsNotOrganizer: User must be an organizer for CancelCalendarItem action."

Additional details: The Ornaizer property appears to be correct in the item array

[IsOrganizer] => 1

Thank you for any assistance you may be able to provide

jamesiarmes commented 5 years ago

If you perform a GetItem request on the event, is the organizer the same user you're authenticating as?

sumit79 commented 5 years ago

I have a point here i think we need something like decline event. I have made a delegate to a user for a room account. I can access calendar but i want to decline some time but can't find an api to do that.