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) »
  • API - adding a contact to a group
Pages: [1]

Author Topic: API - adding a contact to a group  (Read 371 times)

holmesg

  • I post occasionally
  • **
  • Posts: 61
  • Karma: 0
  • CiviCRM version: CiviCRM 4.3.4
  • CMS version: Joomla! 2.5.8
  • MySQL version: 5.1.70
  • PHP version: PHP Version 5.3.22
API - adding a contact to a group
June 26, 2014, 06:18:53 am
I found the "legacy" way to do this:

    $params = array(
                    'contact_id.1' => $contact_id,
                    'group_id'     => 72
                    );
    $result = civicrm_group_contact_add( $params );


But that function is not found. PHP Fatal error:  Call to undefined function civicrm_group_contact_add() in *********/sites/all/modules/rules/modules/php.eval.inc(146)

What's the current way to do it?  I can't find the actual functions listed in the current API reference ...
« Last Edit: June 26, 2014, 06:29:14 am by holmesg »

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: API - adding a contact to a group
June 26, 2014, 07:11:08 am
Hi,

The easiest is probably the api explorer running on your civi, it lists all the entities and generates the code.

Code: [Select]
$params = array(
  'sequential' => 1,
  'contact_id' => 42,
  'group_id' => 3,
  ''
);
$result = civicrm_api3('GroupContact', 'create', $params);

-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

holmesg

  • I post occasionally
  • **
  • Posts: 61
  • Karma: 0
  • CiviCRM version: CiviCRM 4.3.4
  • CMS version: Joomla! 2.5.8
  • MySQL version: 5.1.70
  • PHP version: PHP Version 5.3.22
Re: API - adding a contact to a group
June 26, 2014, 07:23:40 am
That did the trick ... thanks!  ;D

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • API - adding a contact to a group

This forum was archived on 2017-11-26.