0

I am using the CiviCRM API Explorer v3 and try to create a LineItem. The following fields appear as obligatory fields for that: 'entity_id', 'qty', 'unit_price', 'line_total'

But when I try to create a LineItem with those fields, I get the following error:

    {
    "code": -1,
    "error_message": "DB Error: unknown error",
    "mode": 16,
    "debug_info": "INSERT INTO `civicrm_line_item` (`entity_id` , `label` , `qty` , `unit_price` , `line_total` ) VALUES ( ... , 'line item' ,  1.00 ,  ... ,  ... )  [nativecode=1364 ** Field 'entity_table' doesn't have a default value]",
    "type": "DB_Error",
    "user_info": "INSERT INTO `civicrm_line_item` (`entity_id` , `label` , `qty` , `unit_price` , `line_total` ) VALUES ( ... , 'line item' ,  1.00 ,  ... ,  ... )  [nativecode=1364 ** Field 'entity_table' doesn't have a default value]",
    "to_string": "[db_error: message=\"DB Error: unknown error\" code=-1 mode=callback callback=CRM_Utils_REST::fatal prefix=\"\" info=\"INSERT INTO `civicrm_line_item` (`entity_id` , `label` , `qty` , `unit_price` , `line_total` ) VALUES ( ... , 'line item' ,  1.00 ,  ... ,  ... )  [nativecode=1364 ** Field 'entity_table' doesn't have a default value]\"]",
    "is_error": 1
}

When I add the field "Line Item Entity Type" (in the code: "entity_table") to the API call, it works. Does anybody know why this field is not marked as obligatory in API Explorer v3?

1 Answer 1

2

The entity table is mandatory for creating line items, unfortunately, in the API spec for line items, the Entity table is not marked as mandatory.

In the recent version of Civi it is also mandatory to have a price field and price field value for the line item else it would create 500 errors in some scenarios.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.