CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Finding the "group status" of a contact using API v3
Pages: [1]

Author Topic: Finding the "group status" of a contact using API v3  (Read 585 times)

torenware

  • I post frequently
  • ***
  • Posts: 153
  • Karma: 4
Finding the "group status" of a contact using API v3
August 16, 2012, 11:03:10 pm
I've started some CiviCRM work after a long hiatus, using version 4.1.  I need to figure out, given a contact_id and a group_id, if a contact is in the group with either a status of "added" or "pending".  Looking in api/v3/examples  and tests/phpunit/v3/, it _looks_ as if you'd want to call the API as follows:
Code: [Select]
$contact_id = 5;
$group_id = 2;

require_once 'api/api.php';
$params = array(
  'version' => 3,
  'contact_id' => $contact_id,
  'group_id' => $group_id,
);

$results=civicrm_api("GroupContact","get", $params);

print_r($results);

This does execute, and without error, but the results gave me two groups for contact_id = 5, neither of which was group_id = 2.

This was a surprise.  How do I need to call this API to get the information I want?


xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Finding the "group status" of a contact using API v3
August 17, 2012, 01:29:03 am
Hi,

GroupContact api has been migrated directly from v2 and needs some love

http://issues.civicrm.org/jira/browse/CRM-10331

If you could get rid of the old code and replace it (in api/v3/GroupContact.php) by using the proper _basic functions (check out Email.php as an example)
 
  return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);

it should be enough to get it working properly
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Finding the "group status" of a contact using API v3
August 20, 2012, 02:52:13 pm
The function being called allows permissions to be applied - however, it doesn't currently accept a group id - I think that part is not hard looking at it - if you want to submit a unit test I'd be happy to patch it
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

torenware

  • I post frequently
  • ***
  • Posts: 153
  • Karma: 4
Re: Finding the "group status" of a contact using API v3
August 21, 2012, 03:25:27 pm
It may be a little while -- I'm not set up for core CiviCRM development right now.  But when things quiet down, I'll set up for PHPUnit work and see what I can do.


Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Finding the "group status" of a contact using API v3

This forum was archived on 2017-11-26.