Plz help-urgent- post sale invoice

Hi everyone,

Here info of my project,

1- Client cloud server api = https//:domain/api/v1/Postdata

2- pos machine erpnext on other location.

I want to post sale invoice that salesman create on pos machine , to client server through API using provided json .

Plz let me know in which file i should use json and ho to integrate my pos erpnext system with my client to share sale invoice.

Request to experts plz help me to resolve this problem and guide me step by step that how i can integrate.

Firstly, I don’t think is an ‘urgent’ message forum. We all are volunteers and can help only as much.
Secondly, I think it would be better if you can explain what you have tried that is not working. Sales Invoice JSON would simply be JSON containing atleast the mandatory fields of the Sales Invoice doctype. You can easily see that in action if you tap into your normal browser request trace.

Frankly I couldn’t understand what is tripping you. Some leads might help you get answers faster.

Also please don’t make multiple threads of 1 issue. You have posted same issue om another thread. In order to assist you need to need to state clearly what the objective is, what have you tried and traceback errors you got. Else it will surely be ignored by the volunteers.

Sorry to use urgent word.

Dear @Muzzy u r right that i have already posted same issue, @shreyansh Actually i am not a expert developer . I liked erpnext features and thats y i want to use it .

My requirements are so simple.

I want when i submit pos sale invoice my sale detail like .
1- sale-item-name
2-date and time
3- pos-user-id
4- total sale amount
5- total tax amount
6- total bill amount
Above will Send to my online server at the time of submission pos sale invoice,
I have json and API of my online server .
Now issue is, i am not much familiar with erpnext and i dont know in which files i put my json and API .
Plz let me know k files name and how can i use my json post request and what changes i should do in other files to perform this task successful.

{

“InvoiceNumber”:””,

“USERPOSID”:1234,

“DateTime”:”2020-01-01,

“TotalBillAmount”:0.0,

“Quantity”:0.0,

“TotalSaleAmount”:0.0,

“TotalTax”:0.0,

}

I hope i have explain what u want to know,

Again sorry for urgent word and same issue post

Hi,

So, there are two ways I can think of: (assuming you are v12+)

  1. Webhoooks: Webhooks
  2. REST API: REST API

For either, you don’t need any modifications in erpnext. They both are fairly well supported interfaces. Of course, here I am assuming you are trying to extract only those fields which you have customized on the doctype you are trying to access.

If I were you, I would have done this:

  1. Create a Webhook on the Sales Invoice form. Then, maybe using some on doctype field filter only those which are POS submitted. (for example, a default field which can set to POS when POS invoice is created)
  2. Then, catch this webhook in a cloud hosted functions - like Google Cloud Function, or Heroku etc.
  3. Parse the JSON, transform the way you want, and post it to your API.

You can always skip (2) above assuming your API is able to handle POSTed data from a webhook (which is also a JSON)

@shreyansh thanx alot for your kind response, today i will check as per your provided information Then let u know .

Thanx again

@shreyansh below is error of post using webhook.

Plz let me know that how to disable/false ssl verification on request url.

