jamesiarmes / php-ews

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

Create Public Folder Calendar Event #267

Open xand49 opened 9 years ago

xand49 commented 9 years ago

I'm attempting to plug a php based calendar management system into exchange 2007 calendars.

I have the below code setup at present.

$subject = 'Appointment with ..';

    $request = new EWSType_CreateItemType();
    $request->Items = new EWSType_NonEmptyArrayOfAllItemsType();
    $request->Items->CalendarItem = new EWSType_CalendarItemType();

    $request->Items->CalendarItem->Subject = $subject;

    $date1 = new DateTime('2015-05-10T15:00:00+03:00');
    $DateStart = $date1->format('Y-m-d H:i:00');
    $date = new DateTime($DateStart);
    $request->Items->CalendarItem->Start = $date->format('c');
    $date1 = new DateTime('2015-05-10T17:00:00+03:00');
    $DateEnd = $date1->format('Y-m-d H:i:00');
    $date = new DateTime($DateEnd);
    $request->Items->CalendarItem->End = $date->format('c');

    $request->Items->CalendarItem->ReminderIsSet = false;

    $request->Items->CalendarItem->ReminderMinutesBeforeStart = 15;

    $request->Items->CalendarItem->Body = new EWSType_BodyType();
    $request->Items->CalendarItem->Body->BodyType = EWSType_BodyTypeType::HTML;

$request->Items->CalendarItem->Body->_ = <<<EOD

<p><strong>Staff Attending</strong>:bob</p>

    $request->Items->CalendarItem->ItemClass = new EWSType_ItemClassType();
    $request->Items->CalendarItem->ItemClass->_ = EWSType_ItemClassType::APPOINTMENT;

    $request->Items->CalendarItem->Sensitivity = new EWSType_SensitivityChoicesType();
    $request->Items->CalendarItem->Sensitivity->_ = EWSType_SensitivityChoicesType::NORMAL;

    $request->Items->CalendarItem->Categories = new EWSType_ArrayOfStringsType();
    $request->Items->CalendarItem->Categories->String = array(
        'Client Meeting (Scheduled)'
    );

    $request->Items->CalendarItem->Location = "Showroom";

    $request->SendMeetingInvitations = EWSType_CalendarItemCreateOrDeleteOperationType::SEND_ONLY_TO_ALL;
    $request->Items->CalendarItem->RequiredAttendees->Attendee[0]->Mailbox->EmailAddress = "user@domain.com";
    $request->Items->CalendarItem->RequiredAttendees->Attendee[0]->Mailbox->RoutingType  = 'SMTP';
    $n = 1;

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

This will setup an event in the users personal calendar just fine, but what I need to do is to get it to post to a public folder calendar which I have the folderID for.

If anyone could assist it would be greatly appreciated.

xand49 commented 9 years ago

bump.

heiangus commented 9 years ago

Try adding the line:

    $request->SavedItemFolderId->FolderId->Id=$folder_id;

after the $request = new EWSType_CreateItemType();

where $folder_id is your stupidly long microsoft folder id!!!!

(I also answered your same question on stackoverflow, please mark as the answer there if it works, thanks:-)

xand49 commented 9 years ago

had an error as per stack by just adding that line, added the following block and I received no error messages, however it doesn't actually add the event.

$request->SavedItemFolderId = new EWSType_TargetFolderIdType(); $request->SavedItemFolderId->FolderId = new EWSType_FolderIdType(); $request->SavedItemFolderId->FolderId->Id=$folderID;

heiangus commented 9 years ago

you could also try:

$request->SavedItemFolderId->DistinguishedFolderId->Id = 'calendar'; $request->SavedItemFolderId->DistinguishedFolderId->Mailbox->EmailAddress = 'email@domain.com'

using the email address of the folder (that's easy to set in exchange)

murraycollingwood commented 8 years ago

I have spent a couple of days trying numerous variations of the above. I'm generally getting one of these errors depending on the settings: "The request failed schema validation: The 'id' attribute is not declared." "The request failed schema validation: The 'Id' attribute is invalid"

I have the (stupidly long) folder id value.

Has anybody solved this problem?
Could you please post an example if you got this to work. It might be handy to know if you didn't get it to work, maybe James will give us some help?

murraycollingwood commented 8 years ago

(bump) Does anybody have an example of creating a booking for a RoomMailbox?

uo-hrsys commented 7 years ago

related: https://github.com/jamesiarmes/php-ews/issues/154

Although It never works for me