We've created so called 'smart' groups in civicrm, and we need to know if a certrain user belongs to this group.

I can get the groups of a user with the following code:


But the "Smart group of the UID is not listed here,. When I do the following:


I get the result, that the user belongs to this group.

What I want is only to give the contact_id as parameter to check in which smart groups this user is

1 Answer 1


Smart Groups are basically a saved search. Checking whether a given contact is in a saved search result means running the search for that combination, which is not efficient - hence the reason the information you want isn't available through existing APIs.

See eg CRM-11903: GroupContact API doesn't get smart group members.

If you want to be able to query the API for this information, you have some options -

  • As you're doing, use the Contact API and filter by group ID to check each Contact/Smart group pair. Not efficient, but you've already found it works.
  • Create a "regular" group and automate the process of updating its members based on the criteria of your smart group. A bit rough - but probably not too hard.
  • Implement the functionality you need in a new API method. Probably not as hard as it sounds, check existing API methods for examples.
  • While it can't be relied on, it might help you to know there's also a DB table which caches the mapping of contacts to groups incl smart groups: civicrm_group_contact_cache - just remember it's a cache table so not to be trusted! Commented Mar 26, 2016 at 10:37

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.