Author Topic: V2.0 and APIs  (Read 3485 times)

Offline dflasse

  • I post occasionally
  • **
  • Posts: 45
  • Karma: 0
    • Tout peut arriver
V2.0 and APIs
« on: April 04, 2008, 04:57:25 am »
Hi there,

I'm busy migrating our CiviCRM set up to V2. The upgrade itself ran smoothly but I'm stuck in migrating the code snippets we used with API.

I'm trying to retrieve all contact email from several groups (see below). I managed to get an array of groups but I can't get contacts belonging to a group.

Any help greatly appreciated.

 $params = array( 'title' => $param );

                //$return_properties = array('title' );
                $myGroups =& civicrm_groups_get($params);

                foreach($myGroups as $group)
                {
                $params = array('group_id' => $group['id']);
               
                $myContacts = civicrm_group_contact_get(&$params);

                        foreach ($myContacts as $contact)
                        {
                        $display .= $contact['email'] . ", ";
                        }
                }
                return $display;

Offline Kurund Jalmi

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 3824
  • Karma: 117
    • CiviCRM
  • CiviCRM version: 4.x, future
  • CMS version: Drupal 7, Joomla 2.x
  • MySQL version: 5.1.61
  • PHP version: 5.3.10
Re: V2.0 and APIs
« Reply #1 on: April 04, 2008, 07:05:39 am »
Found this reply helpful? Help us improve CiviCRM with the Make it Happen! initiative.

Donate NOW

Offline dflasse

  • I post occasionally
  • **
  • Posts: 45
  • Karma: 0
    • Tout peut arriver
Re: V2.0 and APIs
« Reply #2 on: April 06, 2008, 11:15:58 pm »
Where do I find the documentation about this API? I'm a very lousy php developper and the code itself is very cryptic for me. Thanks!

Offline dflasse

  • I post occasionally
  • **
  • Posts: 45
  • Karma: 0
    • Tout peut arriver
Re: V2.0 and APIs
« Reply #3 on: April 06, 2008, 11:46:09 pm »
Nevermind ... I should better get some sleep!

Offline dflasse

  • I post occasionally
  • **
  • Posts: 45
  • Karma: 0
    • Tout peut arriver
Re: V2.0 and APIs
« Reply #4 on: April 07, 2008, 12:08:52 am »
Well ... I'm stuck again ...

Here's the piece of code that used to work prior to V2.0:

public function search_group_contacts_tb($param){
               
                $params = array( 'title' => $param );

                $return_properties = array('title' );
                $myGroups =& crm_get_groups($params, $return_properties);
               
                foreach($myGroups as $group) {
                        $return_properties = array( 'email' );
                        $sort = array("email" => "ASC");
                       
                $myContacts =& crm_get_group_contacts(&$group, $return_propertie
s ,'Added',$sort, $offset = 0, $row_count = null );
                       
                        foreach ($myContacts as $contact) {
                    $display .= $contact->email . ", ";
                }
                }
                return $display;
        }

The crm_get_group_contact API seems not to be available anymore. So is the 'crm_get_group'. I managed to adapt the latter with the 'civicrm_groups_get' V2 API but I can't find an alternative to the first one.

The bottom line is how do I retrieve the email address from a group? civicrm_contact_search() isn't helpful since the ERD shows the groups a contact belongs to is only available through the civicrm_group_contact table. Therefore I don't see what parameter I could pass to civicrm_contact_search().

Offline dflasse

  • I post occasionally
  • **
  • Posts: 45
  • Karma: 0
    • Tout peut arriver
Re: V2.0 and APIs
« Reply #5 on: April 07, 2008, 11:36:48 pm »
I've seen that the API documentation has been updated. It is much clearer why my application stopped working with civiCRM 2.0. I totally missed the warnings prior to upgrade.

However, I still miss the equivalent of crm_get_group_contacts (deprecated) in the new set of APIs.

Offline grobot

  • Ask me questions
  • ****
  • Posts: 430
  • Karma: 44
  • www.giantrobot.co.nz/contact
    • Giant Robot -- CiviCRM + Drupal support
Re: V2.0 and APIs
« Reply #6 on: April 08, 2008, 02:48:28 am »
Did you find a way to make this work?
Giant Robot ● Drupal + CiviCRM support & consulting
@grobotwww.giantrobot.co.nz

Offline dflasse

  • I post occasionally
  • **
  • Posts: 45
  • Karma: 0
    • Tout peut arriver
Re: V2.0 and APIs
« Reply #7 on: April 08, 2008, 03:00:09 am »
Unfortunately no.

Offline Kurund Jalmi

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 3824
  • Karma: 117
    • CiviCRM
  • CiviCRM version: 4.x, future
  • CMS version: Drupal 7, Joomla 2.x
  • MySQL version: 5.1.61
  • PHP version: 5.3.10
Re: V2.0 and APIs
« Reply #8 on: April 09, 2008, 03:45:11 am »
Found this reply helpful? Help us improve CiviCRM with the Make it Happen! initiative.

Donate NOW