Answers.Body: <p>First of all I would recommend using API4 for this. If you want to get the custom data with API3 you should be able to do this by returning the &quot;custom_&quot; + id of the custom field like so:</p>
  <pre><code>$result = civicrm_api3('Contact', 'get', [
    'sequential' =&gt; 1,
    'return' =&gt; [&quot;custom_4&quot;],
  ]);
  </code></pre>
  <p>And perhaps you can achieve what you want with something like:</p>
  <pre><code>$result = civicrm_api3('Contact', 'getcount', [
    'custom_4' =&gt; ['IS NOT NULL' =&gt; 1],
  ]);
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-20T12:58:33.327Z
Answers.Text: Thanks, could you also share the approach for API4, is it more flexible?
Answers.UserDisplayName: kenorb
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-21T13:46:56.267Z
Answers.Text: Yes, but you can try with the API4 explorer in your install? And check this documentation: https://docs.civicrm.org/dev/en/latest/api/v4/usage/
Answers.UserDisplayName: ErikH - CiviCooP
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-20T06:43:25.767Z
Answers.LastActivityDate: 2023-04-20T06:43:25.767Z
Answers.UserDisplayName: ErikH - CiviCooP
Body: <p>I've custom data stored in custom fields. I've submitted few records as part of the same Contact.</p>
  <p>I can use the following API to fetch information about custom group by:</p>
  <pre><code>$result = civicrm_api3('CustomGroup', 'get', ['id' =&gt; 77]);
  </code></pre>
  <p>which returns:</p>
  <pre><code>{
  
      &quot;is_error&quot;: 0,
      &quot;version&quot;: 3,
      &quot;count&quot;: 1,
      &quot;id&quot;: 77,
      &quot;values&quot;: [
          {
              &quot;id&quot;: &quot;77&quot;,
  ...
              &quot;table_name&quot;: &quot;civicrm_value_myform_77&quot;,
  ...
          }
      ]
  }
  </code></pre>
  <p>In that SQL table, I can see multiple records which belong to Contact (<code>entity_id=2</code>).</p>
  <p>How I can list those records using API3? In the format that I can count how many records there are.</p>
  <p>I can't list based on Contact, because these records belong to the same one.</p>
  <p>Basically I'm looking for something like:</p>
  <pre><code>SELECT COUNT(id) FROM civicrm_value_myform_77 WHERE entity_id = 2
  </code></pre>
  
Tags: <drupal><custom-fields><api><multi-record>
Title: How to list records from the given custom group via API?
ThreadText: # How to list records from the given custom group via API?
  
  (Asked by: username_0 on 2023-04-19)
  
  I've custom data stored in custom fields. I've submitted few records as part of the same Contact.
  I can use the following API to fetch information about custom group by:
  $result = civicrm_api3('CustomGroup', 'get', ['id' => 77]);
  
  which returns:
  {
  
      "is_error": 0,
      "version": 3,
      "count": 1,
      "id": 77,
      "values": [
          {
              "id": "77",
  ...
              "table_name": "civicrm_value_myform_77",
  ...
          }
      ]
  }
  
  In that SQL table, I can see multiple records which belong to Contact (entity_id=2).
  How I can list those records using API3? In the format that I can count how many records there are.
  I can't list based on Contact, because these records belong to the same one.
  Basically I'm looking for something like:
  SELECT COUNT(id) FROM civicrm_value_myform_77 WHERE entity_id = 2
  
  **Tags:** drupal, custom-fields, api, multi-record
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2023-04-20. Score: 1 | Accepted answer
  
  First of all I would recommend using API4 for this. If you want to get the custom data with API3 you should be able to do this by returning the "custom_" + id of the custom field like so:
  $result = civicrm_api3('Contact', 'get', [
    'sequential' => 1,
    'return' => ["custom_4"],
  ]);
  
  And perhaps you can achieve what you want with something like:
  $result = civicrm_api3('Contact', 'getcount', [
    'custom_4' => ['IS NOT NULL' => 1],
  ]);
  
  > **Comments:**
  > **username_0**: Thanks, could you also share the approach for API4, is it more flexible?  
  > **username_1**: Yes, but you can try with the API4 explorer in your install? And check this documentation: https://docs.civicrm.org/dev/en/latest/api/v4/usage/  
  
  ---
  
  