How to receive data from a POST request in frappe

I am sending post request to frappe API using python script


how could I receive this posted data in frappe, I have tried frappe.request.data but it’s not working

When you post to a frappe api method:

If you included parameters in yous post method, the parameters will be passed into the method. The method then uses these parameters to do what it is coded to do.

  1. Do you know the method that you are posting the data to?
  2. What are you trying to achieve with your post? (I see a customer doctype parameter but a education module in the path.)

@fineco Thanks for the reply and yes I know the method to which I am passing data here is complete url
http://192.168.1.23:8000/api/method/erpnext.education.doctype.papertemplate.templates.paperTemplate.post_test

In method post_test I want to Iterate the doc dictionary and insert that record into customer’s doctype
here is the receiving side code which always return false for the moment I just want to check if data received or not ?
image

try json.dumps(payload) while making the request.
and json.loads(frappe.request.data) when reading data from request.

e.g.

make request

r = requests.post(url, data=json.dumps(doc))

read request

@frappe.whitelist(allow_guest=True)
def post_test():
    return json.loads(frappe.request.data)
5 Likes

from frappe import _

@frappe.whitelist(allow_guest=True)
def post_test(**kwargs):
	#pack your parameters back into a dictionary
	kwargs=frappe._dict(kwargs)
	#auth into erp site
	#use built-in api or other method to add the customer
	make post to URL: http://xxx.xxx.xxx/api/resource/Customer?data=kwargs

If you intend to just add a customer, as it seems, you may want to authenticate the user and directly use the /api/resource/Customer resource. This should also work if you post via web.@relevant_one method also works for sending the request but returns the incoming parameters before using them.

9 Likes

Thanks a lot @fineco :slight_smile: I works for me.

1 Like