I am relatively new at civicrm and I have a question about Event imports. I've been reading the documentation here: https://docs.civicrm.org/user/en/latest/common-workflows/importing-data-into-civicrm/ about Import Participants and Import Contributions. The documentation seems to keep them separate from each other. The documentation touches upon importing multiple csv's for relational data, but doesn't go into great detail about the actual process.

The question is: Is there a standard procedure for importing event participants with their corresponding contributions / payment?

I know that there are many tables involved such as contribution, financial_trxn, financial_entity_trxn, event, participant, line_item...that are involved in this sort of import and frankly, it seems like a complicated import.

  • Has anyone built an extension to help with this import? It would seem like an excellent one to have with proper user documentation. – Dwight Martino Aug 5 at 18:09

The way to do this is to import the Contributions and Participant records separately via the CiviCRM import tools. You may need to also import any new contacts you have first. Using the import tools takes care of all the extra complicated tables.

Then to connect the Contributions to the Participants: You will need to export a csv of all the imported Contributions and a csv of all the imported Participant records. Match up those two lists based on the Contact ID. Then you will manipulate that data to be importable into the civicrm_participant_payment table. Which is just Participant id and Contribution id.

Then you will have all data where it needs to be and properly connected

| improve this answer | |
  • 1
    Thanks Tommy. I ended up writing two PHP scripts and then using the civicrm API for generating the data insert block of code. Like you said though, I did have to insert the participants and the contributions separate. I also had to do a third insert, which was for participant_payment. After that, the API code civi generated did end up giving me an insert that populated all the relevant tables to Event registrations – Kurt Leadley May 9 '19 at 14:07

I ended up using a combination of my own solution and Tommy B's. I wrote two PHP scripts. Each time, the PHP script would parse relevant data from a csv file, storing the information in an array, looping through the array and then using code that the civicrm API generated for doing participant and contribution data inserts.

define ('SITEROOT', '/home/****/public_html');
define('CIVIROOT', SITEROOT.'/administrator/components/com_civicrm/civicrm');
require_once CIVIROOT.'/civicrm.config.php';
require_once CIVIROOT.'/CRM/Core/Config.php';

$config = CRM_Core_Config::singleton();

echo 'CiviCRM has been successfully initialized.<br/><br/>';

require_once 'CRM/Utils/Request.php';
//is dryrun unless ?dryrun=0
$nA = CRM_Core_DAO::$_nullArray;
$dryrun = CRM_Utils_Request::retrieve('dryrun', 'Positive', $nA, FALSE, 1, 'REQUEST');
echo 'dryrun: '.($dryrun?'TRUE':'FALSE').'<br/><br/>';

$mysqli = new mysqli("localhost", "*******", "*****", "*******");

$csvFile = file('eventsFull.csv');
$data = [];
foreach ($csvFile as $line) {
    $data[] = str_getcsv($line);
foreach ($data as $row) {
$eventID = $row[93];
$statusID = $row[19];
//// This is from the API below /////////
  $result = civicrm_api3('Participant', 'create', [
    'event_id' => $eventID,
    'contact_id' => $userID,
    'status_id' => $statusID,
    'role_id' => $roleID,
    'register_date' => $registrationDate,
    'source' => $source,
    'fee_level' => $feeLevel,
    'fee_amount' => $price,
    'fee_currency' => $currency,
    'discount_amount' => $discount,
    'custom_35' => $dietNeeds,
    'is_pay_later' => $isPayLater,

There was some more to the code, but that was the general idea. I had two other imports, three in total. One for $result = civicrm_api3('Contribution', 'create', One for $result = civicrm_api3('Participant', 'create', [ and one for $result3 = civicrm_api3('ParticipantPayment', 'create', [

| improve this answer | |
  • I'd like to note that the newer API (version 4) queries sometimes act a little wonky, or not at all, depending on the parameters and the tables / joins. I unfortunately did not document my findings in this, as I was in a rush. I do remember it was failing both in CiviCRM's API / Developer GUI, and in my PHP code though. This was a good indicator that the API in v4 didn't work properly, because it worked in version 3 on both ends. If the API in version 4 is acting funny, normal MySQL queries work fine too. Just a tidbit – Kurt Leadley Aug 22 at 7:49

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.