REST API POST for Customer and Sales Invoice DocType Challange

I’m trying to integrate our own POS and some More features with ERPNEXT and having challenge with following list.

  1. Rest API unable to post records for sales and Customer. i tried the following URL. where as GET request is working fine. i’m testing it with POSTMAN app.

http://127.0.0.1:8/api/resource/Customer?data={“customer_name”: “Adnan”,“customer_group”:“Commercial”,“customer_type”: “Company”,“territory”: “US”}

  1. how to create Customer with Contact through API
  2. where i can find the list of Whitelist Methods which we can call through API like “Login…etc”
  3. any sample URL to create invoice through API.

before using API we were thinking to write a SP to post sale invoice directly to DB but that can create some unknown challenges and finally we decided to go with API. any support will be highly appreciated.

Regards,
Adnan

@adnan

Refer this page for Rest API - Rest API

You can create a document by sending a POST request to the URL

e.g. for creating customer

http://localhost:8000/api/resource/Customer

Body

data: {"customer_group": "Commercial", "territory": "India", "customer_type": "Company", "customer_name": "Sangram Patil"}

Thanks @Sangram
i tried the above data as it is but i’m getting the internal server error. find the below image. but i’m able to fetch the data. and yes i got most of the help from rest api document.

Instead of raw pass it from form-data

it’s not working on my side even i tried same parameters…

there shouldn’t be any issue…

Can share full traceback/ Response.

sorry i got it…let me see if i can fix it

Thanks i got it working.

is their any example where we can insert customer along with contact together?
also where i can find the list of white list methods?

really appreciate your efforts.

Thanks

you have to write separate API for both Customer and Contact.

Check api.py for more details

hi @Sangram
hope you are doing good. i’m facing a small challenge with sales invoice through API with Payment information. and i’m getting the above error with V8.

below is the string i’m passing.

{
“cash_bank_account”:“Cash - CP”,
“is_pos”:“1”,
“submit_on_creation”:“1”,
“against_income_account”:“Sales - CP”,
“party_account_currency”:“USD”,
“owner”:“administrator”,
“price_list_currency”:“USD”,
“mode_of_payment”:" Cash",
“customer_name”:“Mehdi Hassan”,
“update_stock”:“1”,
“company”:“Test Company”,
“customer”:“Mehdi Hassan”,
“territory”:“All”,
“is_opening”:" No",
“customer_group”:“Individual”,
“naming_series”:“MTS-”,
“currency”:“USD”,
“debit_to”:“Debtors - CP”,
“remarks”:" POS - 100306",
“posting_date”:" 2017-05-08",
“selling_price_list”:“PIP Selling”,
“discount_amount”:"",
“apply_discount_on”:"",
“items”:“FROBEN SR 200MG CAP”,
“items”:[
{
“cost_center”:“Branch - CP”,
“qty”:“15”,
“warehouse”:“Branch - CP”,
“pricing_rule”:“7% Discount “,
“owner”:“administrator”,
“item_code”:“FROBEN SR 200MG CAP”,
“parenttype”:” Sales Invoice”,
“parentfield”:“items”
}
],
“payments”:[
{
“mode_of_payment”:" Cash",
“amount”:“282.6”,
“account”:“Cash - CP”
}
]
}

if i remove the payment section from above data it’s working fine.

please have a look if you have time to see where i’m doing mistake.

Thanks in Advance.

Need Urgent help if someone tested Sales invoice with V8 REST API

@adnan

It is python error, have to look can’t multiply sequence by non-int of type ‘float’

Might be you are giving wrong inputs in the payment section.

Do it without adding payment section and do it manually so will get the issue. Where it comes from.

Hello , @adnan

i am getting the same problem trying to create customer through api ,
can you tell me how you got this solved ?

i am passing data according to above.

this is the string i am passing in value :

{"customer_name":"test_customer","customer_group":"All Customer Groups","territory":"All Territories","customer_type":"Company","mobile_no":“546546546”}

its giving me Json error

File “/usr/lib/python2.7/json/decoder.py”, line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File “/usr/lib/python2.7/json/decoder.py”, line 384, in raw_decode
raise ValueError(“No JSON object could be decoded”)
ValueError: No JSON object could be decoded
Home
Status: 500

any help is appreciated

Check the double quotes “546546546”

1 Like

copy your value of JSON and try in the following website.

it’ll tell you where the problem is in your json.

in Above json, “546546546” these are not double quotes. correct them.

Regards,
Adnan

Thanks a Ton @adnan , @schilgod ,
.
could you please guide me to create a sales invoice as well ,
i just want to create a pos invoice with minimum details ,

.
here is the string i pass
{"is_pos":"1","submit_on_creation":"1","customer":"test","update_stock":"1","territory":"All","is_opening":" No","currency":"KWD","debit_to":"Debtors - SJ","items":[{"item_code":"test item-06D","qty":"15","rate":"5"}],"payments":[{"mode_of_payment":" Cash","amount":"250"}]}

.
the json checks out from the validation on the site

but it gives me an error -

File “/home/taher/frappe-bench/apps/frappe/frappe/model/base_document.py”, line 465, in get_invalid_links
setattr(self, df.fieldname, values.name)
AttributeError: ‘NoneType’ object has no attribute ‘name’
Home
Status: 500

thank you in advance .

Please POST full Error.

This error Means you are using wrong Value for a list Field. or mandatory parameter is missing

@adnan
i think the issue is with the payments ,

when i pass params as :
{"customer":"test_customer123","submit_on_creation":"1","is_pos":"1","update_stock":"1","items":[{"item_code":"test item-06D","qty":"15","rate":"5"},{"item_code":"test item 6d box","qty":"1","rate":"5"}]}

It works absolutely fine , though still invoice does not get submitted ,
.
but when i try to pass the payments as
{"customer":"test_customer123","submit_on_creation":"1","is_pos":"1","update_stock":"1","items":[{"item_code":"test item-06D","qty":"15","rate":"5"},{"item_code":"test item 6d box","qty":"1","rate":"5"}],"payments":[{"mode_of_payment":" Cash","amount":"250"}]}

its giving me below error :

Server Error
Traceback (most recent call last):
File “/home/taher/frappe-bench/apps/frappe/frappe/app.py”, line 67, in application
response = frappe.api.handle()
File “/home/taher/frappe-bench/apps/frappe/frappe/api.py”, line 119, in handle
“data”: frappe.get_doc(data).insert().as_dict()
File “/home/taher/frappe-bench/apps/frappe/frappe/model/document.py”, line 217, in insert
self._validate_links()
File “/home/taher/frappe-bench/apps/frappe/frappe/model/document.py”, line 717, in _validate_links
result = d.get_invalid_links(is_submittable=self.meta.is_submittable)
File “/home/taher/frappe-bench/apps/frappe/frappe/model/base_document.py”, line 465, in get_invalid_links
setattr(self, df.fieldname, values.name)
AttributeError: ‘NoneType’ object has no attribute ‘name’
Home
Status: 500

all the spelling and mandatory fields are there , still i am not sure why payments is causing the issue .

yes you are missing Mandatory Parameters from Payment.

{“mode_of_payment”:“XXXX”,“amount”:xxxx"base_amount":xxxx,“account”:“XXX”}

try with these parameters.

and Amount should not be in Double quotes