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?