Sales Invoice Api call issue

Hi,

I’m trying to isert my sales invoice details via api

But it showing some error

please help me out.

Here is my api call

$item_mapping = array(
‘item_code’ => $courier_charges,
‘item_name’ => $courier_charges,
‘qty’ => 1,
“description”=>$courier_charges,
“gst_hsn_code”=>996812,
“uom”=>“Nos”,
“stock_uom”=>“Nos”,
“conversion_factor”=>1,
“stock_qty”=>1,
“price_list_rate”=>$total_amount_courier,
“amount”=>$total_amount_courier,
“income_account”=>“Sales - P”,
“expense_account”=>“Cost of Goods Sold - P”,
“cost_center”=>“Main - P”,
‘rate’=>$total_amount_courier
);

$item_mapping_arr = array(
‘item_code’ => “123”,
‘qty’ => 1,
‘rate’=>$total_amount_courier
);
$payment_due_date = date(‘Y-m-d’,strtotime("+7 day", strtotime(date(‘Y-m-d’))));

$erp_fields=array();
$erp_fields[‘naming_series’]=“SINV-”;
$erp_fields[‘tax_id’]=“33AAFCS2530P1Z8”;
$erp_fields[‘customer’]=$party_code;
$erp_fields[‘due_date’]=$payment_due_date;
$erp_fields[‘items’]=$item_mapping_arr;
$erp_fields[‘debit_to’]=“Debtors - P”;

$insert = apiCall(“INSERT”, “Sales Invoice”, $erp_fields, ‘’);

//all the above variables have values and no issues in the api call(i’m pretty sure about that).
because i’m using the function everywhere and Its working

here is my error
Server Error

Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/app.py”, line 67, in application
response = frappe.api.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/api.py”, line 119, in handle
“data”: frappe.get_doc(data).insert().as_dict()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 218, in insert
self.run_before_save_methods()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 859, in run_before_save_methods
self.run_method(“validate”)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 755, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 1024, in composer
return composed(self, method, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 1007, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 749, in
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/doctype/sales_invoice/sales_invoice.py”, line 58, in validate
super(SalesInvoice, self).validate()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/selling_controller.py”, line 37, in validate
super(SellingController, self).validate()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/stock_controller.py”, line 17, in validate
super(StockController, self).validate()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/accounts_controller.py”, line 40, in validate
self.set_missing_values(for_validate=True)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/doctype/sales_invoice/sales_invoice.py”, line 249, in set_missing_values
super(SalesInvoice, self).set_missing_values(for_validate)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/selling_controller.py”, line 49, in set_missing_values
self.set_price_list_and_item_details(for_validate=for_validate)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/selling_controller.py”, line 71, in set_price_list_and_item_details
self.set_missing_item_details(for_validate=for_validate)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/accounts_controller.py”, line 188, in set_missing_item_details
if item.get(“item_code”):
AttributeError: ‘unicode’ object has no attribute ‘get’

Thankyou.

It’s related to the “type” of the field. The provided value is a string, converting its type to dict might help.