Answers.Body: <p>This is not a right way of adding participant with contribution associated with it. When there is payment associated with Participants than we need to specify line items in create Participant and/or Contribution api. I would suggest to use <a href="https://github.com/civicrm/civicrm-core/blob/master/api/v3/examples/Order/CreateOrderParticipant.php" rel="nofollow noreferrer">Order api</a> to achieve your needs as it is straight forward and handles in convenient way for adding payments in CiviCRM. </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-26T12:47:00.643Z
Answers.LastActivityDate: 2017-12-26T12:47:00.643Z
Answers.UserDisplayName: Pradeep Nayak
Body: <p>I register participants and payments via the API. 
  Step 1: create a contribution for the buyer
  Step 2: create participants
  Step 3 create participant_payments linking the above.</p>
  
  <p>The weird thing is that civi adds a line to the fee_level of the first participant stating "Contribution Amount: 1".
  <a href="https://i.sstatic.net/5pamU.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/5pamU.png" alt="screenshot"></a></p>
  
  <p>Why? Am I doing something wrong?</p>
  
  <p>Following the suggestion of Jon G I have been able to pin this down to something related to price sets. Participants of events that do not use price sets do not get this "contribution amount: 1"-line.</p>
  
  <p>Kind regards,</p>
  
  <p>Janec</p>
  
  <p>The api calls:</p>
  
  <p>1) create participant:</p>
  
  <pre><code>public function createParticipant($civiEventId, $contactId, $customFields = [], $amount, $currency, $fee_level) {
  $entity = 'Participant';
  // Create filter.
  $params = [
    'event_id' =&gt; $civiEventId,
    'contact_id' =&gt; $contactId,
    'status_id' =&gt; "Registered",
    'participant_role_id' =&gt; "deelnemer",
    'participant_fee_level' =&gt; $fee_level,
    'participant_fee_amount' =&gt; $amount,
    'participant_fee_currency' =&gt; $currency
  ];
  if (count($customFields) &gt; 0 &amp;&amp; is_array($customFields)) {
    foreach ($customFields as $customFieldKey =&gt; $customFieldValue) {
      if(is_integer($customFieldKey)){
        $customId = "custom_".$customFieldKey;
      } else {
        $customId = $customFieldKey;
      }
      $params[$customId] = $customFieldValue;
    }
  }
  $action = "create";
  
  return $this-&gt;query($entity, $params, $action);
  </code></pre>
  
  <p>}</p>
  
  <p>2) create contribution</p>
  
  <pre><code>public function createContribution($financial_type, $total_amount, $civi_id, $mollie_id, $date) {
  $entity = 'Contribution';
  $action = 'create';
  // Create filter.
  $params = [
    'financial_type_id' =&gt; $financial_type,
    'total_amount' =&gt; $total_amount,
    'contact_id' =&gt; $civi_id,
    'custom_100' =&gt; $mollie_id,
    'receive_date' =&gt; $date,
    'currency' =&gt; "EUR",
    'source' =&gt; "Chiro.be via mollie",
  ];
  return $this-&gt;query($entity, $params, $action);
  </code></pre>
  
  <p>}</p>
  
  <p>3) create participantPayment</p>
  
  <pre><code>public function createParticipantPayment($participant_id, $contribution_id) {
  $entity = 'ParticipantPayment';
  $action = 'create';
  // Create filter.
  $params = [
    'participant_id' =&gt; $participant_id,
    'contribution_id' =&gt; $contribution_id,
  ];
  return $this-&gt;query($entity, $params, $action);
  </code></pre>
  
  <p>}</p>
  
  <p>using version 4.7.27.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-12-14T15:36:24.637Z
