Standard Json format for sales order through rest api

I have a XLSX sheet which has the orders data…I want to read the xlsx and create the Sales Order using rest api…
what is the json format for successful creation of sales order…

Currently i have tried previously created Sales Order Json format ,But i am getting "ValidationError: Please enter ‘Expected Delivery Date’ " Error.

1 Like

Try this:

[
{
“advance_paid”: 0.0,
“company”: “_Test Company”,
“conversion_rate”: 1.0,
“currency”: “INR”,
“customer”: “_Test Customer”,
“customer_group”: “_Test Customer Group”,
“customer_name”: “_Test Customer”,
“delivery_date”: “2013-02-23”,
“doctype”: “Sales Order”,
“base_grand_total”: 1000.0,
“grand_total”: 1000.0,
“naming_series”: “_T-Sales Order-”,
“order_type”: “Sales”,
“plc_conversion_rate”: 1.0,
“price_list_currency”: “INR”,
“items”: [
{
“base_amount”: 1000.0,
“base_rate”: 100.0,
“description”: “CPU”,
“doctype”: “Sales Order Item”,
“item_code”: “_Test Item Home Desktop 100”,
“item_name”: “CPU”,
“parentfield”: “items”,
“qty”: 10.0,
“rate”: 100.0,
“warehouse”: “_Test Warehouse - _TC”,
“stock_uom”: “_Test UOM”,
“conversion_factor”: 1.0,
“uom”: “_Test UOM”
}
],
“selling_price_list”: “_Test Price List”,
“territory”: “_Test Territory”,
“transaction_date”: “2013-02-21”
}
]

1 Like

hi @KanchanChauhan
Thanks for the reply…i tried that format…Now I am getting following error

