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) »
  • [solved] Chained api get call ignores arguments
Pages: [1]

Author Topic: [solved] Chained api get call ignores arguments  (Read 415 times)

andersiversen

  • I post occasionally
  • **
  • Posts: 76
  • Karma: 1
  • CiviCRM version: 4.4.4
  • CMS version: Drupal 7.26
  • MySQL version: 5.5.32
  • PHP version: 5.3.10
[solved] Chained api get call ignores arguments
February 25, 2015, 05:10:03 am
Hello

I'm using the following chained api call:

Code: [Select]
civicrm_api("Contact","get", array ('version' => 3,'sequential' => '1', 'contact_sub_type' => 'Student', 'api.groupContact.get' => array('group_id' => 4, 'status' => 'Added')));
I would think that it should return only students in group 4, but it ignores the 'group_id' argument and returns a result like:
Code: [Select]
...
            [4] => Array
                (
                    [contact_id] => 25660
                    [contact_type] => Individual
                    [contact_sub_type] => Array
                        (
                            [0] => Student
                        )

                    [sort_name] => Lastname, Mathilde
                    [display_name] => Mathilde Lastname
                    [do_not_email] => 0
...
                    [id] => 25660
                    [api.groupContact.get] => Array
                        (
                            [is_error] => 0
                            [version] => 3
                            [count] => 2
                            [values] => Array
                                (
                                    [0] => Array
                                        (
                                            [id] => 91514
                                            [group_id] => 2
                                            [title] => Some group title
                                            [visibility] => User and User Admin Only
                                            [is_hidden] => 0
                                            [in_date] => 2014-11-06 10:06:46
                                            [in_method] => API
                                        )

                                    [1] => Array
                                        (
                                            [id] => 88432
                                            [group_id] => 10
                                            [title] => Some other group title
                                            [visibility] => Public Pages
                                            [is_hidden] => 0
                                            [in_date] => 2014-11-04 09:54:01
                                            [in_method] => API
                                        )

                                )

                        )

                )

Is this as it should be? (this is on a civicrm 4.4 installation)

If I switch the contact get call and group get call, so I do it the other way around (the contact get is nested inside the group get), it would probably do what I want. But that's only in my unique case here, because I don't really have any contacts in group 4 who aren't students.
« Last Edit: February 25, 2015, 07:33:23 am by andersiversen »

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Chained api get call ignores arguments
February 25, 2015, 05:46:01 am
What chaining does is to first fetch results from the outer query (ignoring chaining) and then it goes back through the results and fetches the results of the chained api action for each one.
So I think it is working correctly and you are trying to make chaining do something it wasn't intended for, which is to set additional filters on the outer results.
If you really want to fetch all students in group 4, try this:

Code: [Select]
civicrm_api3("Contact","get", array ('contact_sub_type' => 'Student', 'group' => 4));
Try asking your question on the new CiviCRM help site.

andersiversen

  • I post occasionally
  • **
  • Posts: 76
  • Karma: 1
  • CiviCRM version: 4.4.4
  • CMS version: Drupal 7.26
  • MySQL version: 5.5.32
  • PHP version: 5.3.10
Re: [solved] Chained api get call ignores arguments
February 25, 2015, 07:37:47 am
That works perfectly - thanks Coleman!

For reference:
If I go to the api explorer and choose entity Contact and action getfields, I see all the fields that I can use with a contact get call (I guess). But I don't see "group" as one of them.
- where do I see a complete list of all the fields I can use in a contact get call, including the fields which aren't in the contact table in the database (eg group - and email is another example) ?

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: [solved] Chained api get call ignores arguments
February 25, 2015, 09:29:58 am
I can see those fields in the api explorer with the newest version (4.6)
Try asking your question on the new CiviCRM help site.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • [solved] Chained api get call ignores arguments

This forum was archived on 2017-11-26.