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) »
  • Best api method to get all groups (names and id's) and add contact to a group
Pages: [1]

Author Topic: Best api method to get all groups (names and id's) and add contact to a group  (Read 1071 times)

nant

  • I post frequently
  • ***
  • Posts: 143
  • Karma: 4
    • Joomlapolis
  • CiviCRM version: 4.3.4
  • CMS version: Joomla 2.5.11
  • MySQL version: 5
  • PHP version: 5.3
Best api method to get all groups (names and id's) and add contact to a group
October 14, 2013, 02:02:12 am
I am extending my Joomla plugin:

https://civicrm.org/extensions/joomla-2-civicrm-user-synchronization

and I need to grab all groups available from civi install to present them for selection and then I need a method to add a specific contact to one or more of these groups.

Any suggestions are welcome.
--
Nick (aka nant from CB Team)

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Best api method to get all groups (names and id's) and add contact to a group
October 14, 2013, 02:16:21 am
To get the groups would be api.group.get
To add a contact to a group is api.groupcontact.create (contact_id, group_id)

I'm not sure about the url on joomla, but civicrm/api/explorer and civicrm/api/doc should help you finding entities you want and find their fields

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

nant

  • I post frequently
  • ***
  • Posts: 143
  • Karma: 4
    • Joomlapolis
  • CiviCRM version: 4.3.4
  • CMS version: Joomla 2.5.11
  • MySQL version: 5
  • PHP version: 5.3
Re: Best api method to get all groups (names and id's) and add contact to a group
October 14, 2013, 02:36:26 am
Quote from: xavier on October 14, 2013, 02:16:21 am
To get the groups would be api.group.get
To add a contact to a group is api.groupcontact.create (contact_id, group_id)

I'm not sure about the url on joomla, but civicrm/api/explorer and civicrm/api/doc should help you finding entities you want and find their fields

Good luck

Thanks - got the group list working.

Question: can I add a single contact to multiple groups in one api call or do I need to loop?
--
Nick (aka nant from CB Team)

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Best api method to get all groups (names and id's) and add contact to a group

This forum was archived on 2017-11-26.