Answers.Body: <p>Try changing <code>\Civi\Api4\Contact::get(TRUE)</code> to <code>\Civi\Api4\Contact::get(FALSE)</code></p>
  <p>The <code>TRUE</code>/<code>FALSE</code> parameter is a short-hand for <code>checkPermissions</code>.  The default in Api4 is that permissions <strong>are</strong> checked but you can disable that.  Obviously if you're going to disable permissions you need to consider who is running the code, what info it returns and how it is used.</p>
  <p>If your membership sign-up is used without logging in (anonymous users) then they won't have access to use the API, but you still want this to run so bypassing permissions checking is appropriate.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-02-14T09:56:58.720Z
Answers.LastActivityDate: 2024-02-14T09:56:58.720Z
Answers.UserDisplayName: Aidan
Body: <p>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...</p>
  <p>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:</p>
  <pre><code>$contactId = $objectRef-&gt;contact_id;
  </code></pre>
  <p>But then when I use the API4 to retrieve contact details nothing is returned. Here is the code I received from Support&gt;Developer&gt;API4 Explorer:</p>
  <pre><code>    $contacts = \Civi\Api4\Contact::get(TRUE)
    -&gt;addSelect('display_name', 'email_primary.email')
    -&gt;addWhere('id', '=', $contactId)
    -&gt;setLimit(1)
    -&gt;execute();
  foreach ($contacts as $contact) {
    // do something
  }
  </code></pre>
  <p>The returned $contacts array is empty, even though it is present in the backend and $contactId has a value.</p>
  <p>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.</p>
  
Tags: <civicrm-entity><apiv4><civicontact>
Title: Retrieving Contact information with API4 Inside the module
ThreadText: # Retrieving Contact information with API4 Inside the module
  
  (Asked by: username_0 on 2024-02-14)
  
  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.
  
  **Tags:** civicrm-entity, apiv4, civicontact
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2024-02-14. Score: 3 | Accepted answer
  
  Try changing `\Civi\Api4\Contact::get(TRUE)` to `\Civi\Api4\Contact::get(FALSE)`
  
  The `TRUE`/`FALSE` parameter is a short-hand for `checkPermissions`. The default in Api4 is that permissions **are** checked but you can disable that. Obviously if you're going to disable permissions you need to consider who is running the code, what info it returns and how it is used.
  
  If your membership sign-up is used without logging in (anonymous users) then they won't have access to use the API, but you still want this to run so bypassing permissions checking is appropriate.
  
  
  ---
  
  