Error when sending HTTP request in Body

Continuing the discussion from Using API to add new Customer:

@Spy could you please share with me the Body string which worked for you at the end? I’m having the same error. When I send the RESTful HTTP Call in the Query URL, everything works fine. When I’m sending it in the Body, I’m getting the error:

“TypeError: expected string or buffer\n”]"}"

Here examples for the 2 versions:

A: The Body version with the error:

B: The Query version which works successfully:

@David_Stegnitz its a JSON parse error, maybe your JSON gets escaped somewhere?

@rmehta Yes, I believe it has something to do with the format. I reproduced the issue on the ‘Postman’ tool, and here is my conclusion:

If I use an empty line between the content-disposition string and the body content, everything works fine:

But if I change anything small in the formatting, such as removing a line break, or just removing the empty line, I get the ‘expected string or buffer’ error. The problem I’m having is that in the Tomcat Integration framework I’m using, everything is XML based and I have to convert it to json, so I’m unable to influence the formatting of the passing json body content. Do you have any idea of how I could overcome the issue?

@rmehta I finally made it working with some code changes which I will document and share later on. However, now I’m getting a next validation message from ERPNext:

‘ValidationError: Max 100 rows for Stock Reconciliation.\n"]","_server_messages":"[“Removed items with no change in quantity or value.”, “Max 100 rows for Stock Reconciliation.”]"}’

Is this a general restriction that only max 100 rows in a document are allowed? Can I change that setting?

Thanks, David

@David_Stegnitz its designed to prevent web timeouts, maybe you should be able to bypass this by passing a flag. Do you want to try this? We can add it in the core product.

@rmehta Yes, I would like to try this. Could you advise me on the next steps on this and how I can try passing the flag? Thanks, David

As follows a summary of the changes we have done in the ERPNext Code:

Issue: There is an error appear “ValueError: No JSON object could be decoded” when data is sent from SAP to ERPNext in http request body.

Root cause: Http request is not well formed on SAP side, as result no data is coming to ERPNext.

Description: The issue was fixed on SAP side by forming http request which ERPNext could process.

Http request is still coming to ERPNext not completely in expected format: the data are present in request body but not in form data.
I’ve added the following code to ERPNext to handle this case:

file frappe-bench/apps/frappe/frappe/
— 2015-11-18 16:47:40.297103843 +0530
+++ 2015-11-20 23:48:44.482411978 +0530
@@ -70,10 +70,6 @@
response = frappe.handler.handle()

            elif frappe.request.path.startswith("/api/"):
  •                   if is None:
  •                  = request.get_data()
  •                   response = frappe.api.handle()
              elif frappe.request.path.startswith('/backups'):

Also in regards to the max 100 row Validation in the Stock Reconciliation Document, we have commented out the following code part:

75> if len(self.items) > 100:
76> frappe.throw(_(""“Max 100 rows for Stock Reconciliation.”""))

@rmehta If it would be possible to include the first HTTP change to the core version as well as to add an option to submit a flag thru the HTTP call to eliminate the 100-row validation, that would be great.

Thanks, David