Try ERPNext Buy Support Partners Foundation

Erpnext Rest API for Sales Invoice creation from Sales Order using Postman

Hi All,

I am having a problem creating and saving the invoice using the sale order name . I am trying to do this in postman. Here is my screenshot

It outputs a json file but once I check the erpnext website I could not find what was the invoice generated.

Here is the sample json file:

    "message": {
        "owner": "",
        "idx": 0,
        "docstatus": 0,
        "naming_series": "ACC-SINV-.YYYY.-",
        "customer": "Albert",
        "customer_name": "Albert",
        "is_pos": 0,
        "is_consolidated": 0,
        "is_return": 0,
        "company": "Store",
        "posting_date": "2020-10-14",
        "posting_time": "16:47:34.608501",
        "set_posting_time": 0,
        "due_date": "2020-10-14",
        "update_billed_amount_in_sales_order": 0,
        "territory": "All Territories",
        "shipping_address_name": "",
        "currency": "PHP",
        "conversion_rate": 1.0,
        "selling_price_list": "Standard Selling",
        "price_list_currency": "PHP",
        "plc_conversion_rate": 1.0,
        "ignore_pricing_rule": 1,
        "set_warehouse": "Albert CS",
        "update_stock": 0,
        "total_billing_amount": 0.0,
        "total_qty": 1.0,
        "base_total": 2500.0,
        "base_net_total": 2500.0,
        "total_net_weight": 0.0,
        "total": 2500.0,
        "net_total": 2500.0,
        "tax_category": "",
        "base_total_taxes_and_charges": 0.0,
        "total_taxes_and_charges": 0.0,
        "loyalty_points": 0,
        "loyalty_amount": 0.0,
        "redeem_loyalty_points": 0,
        "apply_discount_on": "Grand Total",
        "base_discount_amount": 0.0,
        "additional_discount_percentage": 0.0,
        "discount_amount": 0.0,
        "base_grand_total": 2500.0,
        "base_rounding_adjustment": 0.0,
        "base_rounded_total": 2500.0,
        "base_in_words": "PHP Two Thousand, Five Hundred only.",
        "grand_total": 2500.0,
        "rounding_adjustment": 0.0,
        "rounded_total": 2500.0,
        "in_words": "PHP Two Thousand, Five Hundred only.",
        "total_advance": 0.0,
        "outstanding_amount": 2500.0,
        "allocate_advances_automatically": 0,
        "base_paid_amount": 0.0,
        "paid_amount": 0.0,
        "base_change_amount": 0.0,
        "change_amount": 0.0,
        "write_off_amount": 0.0,
        "base_write_off_amount": 0.0,
        "write_off_outstanding_amount_automatically": 0,
        "group_same_items": 0,
        "language": "en",
        "is_internal_customer": 0,
        "customer_group": "All Customer Groups",
        "is_discounted": 0,
        "status": "Draft",
        "debit_to": "Debtors - CS",
        "party_account_currency": "PHP",
        "is_opening": "No",
        "c_form_applicable": "No",
        "commission_rate": 0.0,
        "total_commission": 0.0,
        "pos_total_qty": 0.0,
        "doctype": "Sales Invoice",
        "items": [
                "owner": "",
                "parentfield": "items",
                "parenttype": "Sales Invoice",
                "idx": 1,
                "docstatus": 0,
                "item_code": "Camera",
                "item_name": "Camera",
                "description": "Camera",
                "item_group": "Products",
                "image": "",
                "qty": 1.0,
                "stock_uom": "Nos",
                "uom": "Nos",
                "conversion_factor": 1.0,
                "stock_qty": 1.0,
                "price_list_rate": 2500.0,
                "base_price_list_rate": 2500.0,
                "margin_type": "",
                "margin_rate_or_amount": 0.0,
                "rate_with_margin": 0.0,
                "discount_percentage": 0.0,
                "discount_amount": 0.0,
                "base_rate_with_margin": 0.0,
                "rate": 2500.0,
                "amount": 2500.0,
                "base_rate": 2500.0,
                "base_amount": 2500.0,
                "is_free_item": 0,
                "net_rate": 2500.0,
                "net_amount": 2500.0,
                "base_net_rate": 2500.0,
                "base_net_amount": 2500.0,
                "delivered_by_supplier": 0,
                "income_account": "Sales - CS",
                "is_fixed_asset": 0,
                "expense_account": "Cost of Goods Sold - CS",
                "enable_deferred_revenue": 0,
                "weight_per_unit": 0.0,
                "total_weight": 0.0,
                "warehouse": "Albert- CS",
                "allow_zero_valuation_rate": 0,
                "item_tax_rate": "{}",
                "actual_batch_qty": 0.0,
                "actual_qty": 599.0,
                "sales_order": "SAL-ORD-2020-00068",
                "so_detail": "8dd69dbc8b",
                "delivered_qty": 0.0,
                "cost_center": "Main - CS",
                "page_break": 0,
                "doctype": "Sales Invoice Item",
                "__islocal": 1,
                "__unsaved": 1
        "pricing_rules": [],
        "packed_items": [],
        "timesheets": [],
        "taxes": [],
        "advances": [],
        "payment_schedule": [],
        "payments": [],
        "sales_team": [],
        "__islocal": 1,
        "__onload": {
            "load_after_mapping": true
        "__unsaved": 1

Any thoughts on how will I make this create an invoice?

Please notice that the JSON response contains no data section. Instead it contains a message section.

It’s obvious once you see it. In long hand the message is trying to say, “Oh, so ya wanna invoice, eh? Buster? Well here’re the pieces. Go make yer own, ‘n quit botherin’ me.”

So all you have to do is cut out the message body, and paste it into a POST.

curl -sLX POST '' \
-H 'Authorization: token ec226d15b52879e:ca6deade2ff3d0e' \
-H 'Content-Type: application/json' \
--data-raw '{
        "owner": "",
        "idx": 0,
        "docstatus": 0,
        "naming_series": "ACC-SINV-.YYYY.-",
        "customer": "Albert",
        "customer_name": "Albert",

     "     "     "     "     "     "     "
1 Like

Hey @Jest,

I’m working with the API right now as well and finding that we’re having many issues using Postman in particular. I saw some other folks suggest to try using ARC (also free) instead and we’ve had luck with that. I believe Postman sometimes tacks on a header that is not recognized by ERPNext and it errors out and says “200 OK”, which normally would mean success, but 200 is the “resource not recognized” code for ERPNext. Try it with ARC and see if that works. :slight_smile:

1 Like

I have used Postman with complete success for this exact task.

In the top-right corner of the bottom-left window there is a Cookies link and a Code link. You can press the Code link to generate an executable command in any one of a couple of dozen languages, including curl.

If you are unsuccessful creating a Sales Invoice from a Sales Order, please post the error message and a curl format example of what you did and I will help you try to track down the Postman setting that is incorrect.

1 Like

Thank you I’ll try that

thanks I’ll try it if Postman still won’t work for me

Oh , I see I have not noticed it yesterday I was focused on the response header .

Is it possible to create invoice with just the Sales Order Name and not writing every details of that sales_order?

To be honest I do not see anything on an Invoice that links back to the Sales Order it came from.

1 Like