I am developing a simple module that hooks into Membership Create, and then uses the information of the related contact to perform some other functions, like initiating a NextCloud account with the same email address and display name. There is a Contribution page in place, using a profile for members, and after the form is submitted the rest roles...
All is working well. Membership is created. Contact is created. The hook gets triggered after the Membership create. I can also get the associated contact ID with:
$contactId = $objectRef->contact_id;
But then when I use the API4 to retrieve contact details nothing is returned. Here is the code I received from Support>Developer>API4 Explorer:
$contacts = \Civi\Api4\Contact::get(TRUE)
->addSelect('display_name', 'email_primary.email')
->addWhere('id', '=', $contactId)
->setLimit(1)
->execute();
foreach ($contacts as $contact) {
// do something
}
The returned $contacts array is empty, even though it is present in the backend and $contactId has a value.
I made sure the membership group can be listed by public, but I dont think that should be an issue. Where else shall I look into? Any help is appreciated.