jamesiarmes / php-ews

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

Error during request or responce with error when creating recurring CalendarItem event #616

Open ValerianMemsk opened 1 year ago

ValerianMemsk commented 1 year ago

Version (e.g. 1.0, dev-master): PHP version: 8.1 Microsoft Exchange version: 2013 (if i assume correctly)

Description of problem: Trying to create CalendarItem event in exchange calendar with user-provided data. Simple ones and with partisipants working fine. But when I try to add recurrence in those events - nothing works. Watched similar questions here and on stackoverflow - they seem outdated. Tried to implement them with v1.0 classes - didnt work What am I doing wrong?

Example request:

Tried daily and weekly recurrence.

    $request = new CreateItemType();
    $request->Items = new NonEmptyArrayOfAllItemsType();

    //Event accembly---------------------------
    $event = new CalendarItemType();

    $event->Start = $eventData['startTime'];
    $event->End = $eventData['endTime'];
    $event->Subject = $eventData['subject'];
    $event->Location = $eventData['location'];

    //In case event is recurring---------------
    if ($eventData['isRecurring']) {
      $event->CalendarItemType = CalendarItemTypeType::RECURRING_MASTER;
      $recurrence = new RecurrenceType();

      switch ($eventData['recurrenceDetails']['type']) {
        case 'daily':
          $recurrence->DailyRecurrence = new DailyRecurrencePatternType();
          $event->Recurrence = $recurrence;
          break;

        case 'weekly':

          $weeklyRecurrenceInfo = new WeeklyRecurrencePatternType();
          $weeklyRecurrenceInfo->Interval = $eventData['recurrenceDetails']['interval'];
          $weeklyRecurrenceInfo->DaysOfWeek = new ArrayOfStringsType();
          $weeklyRecurrenceInfo->DaysOfWeek = [DayOfWeekType::THURSDAY];

          $recurrence->WeeklyRecurrence = $weeklyRecurrenceInfo;
          $event->Recurrence = $recurrence;
          break;
      }
    }  

    $eventBody = new BodyType();
    $eventBody->_ = $eventData['description'];
    $eventBody->BodyType = BodyTypeType::TEXT;

    $event->Body = $eventBody;

    $request->Items->CalendarItem[] = $event;
    //--------------------------------------------

    $request->SendMeetingInvitations = CalendarItemCreateOrDeleteOperationType::SEND_TO_NONE;

    $response = $this->client->CreateItem($request);
    return $response;    

Example response:

Daily option leads to

local.ERROR: The request is invalid. {"userId":11,"exception":"[object] (SoapFault(code: 0 faultcode: a:ErrorInvalidRequest detail: {\"ResponseCode\":\"ErrorInvalidRequest\",\"Message\":\"The request is invalid.\"}): The request is invalid. at /var/www/html/vendor/php-ews/php-ews/src/Client.php:1631)

Weekly to response with:

+CreateItemResponseMessage: array:1 [▼
      0 => jamesiarmes\PhpEws\Response\ItemInfoResponseMessageType {#2516 ▼
        +DescriptiveLinkKey: 0
        +MessageText: "Set action is invalid for property."
        +MessageXml: {#2495 ▼
          +"any": array:1 [▼
            "FieldURI" => jamesiarmes\PhpEws\Type\PathToUnindexedFieldType {#2493 ▼
              +FieldURI: "calendar:CalendarItemType"
            }
          ]
        }
        +ResponseClass: "Error"
        +ResponseCode: "ErrorInvalidPropertySet"
        +Items: jamesiarmes\PhpEws\ArrayType\ArrayOfRealItemsType {#2517 ▶}
      }
    ]

Additional details: