5

We have a custom module that we use to do event registrations (non - paid), however i was wondering is there anyway through the API of being able to trigger CiviCRM sending a confirmation registration email when we submit the registration via API?

4

There is a send email API in an extension that should be able to handle that? Not the automatic sending but you can trigger the API in whatever processing you do. Extension can be found here: https://github.com/CiviCooP/org.civicoop.emailapi

  • This extension is available in the CiviCRM Extensions Directory online, and it looks like it's new in 2015 and actively supported. (Thanks Jaap Jansma and CiviCooP!) Is this correct that it's only confirmed compatible through Civi 4.5, and so it would not appear in a Civi 4.6.7 list of "native" extensions on the civicrm/admin/extensions page? – Daniel Ando Scholnick Aug 21 '15 at 14:15
  • Yes, that is correct (and it is also updated by Ixiam if we are thanking :-) – ErikH - CiviCooP Aug 24 '15 at 6:53
3

I haven't tried the org.civicoop.emailapi extension, but I did give it a quick skim, and it didn't look like it would be suitable for the use case of an event registration confirmation email. I didn't see where it would accept params for the event ID or the participant ID, so while it might be able to send the appropriate template, much of the data wouldn't be populated.

Instead I ended up using a core BAO. This is not recommended, because presumably the method is not intended to be a public interface and could change from one version to the next.

Nevertheless, it was expedient. Here's some sample code for anyone else who may need to do this:

<?php

// your contact ID may come from elsewhere
$cid = $form->getVar('_primary_volunteer_id');

foreach ($form->_submitValues['field_added_by_buildform_hook'] as $eventId) {
  $participant = civicrm_api3('Participant', 'create', array(
    'contact_id' => $cid,
    'event_id' => $eventId,
    'role_id' => 'Attendee',
    'source' => 'My Customized Form',
  ));

  // elsewhere I have called civicrm_api3('Event', 'get', $params)
  // to populate $eventData
  $locBlock = civicrm_api3('LocBlock', 'getsingle', array(
    'id' => $eventData[$eventId]['loc_block_id'],
    'return' => 'all',
  ));
  // for some reason, the BAO expects 1-indexing rather than 0-indexing
  $locBlock['address'] = array(1 => $locBlock['address']);

  // Note: other stuff data can go into $mailParams, such
  // as fee information. It's not well-documented, and it
  // wasn't relevant to my use case, so I didn't bother.
  $mailParams = array(
    'event' => $eventData[$eventId],
    'location' => $locBlock,
  );
  CRM_Event_BAO_Event::sendMail($cid, $mailParams, $participant['id']);
}
  • this is really handy - thanks - I was thinking that you could potentially add an option to the participant.create API send_confirmation to take care of sending the confirmation email. – michaelmcandrew Feb 19 at 12:13

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.