Traceback (most recent call last):
File “/home/jithendra/frappe-bench/apps/frappe/frappe/app.py”, line 61, in application
response = frappe.api.handle()
File “/home/jithendra/frappe-bench/apps/frappe/frappe/api.py”, line 116, in handle
data.update({
AttributeError: ‘list’ object has no attribute ‘update’

I am using following rest api “http://192.168.0.109:8000/api/resource/Sales Order” and “Post” method

Please go through these links, might help you:

https://frappe.github.io/erpnext/current/models/selling/sales_order

thanks @KanchanChauhan

Now i am passing this json;

{
“data”: {
“advance_paid”: 0.0,
“company”: “Merit System Private Limited”,
“conversion_rate”: 1.0,
“currency”: “INR”,
“customer”: “Mani V”,
“customer_group”: “Commercial”,
“customer_name”: “Mani V”,
“delivery_date”: “2017-03-28”,
“doctype”: “Sales Order”,
“base_grand_total”: 85490.0,
“grand_total”: 85490.0,
“naming_series”: “SO-”,
“order_type”: “Sales”,
“plc_conversion_rate”: 1.0,
“price_list_currency”: “INR”,
“items”: [{
“base_amount”: 85490.0,
“base_rate”: 85490.0,
“description”: “Lenovo Yoga 710 (14") Yoga 710 (14") 14" LAPTOP FOR ON-THE-GO CONNECTIVITY”,
“doctype”: “Sales Order Item”,
“item_code”: “Lenovo Yoga 710 (14") Yoga 710 (14") 14" LAPTOP FOR ON-THE-GO CONNECTIVITY”,
“item_name”: “Lenovo Yoga 710 (14") Yoga 710 (14") 14" LAPTOP FOR ON-THE-GO CONNECTIVITY”,
“parentfield”: “items”,
“qty”: 1.0,
“rate”: 85490.0,
“warehouse”: “Finished Goods - MSPL”,
“stock_uom”: “Unit”,
“conversion_factor”: 1.0,
“uom”: “Unit”
}],
“delivery_date”: “2017-03-30”,
“selling_price_list”: “Standard Selling”,
“territory”: “India”,
“transaction_date”: “2017-03-22”,
“cust_address”:“Mani V”
}
}

As you can see i am passing “delivery_date” but i am getting error “ValidationError: Please enter ‘Expected Delivery Date’”

Please help with this

You are sending in delivery_date twice. Can you delete one of it.

@KanchanChauhan
Ya ,i have deleted it…that error still persists…

if i pass json in the below format

{
“advance_paid”: 0.0,
“company”: “Merit System Private Limited”,
“conversion_rate”: 1.0,
“currency”: “INR”,
“customer”: “Mani V”,
“customer_group”: “Commercial”,
“customer_name”: “Mani V”,
“delivery_date”: “2017-03-28”,
“doctype”: “Sales Order”,
“base_grand_total”: 85490.0,
“grand_total”: 85490.0,
“naming_series”: “SO-”,
“order_type”: “Sales”,
“plc_conversion_rate”: 1.0,
“delivery_date”: “2017-03-29”,
“price_list_currency”: “INR”,
“items”: [{
“base_amount”: 85490.0,
“base_rate”: 85490.0,
“description”: “Lenovo Yoga 710 (14") Yoga 710 (14") 14" LAPTOP FOR ON-THE-GO CONNECTIVITY”,
“doctype”: “Sales Order Item”,
“item_code”: “Lenovo Yoga 710 (14") Yoga 710 (14") 14" LAPTOP FOR ON-THE-GO CONNECTIVITY”,
“item_name”: “Lenovo Yoga 710 (14") Yoga 710 (14") 14" LAPTOP FOR ON-THE-GO CONNECTIVITY”,
“parentfield”: “items”,
“qty”: 1.0,
“rate”: 85490.0,
“warehouse”: “Finished Goods - MSPL”,
“stock_uom”: “Unit”,
“conversion_factor”: 1.0,
“uom”: “Unit”
}],

"selling_price_list": "Standard Selling",
"territory": "India",
"transaction_date": "2017-03-22",
    "cust_address":"Mani V"

}

i.e removing one braces (extra object)…i will get following error

Traceback (most recent call last):
File “/home/jithendra/frappe-bench/apps/frappe/frappe/app.py”, line 61, in application
response = frappe.api.handle()
File “/home/jithendra/frappe-bench/apps/frappe/frappe/api.py”, line 120, in handle
“data”: frappe.get_doc(data).insert().as_dict()
File “/home/jithendra/frappe-bench/apps/frappe/frappe/model/document.py”, line 194, in insert
self._validate()
File “/home/jithendra/frappe-bench/apps/frappe/frappe/model/document.py”, line 401, in _validate
self._validate_links()
File “/home/jithendra/frappe-bench/apps/frappe/frappe/model/document.py”, line 626, in _validate_links
invalid_links, cancelled_links = self.get_invalid_links()
File “/home/jithendra/frappe-bench/apps/frappe/frappe/model/base_document.py”, line 494, in get_invalid_links
setattr(self, df.fieldname, values.name)
AttributeError: ‘NoneType’ object has no attribute ‘name’

@KanchanChauhan : As you suggested we have tried with all the solution but still error persist. @makarand_b can you clear about this .

@jithendra,

following simple post request for sales order worked for me

URL: http://localhost:8000/api/resource/Sales Order
Data: data ={
	"customer": "Customer",
	"delivery_date": "2017-03-22",
	"items": [{
		"item_code": "Item code",
		"qty": 2,
		"rate": 200002
	}]
}
Thanks,
Makarand

Hi @makarand_b

My url : http://192.168.0.109:8000/api/resource/Sales Order
my json data : {
“customer”: “Mani V”,
“delivery_date”: “2017-03-30”,
“cust_address”: “Mani V”,
“items”: [{
“item_code”: “Lenovo Yoga 710 (14") Yoga 710 (14") 14" LAPTOP FOR ON-THE-GO CONNECTIVITY”,
“qty”: 2,
“rate”: 90000
}]
}

But I am Still getting the same error

  	Server Error

Traceback (most recent call last):
File “/home/jithendra/frappe-bench/apps/frappe/frappe/app.py”, line 61, in application
response = frappe.api.handle()
File “/home/jithendra/frappe-bench/apps/frappe/frappe/api.py”, line 120, in handle
“data”: frappe.get_doc(data).insert().as_dict()
File “/home/jithendra/frappe-bench/apps/frappe/frappe/model/document.py”, line 194, in insert
self._validate()
File “/home/jithendra/frappe-bench/apps/frappe/frappe/model/document.py”, line 401, in _validate
self._validate_links()
File “/home/jithendra/frappe-bench/apps/frappe/frappe/model/document.py”, line 626, in _validate_links
invalid_links, cancelled_links = self.get_invalid_links()
File “/home/jithendra/frappe-bench/apps/frappe/frappe/model/base_document.py”, line 494, in get_invalid_links
setattr(self, df.fieldname, values.name)
AttributeError: ‘NoneType’ object has no attribute ‘name’

if i use
URL: http://localhost:8000/api/resource/Sales Order
instead of URL : http://192.168.0.109:8000/api/resource/Sales Order
I will get the error as

		Not Permitted

You do not have enough permissions to complete the action

hi @makarand_b can u please tell that, do we need to write separate api for retrieving data from database. If yes, how to write and how to integrate this api to erpnext. I’m new to erpnext, if i get reply it will more helpful for me.

Thanks in advance

How can i set value for table multiselect(Two values)

Welcome to ERPNext @vignesh_b

Have you found and tried these for clues and pointers?

If you remain stuck, start a new thread with specific details, that may get you pointers to try…

I cant able to set default data for tablemultiselect field in install_fixtures.py can anybody help me

{‘doctype’:‘Default Data Setup’,
‘default_name’:_(‘Default Data’),
‘date’:“2020-05-28”,
‘email’:“vignesh@gmail.com”,
‘date_time’:“2020-05-28 06:15:26.021900”,
‘select’:“External”,
‘time’:“06:15:26”,
‘currency’:“USD”,
‘password’:“123”,
“mobile”:“987654321”,
‘is_company’:1,
‘rating’:3,
‘percent’:“99”,
‘read’:“Hello”,
‘naming_series’:“80000”,
‘image_3’:“/assets/erpnext/images/erp-icon2.svg”,
“table_multi”:“”
},

Hello,

It seems you are not performing the request correctly.

Must be a POST request with form-data and key name data.