Comments.Text: More specifics: I pay for two particpants. I am not a particpant myself.
Comments.UserDisplayName: Janec Poppeliers
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-12-14T15:47:21.080Z
Comments.Text: I tested with myself as payer and participant but still the extra line gets added to the first participant (alphabetically?). i would have expected that the line got added to the paying-participant.
Comments.UserDisplayName: Janec Poppeliers
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-12-14T16:31:55.553Z
Comments.Text: I tried but could not replicate this.  Could you please a) indicate what version of CiviCRM you're using? b) show your API calls?  You may want to consider using the API Explorer (**Support » Developer » API Explorer**) on the sandbox (dmaster.demo.civicrm.org) to see if the problem exists in CiviCRM itself.
Comments.UserDisplayName: Jon G - Megaphone Tech
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-12-15T13:23:59.073Z
Comments.Text: Thanks for the suggestion. I have added it to the question.
Comments.UserDisplayName: Janec Poppeliers
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-12-18T11:46:21.337Z
Comments.Text: This is more a suggestion as I don't have quite an answer but I believe this behavior is due the way the Contribution is created via the API or rather how it creates the first Line item, which from what I understand takes the Price Field from the `default_contribution_amount` Price Set. There might be a param that I don't know of that you can pass to specify the Line Item? Meanwhile I suggest you have a look at the Order API, specifically [this example](https://github.com/civicrm/civicrm-core/blob/4ac958d18f497183119bf49c6bb8604bfcce4018/api/v3/examples/Order/CreateOrderParticipant.php#L10).
Comments.UserDisplayName: Andrei
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-12-18T11:47:55.203Z
Comments.Text: You can create the Contribution, specify the Line items and register the Participants, all in one go, pretty cool!
Comments.UserDisplayName: Andrei
Tags: <api><contributions><payment><participants>
Title: via api created only first particpant gets a line: "Contribution Amount: 1"
ThreadText: # via api created only first particpant gets a line: "Contribution Amount: 1"
  
  (Asked by: username_0 on 2017-12-14)
  
  I register participants and payments via the API.
  Step 1: create a contribution for the buyer
  Step 2: create participants
  Step 3 create participant\_payments linking the above.
  
  The weird thing is that civi adds a line to the fee\_level of the first participant stating "Contribution Amount: 1".
  [![screenshot](https://i.sstatic.net/5pamU.png)](https://i.sstatic.net/5pamU.png)
  
  Why? Am I doing something wrong?
  
  Following the suggestion of Jon G I have been able to pin this down to something related to price sets. Participants of events that do not use price sets do not get this "contribution amount: 1"-line.
  
  Kind regards,
  
  username_0
  
  The api calls:
  
  1) create participant:
  
  ```
  public function createParticipant($civiEventId, $contactId, $customFields = [], $amount, $currency, $fee_level) {
  $entity = 'Participant';
  // Create filter.
  $params = [
    'event_id' => $civiEventId,
    'contact_id' => $contactId,
    'status_id' => "Registered",
    'participant_role_id' => "deelnemer",
    'participant_fee_level' => $fee_level,
    'participant_fee_amount' => $amount,
    'participant_fee_currency' => $currency
  ];
  if (count($customFields) > 0 && is_array($customFields)) {
    foreach ($customFields as $customFieldKey => $customFieldValue) {
      if(is_integer($customFieldKey)){
        $customId = "custom_".$customFieldKey;
      } else {
        $customId = $customFieldKey;
      }
      $params[$customId] = $customFieldValue;
    }
  }
  $action = "create";
  
  return $this->query($entity, $params, $action);
  
  ```
  
  }
  
  2) create contribution
  
  ```
  public function createContribution($financial_type, $total_amount, $civi_id, $mollie_id, $date) {
  $entity = 'Contribution';
  $action = 'create';
  // Create filter.
  $params = [
    'financial_type_id' => $financial_type,
    'total_amount' => $total_amount,
    'contact_id' => $civi_id,
    'custom_100' => $mollie_id,
    'receive_date' => $date,
    'currency' => "EUR",
    'source' => "Chiro.be via mollie",
  ];
  return $this->query($entity, $params, $action);
  
  ```
  
  }
  
  3) create participantPayment
  
  ```
  public function createParticipantPayment($participant_id, $contribution_id) {
  $entity = 'ParticipantPayment';
  $action = 'create';
  // Create filter.
  $params = [
    'participant_id' => $participant_id,
    'contribution_id' => $contribution_id,
  ];
  return $this->query($entity, $params, $action);
  
  ```
  
  }
  
  using version 4.7.27.
  
  **Tags:** api, contributions, payment, participants
  
  > **Comments:**
  > **username_0**: More specifics: I pay for two particpants. I am not a particpant myself.  
  > **username_0**: I tested with myself as payer and participant but still the extra line gets added to the first participant (alphabetically?). i would have expected that the line got added to the paying-participant.  
  > **username_1**: I tried but could not replicate this.  Could you please a) indicate what version of CiviCRM you're using? b) show your API calls?  You may want to consider using the API Explorer (**Support » Developer » API Explorer**) on the sandbox (dmaster.demo.civicrm.org) to see if the problem exists in CiviCRM itself.  
  > **username_0**: Thanks for the suggestion. I have added it to the question.  
  > **username_2**: This is more a suggestion as I don't have quite an answer but I believe this behavior is due the way the Contribution is created via the API or rather how it creates the first Line item, which from what I understand takes the Price Field from the `default_contribution_amount` Price Set. There might be a param that I don't know of that you can pass to specify the Line Item? Meanwhile I suggest you have a look at the Order API, specifically [this example](https://github.com/civicrm/civicrm-core/blob/4ac958d18f497183119bf49c6bb8604bfcce4018/api/v3/examples/Order/CreateOrderParticipant.php#L10).  
  > **username_2**: You can create the Contribution, specify the Line items and register the Participants, all in one go, pretty cool!  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_3 on 2017-12-26. Score: 0
  
  This is not a right way of adding participant with contribution associated with it. When there is payment associated with Participants than we need to specify line items in create Participant and/or Contribution api. I would suggest to use [Order api](https://github.com/civicrm/civicrm-core/blob/master/api/v3/examples/Order/CreateOrderParticipant.php) to achieve your needs as it is straight forward and handles in convenient way for adding payments in CiviCRM.
  
  
  ---
  
  