AttributeError: 'unicode' object has no attribute 'qty'. I am getting this error on on sales%20order api call

Can someone please provide required post fields for Sales%20Order api POST call.

curl_setopt($ch, CURLOPT_POSTFIELDS, array(‘data’ => json_encode($arr)));

I tried to call api Sales%20Order GET method and provided that data as post fields for Sales%20Order api POST call still same error.

here is complete error details

Traceback (most recent call last):
File “/home/frappe/benches/bench-2019-03-28/apps/frappe/frappe/”, line 66, in application
response = frappe.api.handle()
File “/home/frappe/benches/bench-2019-03-28/apps/frappe/frappe/”, line 122, in handle
“data”: frappe.get_doc(data).insert().as_dict()
File “/home/frappe/benches/bench-2019-03-28/apps/frappe/frappe/model/”, line 222, in insert
File “/home/frappe/benches/bench-2019-03-28/apps/frappe/frappe/model/”, line 876, in run_before_save_methods
File “/home/frappe/benches/bench-2019-03-28/apps/frappe/frappe/model/”, line 772, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File “/home/frappe/benches/bench-2019-03-28/apps/frappe/frappe/model/”, line 1048, in composer
return composed(self, method, *args, **kwargs)
File “/home/frappe/benches/bench-2019-03-28/apps/frappe/frappe/model/”, line 1031, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/home/frappe/benches/bench-2019-03-28/apps/frappe/frappe/model/”, line 766, in
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File “/home/frappe/benches/bench-2019-03-28/apps/erpnext/erpnext/selling/doctype/sales_order/”, line 34, in validate
super(SalesOrder, self).validate()
File “/home/frappe/benches/bench-2019-03-28/apps/erpnext/erpnext/controllers/”, line 39, in validate
super(SellingController, self).validate()
File “/home/frappe/benches/bench-2019-03-28/apps/erpnext/erpnext/controllers/”, line 21, in validate
super(StockController, self).validate()
File “/home/frappe/benches/bench-2019-03-28/apps/erpnext/erpnext/controllers/”, line 61, in validate
File “/home/frappe/benches/bench-2019-03-28/apps/erpnext/erpnext/controllers/”, line 377, in validate_qty_is_not_zero
if not item.qty:
AttributeError: ‘unicode’ object has no attribute ‘qty’

This works for me

{“customer”: “Customer One”,
“delivery_date”: “2019-03-12”,
“po_no”: “CPONO9990009”,
“shipping_address”: “Customer_One_Store_001-Shipping”,
“items”: [{
“item_code”: “ITEM1”,
“qty”: 1,
“rate”: 12.50

Thank you for reply. But still have same error.

$arr = array(‘customer’=> ‘Customer One’,
‘delivery_date’=> ‘2019-03-12’,
‘po_no’=> ‘CPONO9990009’,
‘shipping_address’=> ‘Customer_One_Store_001-Shipping’,
‘items’=> array(‘item_code’=> ‘1’,‘qty’=> 1,‘rate’=> 12.50));

curl_setopt($ch, CURLOPT_POSTFIELDS, array(‘data’ => json_encode($arr)));

Sorry, sam1. I’m no expert in PHP. To many other ‘irons in the fire’ to dig deeper into your specifics.
You might attempt prototyping the call directly in Postman, or cURL.
The supplied JSON works as a decent ‘minimum’ in the body of a POST to /api/resource/Sales%20Order, in my environment, using Postman, Python (requests), C# and Groovy clients.

I just remember that Postman has a cool ‘Code’ feature.
Here’s the output from Postman for PHP cURL
Maybe it’ll help, if not I suggest the prototyping in Postman option yourself

<?php $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => "{\"customer\": \"Customer One\",\r\n\t\"delivery_date\": \"2019-03-12\",\r\n\t\"po_no\": \"CPONO9990009\",\r\n\t\"shipping_address\": \"Customer_One_Store_001-Shipping\",\r\n\t\"items\": [{\r\n\t\t\t\t\"item_code\": \"ITEM1\",\r\n\t\t\t\t\"qty\": 1,\r\n\t\t\t\t\"rate\": 12.50\r\n\t}]\r\n}", CURLOPT_HTTPHEADER => array( "Accept: application/json", "Authorization: Bearer IkRqbsg9Zw7mRq56jrs0zlbJ9XCA9X", "Content-Type: application/json", "Postman-Token: 00aa12c3-267f-4079-98b7-abc1b3a5c2cd", "cache-control: no-cache" ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; }

@mattlongfield Thank you very much. Finally got it working with your help.
Really appreciate your help. Thanks

Hi please could you offer any learning tips, quick notes, or sticking points you had to resolve. That would be a helpful reference for all and perhaps you too one day.


1 Like