I am trying to get a list of all Ids of participations for a certain contact_id (to use it in JS). Currently I am using the _civicrm_buildForm hook to do that, but to extract the contact_id from the passed in $form object I need to use reflection, since is is stored under _form_values which is protected and $form->getFormValues() always returns NULL.

Also CRM_Core_Resources::singleton()->addScript($script, 5, 'page-footer') doesn't seem to have any effect, probably its too late to call it. So I'm simply echoing the script.

==> all less then ideal I assume it is possible to get the participant ids with smarty or an ajax call, but haven't found any example how to express a "Where-Clause" with those. This is the SQL-Query I'm trying to perform:

SELECT `id` FROM `civicrm_participant` WHERE `contact_id`= x

So any help to prettify the first approach or an example for the others would be much appreciated .

1 Answer 1


Ouch - you're doing it the hard way!

Getting a list of participant records by contact ID is pretty simple using the API. It sounds like maybe you haven't discovered the API Explorer. Without knowing your Civi version (and CMS software/version) I can't tell you exactly where to find it. If you're on Civi 4.5 or 4.6, then in the Help menu (renamed to Support menu in 4.6.5+), go to Developer > API Explorer. If you're on an earlier version, in Drupal it's example.org/civicrm/api/explorer - I can't speak to other CMSes.

Below I've copy/pasted my API Explorer results for finding all the participant records for contact ID 247. Note that some of the syntax for Javascript may not work in Civi earlier than 4.6, so run API Explorer yourself to double-check!




{crmAPI var='result' entity='Participant' action='get' contact_id=247}
{foreach from=$result.values item=participant}


$result = civicrm_api3('Participant', 'get', array(
  'sequential' => 1,
  'contact_id' => 247,


CRM.api3('Participant', 'get', {
  "sequential": 1,
  "contact_id": 247
}).done(function(result) {
  // do something
  • Thanks! I knew about the api explorer, but not how to use it (still not quite sure actually). For some reason I get an error when using the js api: "API permission check failed for Participant\/get call; missing permission: view event participants." And the output of the result of the smarty api is limited to 25. I'm sure there is some kind of limit param, but neither limit = 99999 nor option.limit=99999 does a thing..
    – cytofu
    Sep 21, 2015 at 8:00
  • Use option.limit=0 to get more than 25 records. Also refer civicrm.stackexchange.com/questions/2932/… Sep 21, 2015 at 12:22
  • Here's a link to the API documentation: wiki.civicrm.org/confluence/display/CRMDOC/API+Reference Sep 21, 2015 at 13:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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