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

1 Answer 1


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],

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.