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) »
  • Can I use custom data in chained API calls?
Pages: [1]

Author Topic: Can I use custom data in chained API calls?  (Read 337 times)

DaveFF

  • I post occasionally
  • **
  • Posts: 54
  • Karma: 5
  • Developer at Future First
    • Future First
  • CiviCRM version: 4.4.13
  • CMS version: Drupal 7.34
  • MySQL version: 5.5
  • PHP version: 5.3
Can I use custom data in chained API calls?
October 27, 2014, 02:49:18 am
I'm trying to do the following, to get events of certain types, and (if any) a Host participant that matches a contact in a contact reference custom field on the event:
Code: [Select]
// Get all event mobilisations, and the host participant that matches the school if any
$eventGetResult = civicrm_api('Event', 'get', array(
  'version'       => 3,
  'sequential'    => 1,
  'event_type_id' => array('IN' => $mobEventTypeIds),
  'api.Participant.get' => array(
    // 'event_id' => '$value.id' is implicit
    'participant_role_id' => PARTICIPANT_ROLE_ID_HOST,
    'contact_id'          => '$value.custom_104_id',
  ),
));
if (civicrm_error($eventGetResult)) {
  print_r($eventGetResult);
  die('Error getting events');
}

But I'm getting "Error in call to Participant_get : participant_contact_id is not a valid integer". I have checked that output makes sense (and the Event output includes the custom_104_id) if I don't include the contact_id line. So, in general can custom fields returned by an outer call be matched on by an inner call in a chained API?
Do Not Contact Until extension: https://civicrm.org/extensions/do-not-contact-until
Organisation Name De-duplicator extension: https://civicrm.org/extensions/organisation-name-de-duplicator

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: Can I use custom data in chained API calls?
October 30, 2014, 09:09:09 pm
My recollection of chaining is a bit rusty, but I think that chaining relies heavily on support from the underlying API calls. In this snippet, it seems like the outer call to "Event.get" would need to return a field called "custom_104_id" for use by the chained call.

The notation "custom_123" is supported by the "Contact" API, but I don't think it's supported by Event API (or most other APIs). For other entities, one has to call CustomValue API. It might be possible to do a 3-step chain (Event.get => CustomValue.get => Contact.get), but I don't know anyone's tried that before.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Can I use custom data in chained API calls?

This forum was archived on 2017-11-26.