7

I'm trying to write an API call returning all contacts that are at one end of one or more active relationships of a certain type, and their names. I note that you can specify limit, offset (LIMIT) and sort (ORDER BY) options. Something similar for GROUP BY, so I don't need to do this in PHP separately after the API call, would be useful. Does it exist?

Like this, for example:

$ao_result = civicrm_api('Relationship', 'get', array(
  'version'    => 3,
  'sequential' => 1,
  'relationship_type_id' => 19,
  'is_active'  => TRUE,
  'options'    => array(
    'group_by' => 'contact_id_b',
  ),
  'api.Contact.getvalue' => array(
    'id'     => '$value.contact_id_b',
    'return' => 'display_name',
  ),
));
  • Or even 'group_by' => array('contact_id_b'), because you can have more than one. – DaveFF Jul 23 '15 at 12:16
  • Could this be implemented solely in api/v3/utils.php or would it need to be all the CRM_*_BAO_Query and other places as well? – DaveFF Jul 24 '15 at 8:22
2

I think this makes sense as an addition - but note that there are 3 types of get api

1) api layer api - e.g anything that uses basic_get 2) query object api (contact, contribute etc) 3) random assorted api

1 is easy & in one place - 2 & 3 are ... not

BUT #1 changes substantially in 4.7 compared to 4.6 so you would need to fix at minimum in 4.7 & add unit tests and ALSO in 4.6 if you want it to work there too.

(We are open to backporting the 4.7 internals en masse to 4.6 with an self-deprecating opt-in -eg. $params['options']['4.7plusmode'] = TRUE; - the 4.7 code also supports custom field filters (e.g on address) and lays the groundwork for more nuanced acls since it permits joins in simple api which is a blocker in 4.6)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.