Answers.Body: <p>Ouch - you're doing it the hard way!</p>
  
  <p>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 <strong>Help</strong> menu (renamed to <strong>Support</strong> menu in 4.6.5+), go to <strong>Developer > API Explorer</strong>.  If you're on an earlier version, in Drupal it's <code>example.org/civicrm/api/explorer</code> - I can't speak to other CMSes.</p>
  
  <p>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!</p>
  
  <p>Rest    </p>
  
  <pre><code>/sites/all/modules/civicrm/extern/rest.php?entity=Participant&amp;action=get&amp;api_key=yourkey&amp;key=sitekey&amp;json={"sequential":1,"contact_id":247}
  </code></pre>
  
  <p>Smarty  </p>
  
  <pre><code>{crmAPI var='result' entity='Participant' action='get' contact_id=247}
  {foreach from=$result.values item=participant}
    {$participant.some_field}
  {/foreach}
  </code></pre>
  
  <p>Php </p>
  
  <pre><code>$result = civicrm_api3('Participant', 'get', array(
    'sequential' =&gt; 1,
    'contact_id' =&gt; 247,
  ));
  </code></pre>
  
  <p>Javascript  </p>
  
  <pre><code>CRM.api3('Participant', 'get', {
    "sequential": 1,
    "contact_id": 247
  }).done(function(result) {
    // do something
  });
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-21T08:00:01.037Z
Answers.Text: 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..
Answers.UserDisplayName: cytofu
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-21T12:22:52.907Z
Answers.Text: Use `option.limit=0` to get more than 25 records. Also refer http://civicrm.stackexchange.com/questions/2932/how-do-i-get-more-than-25-records-from-the-api/4339#4339
Answers.UserDisplayName: jitendra - fuzion
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-21T13:00:42.213Z
Answers.Text: Here's a link to the API documentation: http://wiki.civicrm.org/confluence/display/CRMDOC/API+Reference
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-21T04:02:20.487Z
Answers.LastActivityDate: 2015-09-21T04:02:20.487Z
Answers.UserDisplayName: Jon G - Megaphone Tech
Body: <p>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 <code>_civicrm_buildForm</code> 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 <code>_form_values</code> which is protected and <code>$form-&gt;getFormValues()</code> always returns NULL. </p>
  
  <p>Also <code>CRM_Core_Resources::singleton()-&gt;addScript($script, 5, 'page-footer')</code> doesn't seem to have any effect, probably its too late to call it. So I'm simply echoing the script.  </p>
  
  <p>==> 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:</p>
  
  <pre><code>SELECT `id` FROM `civicrm_participant` WHERE `contact_id`= x
  </code></pre>
  
  <p>So any help to prettify the first approach or an example for the others would be much appreciated .</p>
  
Tags: <contacts>
Title: list of all participations for a contact
ThreadText: # list of all participations for a contact
  
  (Asked by: username_0 on 2015-09-20)
  
  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 .
  
  **Tags:** contacts
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-09-21. Score: 2
  
  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!
  Rest    
  /sites/all/modules/civicrm/extern/rest.php?entity=Participant&action=get&api_key=yourkey&key=sitekey&json={"sequential":1,"contact_id":247}
  
  Smarty  
  {crmAPI var='result' entity='Participant' action='get' contact_id=247}
  {foreach from=$result.values item=participant}
    {$participant.some_field}
  {/foreach}
  
  Php 
  $result = civicrm_api3('Participant', 'get', array(
    'sequential' => 1,
    'contact_id' => 247,
  ));
  
  Javascript  
  CRM.api3('Participant', 'get', {
    "sequential": 1,
    "contact_id": 247
  }).done(function(result) {
    // do something
  });
  
  > **Comments:**
  > **username_0**: 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..  
  > **username_2**: Use `option.limit=0` to get more than 25 records. Also refer http://civicrm.stackexchange.com/questions/2932/how-do-i-get-more-than-25-records-from-the-api/4339#4339  
  > **username_1**: Here's a link to the API documentation: http://wiki.civicrm.org/confluence/display/CRMDOC/API+Reference  
  
  ---
  
  