ERPNext Conference 2019* ERPNext.com Blog

Standard Json format for sales order through rest api


#1

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.


#2

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”
}
]


#3

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


#4

Please go through these links, might help you:

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


#5

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


#6

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


#7

@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’


#8

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


#9

@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

Submit_on_creation has no effect
#10

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

#11

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