Answers.Body: <p>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. </p>
  
  <pre><code>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.&lt;br/&gt;&lt;br/&gt;';
  
  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').'&lt;br/&gt;&lt;br/&gt;';
  
  $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];
  .......etc
  //// This is from the API below /////////
    $result = civicrm_api3('Participant', 'create', [
      'event_id' =&gt; $eventID,
      'contact_id' =&gt; $userID,
      'status_id' =&gt; $statusID,
      'role_id' =&gt; $roleID,
      'register_date' =&gt; $registrationDate,
      'source' =&gt; $source,
      'fee_level' =&gt; $feeLevel,
      'fee_amount' =&gt; $price,
      'fee_currency' =&gt; $currency,
      'discount_amount' =&gt; $discount,
      'custom_35' =&gt; $dietNeeds,
      'is_pay_later' =&gt; $isPayLater,
    ]);
    $i++;
  }
  </code></pre>
  
  <p>There was some more to the code, but that was the general idea. I had two other imports, three in total. One for <code>$result = civicrm_api3('Contribution', 'create',</code> One for <code>$result = civicrm_api3('Participant', 'create', [</code> and one for <code>$result3 = civicrm_api3('ParticipantPayment', 'create', [</code></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-08-22T07:49:12.067Z
Answers.Text: 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
Answers.UserDisplayName: Kurt Leadley
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-09T14:24:41.893Z
Answers.LastActivityDate: 2019-05-09T14:24:41.893Z
Answers.UserDisplayName: Kurt Leadley
Answers.Body: <p>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.</p>
  
  <p>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. </p>
  
  <p>Then you will have all data where it needs to be and properly connected</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-09T14:07:37.333Z
Answers.Text: 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
Answers.UserDisplayName: Kurt Leadley
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-08T18:55:19.970Z
Answers.LastActivityDate: 2019-05-08T18:55:19.970Z
Answers.UserDisplayName: Tommy B
Body: <p>I am relatively new at civicrm and I have a question about Event imports. I've been reading the documentation here:
  <a href="https://docs.civicrm.org/user/en/latest/common-workflows/importing-data-into-civicrm/" rel="nofollow noreferrer">https://docs.civicrm.org/user/en/latest/common-workflows/importing-data-into-civicrm/</a>
  about <code>Import Participants</code> and <code>Import Contributions</code>. 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.</p>
  
  <p>The question is: Is there a standard procedure for importing event participants with their corresponding contributions / payment? </p>
  
  <p>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.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-08-05T18:09:42.900Z
Comments.Text: Has anyone built an extension to help with this import? It would seem like an excellent one to have with proper user documentation.
Comments.UserDisplayName: Dwight Martino
Tags: <civievent><civicontribute><civimember>
Title: Importing Event Participants with Contribution/ Payment
ThreadText: # Importing Event Participants with Contribution/ Payment
  
  (Asked by: username_0 on 2019-04-30)
  
  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.
  
  **Tags:** civievent, civicontribute, civimember
  
  > **Comments:**
  > **username_1**: Has anyone built an extension to help with this import? It would seem like an excellent one to have with proper user documentation.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2019-05-08. Score: 3 | Accepted answer
  
  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
  
  > **Comments:**
  > **username_0**: 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  
  
  ---
  
  ### Answer by username_0 on 2019-05-09. Score: 2
  
  I ended up using a combination of my own solution and username_2'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.';
  
  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').'';
  
  $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];
  .......etc
  //// 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,
    ]);
    $i++;
  }
  
  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', [
  
  > **Comments:**
  > **username_0**: 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  
  
  ---
  
  