Answers.Body: <p>This should work</p>
  <pre><code>civicrm_api3('Contribution', 'create', [
      'financial_type_id' =&gt; 11,
      'receive_date' =&gt; 0201008150000,
      'total_amount' =&gt; 11.15,
      'tax_amount' =&gt; 0.53,
      'net_amount' =&gt; 10.62,
      'contact_id' =&gt; $civicrm_id,
      'contribution_status_id' =&gt; &quot;Pending&quot;, 
      'payment_instrument_id' =&gt; &quot;Überweisung&quot;, 
      'is_pay_later' =&gt; 1,
      'skipLineItem' =&gt; 1,
      'api.line_item.create' =&gt; [
          'entity_table' =&gt; 'civicrm_contribution',
          'contribution_type_id' =&gt; 11,
          'financial_type_id' =&gt; 11,
          'price_field_id' =&gt; 55,
          'label' =&gt; 'article name example 1',
          'tax_amount' =&gt; 0.53,
          'unit_price' =&gt; 10.62,
          'line_total' =&gt; 10.62,
          'non_deductible_amount' =&gt; 0.00,
          'qty' =&gt; 1.00,
        ]
    ]);
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-09T09:37:28.783Z
Answers.LastActivityDate: 2020-10-09T09:37:28.783Z
Answers.UserDisplayName: lbl
Body: <p>I want to import a list of contacts from a csv file (specifically: the Contact IDs), and create a Contribution via API for each one of them. Purpose: These contacts are all ordering the same articles, but have not yet ordered via the CiviContribute system, so we need to import the data.</p>
  <p>I wrote a PHP script for that, which is saving the new Contribution correctly on each Contact. It contains the following API call:</p>
  <pre><code>civicrm_api3('Contribution', 'create', [
          'financial_type_id' =&gt; 11,
          'receive_date' =&gt; 20201008150000,
          'total_amount' =&gt; 11.15,
          'contact_id' =&gt; $civicrm_id,
          'contribution_status_id' =&gt; &quot;Pending&quot;, 
          'payment_instrument_id' =&gt; &quot;Überweisung&quot;, 
          'is_pay_later' =&gt; 1,
          'price_set_id' =&gt; 25,
          'skipLineItem' =&gt; 1,
          'api.line_item.create' =&gt; [
            '0' =&gt; [
              'price_field_id' =&gt; 55,
              'qty' =&gt; 1,
              'label' =&gt; 'article name example 1',
              'line_total' =&gt; 8.57,
              'unit_price' =&gt; 8.57,
            ],
            '1' =&gt; [
              'price_field_id' =&gt; 56,
              'qty' =&gt; 1,
              'label' =&gt; 'article name example 1',
              'line_total' =&gt; 2.05,
              'unit_price' =&gt; 2.05,
            ]
          ]
        ]);
  </code></pre>
  <p>But it makes two mistakes:</p>
  <ul>
  <li><p>The value in the &quot;Item&quot; column in the Contribution View and the Invoice is a default value &quot;line item&quot;. I manage to solve this by adding the article name into the code (<code>'label' =&gt; 'article name example 1'</code>), but it should be automatic.</p>
  </li>
  <li><p>The tax is not added in the Contribution View and the Invoice. I think this shows that the new Contribution is not properly connected with its Financial Type (or Price Set?), because the tax is calculated automatically depending on the Financial Type, I think. I added the <code>'financial_type_id'</code> to the api Call, but the problem persists.</p>
  </li>
  </ul>
  <p>Any hint anybody?</p>
  
Tags: <civicontribute><api>
Title: Missing information when Importing Contributions via API
ThreadText: # Missing information when Importing Contributions via API
  
  (Asked by: username_0 on 2020-10-08)
  
  I want to import a list of contacts from a csv file (specifically: the Contact IDs), and create a Contribution via API for each one of them. Purpose: These contacts are all ordering the same articles, but have not yet ordered via the CiviContribute system, so we need to import the data.
  
  I wrote a PHP script for that, which is saving the new Contribution correctly on each Contact. It contains the following API call:
  
  ```
  civicrm_api3('Contribution', 'create', [
          'financial_type_id' => 11,
          'receive_date' => 20201008150000,
          'total_amount' => 11.15,
          'contact_id' => $civicrm_id,
          'contribution_status_id' => "Pending", 
          'payment_instrument_id' => "Überweisung", 
          'is_pay_later' => 1,
          'price_set_id' => 25,
          'skipLineItem' => 1,
          'api.line_item.create' => [
            '0' => [
              'price_field_id' => 55,
              'qty' => 1,
              'label' => 'article name example 1',
              'line_total' => 8.57,
              'unit_price' => 8.57,
            ],
            '1' => [
              'price_field_id' => 56,
              'qty' => 1,
              'label' => 'article name example 1',
              'line_total' => 2.05,
              'unit_price' => 2.05,
            ]
          ]
        ]);
  
  ```
  
  But it makes two mistakes:
  
  * The value in the "Item" column in the Contribution View and the Invoice is a default value "line item". I manage to solve this by adding the article name into the code (`'label' => 'article name example 1'`), but it should be automatic.
  * The tax is not added in the Contribution View and the Invoice. I think this shows that the new Contribution is not properly connected with its Financial Type (or Price Set?), because the tax is calculated automatically depending on the Financial Type, I think. I added the `'financial_type_id'` to the api Call, but the problem persists.
  
  Any hint anybody?
  
  **Tags:** civicontribute, api
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-10-09. Score: 0 | Accepted answer
  
  This should work
  
  ```
  civicrm_api3('Contribution', 'create', [
      'financial_type_id' => 11,
      'receive_date' => 0201008150000,
      'total_amount' => 11.15,
      'tax_amount' => 0.53,
      'net_amount' => 10.62,
      'contact_id' => $civicrm_id,
      'contribution_status_id' => "Pending", 
      'payment_instrument_id' => "Überweisung", 
      'is_pay_later' => 1,
      'skipLineItem' => 1,
      'api.line_item.create' => [
          'entity_table' => 'civicrm_contribution',
          'contribution_type_id' => 11,
          'financial_type_id' => 11,
          'price_field_id' => 55,
          'label' => 'article name example 1',
          'tax_amount' => 0.53,
          'unit_price' => 10.62,
          'line_total' => 10.62,
          'non_deductible_amount' => 0.00,
          'qty' => 1.00,
        ]
    ]);
  
  ```
  
  
  ---
  
  