Answers.Body: <p>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.</p>
  <p>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.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-10-04T11:10:34.480Z
Answers.LastActivityDate: 2022-10-04T11:10:34.480Z
Answers.UserDisplayName: Pradeep Nayak
Body: <p>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'</p>
  <p>But when I try to create a LineItem with those fields, I get the following error:</p>
  <pre><code>    {
      &quot;code&quot;: -1,
      &quot;error_message&quot;: &quot;DB Error: unknown error&quot;,
      &quot;mode&quot;: 16,
      &quot;debug_info&quot;: &quot;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]&quot;,
      &quot;type&quot;: &quot;DB_Error&quot;,
      &quot;user_info&quot;: &quot;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]&quot;,
      &quot;to_string&quot;: &quot;[db_error: message=\&quot;DB Error: unknown error\&quot; code=-1 mode=callback callback=CRM_Utils_REST::fatal prefix=\&quot;\&quot; info=\&quot;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]\&quot;]&quot;,
      &quot;is_error&quot;: 1
  }
  </code></pre>
  <p>When I add the field &quot;Line Item Entity Type&quot; (in the code: &quot;entity_table&quot;) to the API call, it works.
  Does anybody know why this field is not marked as obligatory in API Explorer v3?</p>
  
Tags: <api><line-items>
Title: API Explorer DB error: Field 'entity_table' doesn't have a default value
ThreadText: # API Explorer DB error: Field 'entity_table' doesn't have a default value
  
  (Asked by: username_0 on 2022-10-04)
  
  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?
  
  **Tags:** api, line-items
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-10-04. Score: 1
  
  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.
  
  
  ---
  
  