{‘method_name’: ‘frappe.integrations.doctype.webhook.webhook.enqueue_webhook’, ‘log’: <function log at 0x7ffab7feb7b8>, ‘retry’: 0, ‘is_async’: True, ‘user’: ‘Administrator’, ‘kwargs’: {‘doc’: <erpnext.accounts.doctype.sales_invoice.sales_invoice.SalesInvoice object at 0x7ffab846e5c0>, ‘webhook’: {‘name’: ‘HOOK-0001’, ‘condition’: ‘’, ‘webhook_docevent’: ‘on_submit’, ‘webhook_doctype’: ‘Sales Invoice’}}, ‘job_name’: ‘frappe.integrations.doctype.webhook.webhook.enqueue_webhook’, ‘event’: None, ‘method’: <function enqueue_webhook at 0x7ffab79d6488>, ‘site’: ‘site1.local’}
Traceback (most recent call last):
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/urllib3/contrib/pyopenssl.py”, line 485, in wrap_socket
cnx.do_handshake()
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/OpenSSL/SSL.py”, line 1915, in do_handshake
self._raise_ssl_error(self._ssl, result)
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/OpenSSL/SSL.py”, line 1647, in _raise_ssl_error
_raise_current_error()
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/OpenSSL/_util.py”, line 54, in exception_from_error_queue
raise exception_type(errors)
OpenSSL.SSL.Error: [(‘SSL routines’, ‘tls_process_server_certificate’, ‘certificate verify failed’)]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/urllib3/connectionpool.py”, line 672, in urlopen
chunked=chunked,
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/urllib3/connectionpool.py”, line 376, in _make_request
self._validate_conn(conn)
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/urllib3/connectionpool.py”, line 994, in validate_conn
conn.connect()
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/urllib3/connection.py”, line 394, in connect
ssl_context=context,
File "/home/frappe/frappe-bench/env/lib/python3.6/site-packages/urllib3/util/ssl
.py", line 370, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File “/home/frappe/frappe-bench/env/lib/python3.6/site-packages/urllib3/contrib/pyopenssl.py”, line 491, in wrap_socket
raise ssl.SSLError(“bad handshake: %r” % e)
ssl.SSLError: (“bad handshake: Error([(‘SSL routines’, ‘tls_process_server_certificate’, ‘certificate verify failed’)],)”,)

I don’t know much about to remove that dependency - but I don’t think this is an issue at ERPNext end. Rather,m I’d suggest that you check the SSL certificate of your API server. That seems to be broken or expired. In which case a secure connection for HTTP POST is not available.

Is your end API server SSL protected? Is the certificate valid? Is your erpnext hosted server SSL protected?

Thanx dear you are really supporting person.

@shreyansh yes dear my API server ssl certificate is valid and no issue with it even when i am testing through postman its work fine without any error, in php i know we use peerverifiy and hostverify= false to turn off request url ssl verification. But in erpnext i dont know how to disable ssl verification.

I have another , column/field name in sale invoice are different then my Api server column name,

E.g in erpnext sale invoice totalbillamount but my api server its totalsalevalue,

How i get/fetch totalbillamount from erpnext sale invoice and post it to my Api server through json format as totalsalevalue.

Almost all fields/column name are different then my API server column name in sale invoice table. How i can mapping each column name to post as per me server sale invoice column name.

Thanx in advance to supporting me .

This is an app for WooCommerce integration with ERPNext. It’s similar to what you are trying to achieve. Recommend that you go through it which may give you clues to fix your app.

1 Like

Though I think @Muzzy answers your question pretty well, just adding my opinion.

So, this is what I would have done (and I don’t know how to fix the SSL thing).

  1. I would have created an API in the cloud - maybe Heroku or AWS Lamdba or Google Cloud Function which listens for incoming POST request (maybe with some X-Header)
  2. Create a webhook in ERPNext instance to send across sales invoice fields - which ever I need
  3. Transform the fields into acceptable JSON and send across to final API.

OR, I think webhook configuration also allows you to create a custom JSON using Jinja (see the help link I gave). But, I couldn’t get this working correctly in my setup in past which is my an intermediary hook.

@Muzzy i checked ur share link of wooCommerce connector actually its sending sale data and customer data to erpnext , but in my case i want to send/post my erpnext invoices to other server on Asp.net with SQL db.

@shreyansh Now i have done fews things after a lot of search on internet, some data successfully posted to my API server but how can i get response from my API server …? Actually in response my API server send back Unique Serial Number that will be save against every sale invoice in erpnext and also will be print on sale invoice,

How i can get that serial number on Post response and how to save it in My erpnext db.

@erpnext786 I don’t think that is possible - a Webhook is a one-way street (at least when the underlying infra is not developed by you). ERPNext webhook can only send data and expected a 200 always. Nothing else.

What you are doing requires completely creating an API bridge external to the system. There are many ways to design, but the crux is that that bridge is responsible for fetching data (maybe periodically or on webhook invocation) from ERPNext, pushing to your API, get your API response, push to ERPNext.

I maybe wrong here about ERPNext webhook - but in that case someone else will have to confirm that. My opinion is that what you are expecting is not possible out-of-the-box for ERPNext webhook.

Hi I’m trying to do the same any luck ? Have you done ?