Answers.Body: <p>If you mean the api call "civicrm_api3_group_contact_get($params)" where you are passing contact_id, I think it will return all groups, whether 'Smart' or not - did you try it?  That call just passes contact_id and if status is 'added' it should return the group</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-01T14:16:35.480Z
Answers.Text: Thanks for your answer but no, it doesn't. civicrm_api3_group_contact_get is linked to the civicrm table civicrm_group_contact which is only for member statically added to group.
Answers.UserDisplayName: samuelsov
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-31T23:06:36.437Z
Answers.LastActivityDate: 2015-08-31T23:06:36.437Z
Answers.UserDisplayName: Lesley Evensen
Answers.Body: <p>I am almost sure that the API GroupContact also returns Smart Group membership, my recommendation would be to test.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-01T04:06:23.400Z
Answers.LastActivityDate: 2015-09-01T04:06:23.400Z
Answers.UserDisplayName: ErikH - CiviCooP
Answers.Body: <p>To get the Groups, you can use the <code>GroupContact</code> API</p>
  
  <pre><code>$result = civicrm_api3('GroupContact', 'get', array(
    'sequential' =&gt; 1,
    'contact_id' =&gt; &lt;contact_id&gt;,
  ));
  </code></pre>
  
  <p>To get all the smart groups to which the contact belongs, you can use this BAO function defined in GroupContactCache.php</p>
  
  <pre><code>$smartGroup = CRM_Contact_BAO_GroupContactCache::contactGroup($contactId);
  </code></pre>
  
  <p>returned <code>$smartGroup</code> will be the list of smart_groups for the <code>contactId</code> passed</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-01T07:45:21.740Z
Answers.Text: Thanks @Jitendra. Does that mean that you have tested that the GroupContact API does not return Smart Groups?
Answers.UserDisplayName: ErikH - CiviCooP
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-01T08:36:42.510Z
Answers.Text: yes, `civicrm_group_contact` does not have an entry for smart groups with status `Added` as it does other normal groups.
Answers.UserDisplayName: jitendra - fuzion
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-01T14:19:18.220Z
Answers.Text: Thanks Jitendra Purohit. It's a shame there is no function to get all at once.
Answers.UserDisplayName: samuelsov
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-01T05:37:35.120Z
Answers.LastActivityDate: 2015-09-01T12:31:52.453Z
Answers.LastEditDate: 2015-09-01T12:31:52.453Z
Answers.UserDisplayName: jitendra - fuzion
Body: <p>Starting from a contact ID, i need to find all the groups to which the contact belongs.</p>
  
  <p>I know that i can use api <code>GroupContact</code> but it doesn't work for smart groups (in CiviCRM 4.5)</p>
  
  <p>Is there any api calls that will retrieve all groups at once ?
  Otherwise, what would be the best way ?</p>
  
Tags: <api>
Title: How to get all the groups for a contact
ThreadText: # How to get all the groups for a contact
  
  (Asked by: username_0 on 2015-08-31)
  
  Starting from a contact ID, i need to find all the groups to which the contact belongs.
  
  I know that i can use api `GroupContact` but it doesn't work for smart groups (in CiviCRM 4.5)
  
  Is there any api calls that will retrieve all groups at once ?
  Otherwise, what would be the best way ?
  
  **Tags:** api
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_3 on 2015-09-01. Score: 6 | Accepted answer
  
  To get the Groups, you can use the `GroupContact` API
  
  ```
  $result = civicrm_api3('GroupContact', 'get', array(
    'sequential' => 1,
    'contact_id' => <contact_id>,
  ));
  
  ```
  
  To get all the smart groups to which the contact belongs, you can use this BAO function defined in GroupContactCache.php
  
  ```
  $smartGroup = CRM_Contact_BAO_GroupContactCache::contactGroup($contactId);
  
  ```
  
  returned `$smartGroup` will be the list of smart\_groups for the `contactId` passed
  
  > **Comments:**
  > **username_2**: Thanks @username_3. Does that mean that you have tested that the GroupContact API does not return Smart Groups?  
  > **username_3**: yes, `civicrm_group_contact` does not have an entry for smart groups with status `Added` as it does other normal groups.  
  > **username_0**: Thanks username_3 Purohit. It's a shame there is no function to get all at once.  
  
  ---
  
  ### Answer by username_1 on 2015-08-31. Score: 0
  
  If you mean the api call "civicrm\_api3\_group\_contact\_get($params)" where you are passing contact\_id, I think it will return all groups, whether 'Smart' or not - did you try it? That call just passes contact\_id and if status is 'added' it should return the group
  
  > **Comments:**
  > **username_0**: Thanks for your answer but no, it doesn't. civicrm_api3_group_contact_get is linked to the civicrm table civicrm_group_contact which is only for member statically added to group.  
  
  ---
  
  ### Answer by username_2 on 2015-09-01. Score: 0
  
  I am almost sure that the API GroupContact also returns Smart Group membership, my recommendation would be to test.
  
  
  ---
  
  