Skip to content

Missing property $parentCollection exception on addChild()-call #357

Description

@menglisch

The following code throws an exception:

// $tenantName, $privateKey, $clientId, $thumbprint are provided but left out here

$client = new GraphServiceClient(function () use ($tenantName, $privateKey, $clientId, $thumbprint) {
	$resource = "https://graph.microsoft.com";
	$provider = new AADTokenProvider($tenantName);
	$credentials = new CertificateCredentials($resource, $clientId, $privateKey, $thumbprint, ['https://graph.microsoft.com/.default']);

	return $provider->acquireTokenForClientCertificate($credentials);
});

$user = $client->getUsers()->getByUserPrincipalName('smith@example.com');

/** @var \Office365\Outlook\Events\Event $event */
$event = $user->getEvents()->add();

$start = new DateTimeTimeZone();
$start->DateTime = '2025-10-01';
$start->TimeZone = 'Europe/Berlin';
$event->setStart($start);
$event->setIsAllDay(true);
$event->setBody(new ItemBody(0, 'Test'));

$addedChildQuery = $user->getEvents()->addChild($client); // here is the exception thrown
$addedChildQuery->executeQuery();

But an exception is thrown:

   ErrorException

   Undefined property: Office365\GraphServiceClient::$parentCollection

  at vendor/vgrem/php-spo/src/Runtime/ClientObjectCollection.php:138
    134▕      */
    135▕     public function addChild($clientObject)
    136▕     {
    137▕         $this->data[] = $clientObject;
  ➜ 138▕         if (is_null($clientObject->parentCollection))
    139▕             $clientObject->parentCollection = $this;
    140▕         return $this;
    141▕     }
    142▕

What am I doing wrong?
Does anybody know how to create an event in Office 365 with this library?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugruntimeCore library functionality: HTTP handling, parsing, serialization, internalssharepointSharePoint Online or On-Premises API issues

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions