Sales Order is not saving when inserted via rest api while not getting any errors

i’m trying to raise a new Sales Order via rest api. After calling the insert function frappe returning Sales Order voucher no but it is not inserted in reality when i checked in the portal. Also, i confirmed this by checking the voucher no. its always returning the same voucher number that is not saved SO-KDY-2022-00247.
this is the model data i’m trying to insert

{
            'doctype':'Sales Order',
            'company':frappe.defaults.get_user_default('Company'),
            'branch':'Kondotty T P',
            'customer':'Mubeen Api 5',
            'delivery_date':datetime.now().strftime('%Y-%m-%d'),
            'sales_channel':'App',
            'order_type':'Sales',    
            'transaction_date':datetime.now().strftime('%Y-%m-%d'),                    
            'tax_category':'Cooked foods',
            'taxes_and_charges':'In State GST - TMY',
            'shipping_address_name':'Mubeen Api 5 - Billing-1-Billing',
            'customer_address':'Mubeen Api 5 - Billing-1-Billing',
            'shipping_rule':'Within 5 Kilometer',
            'items':[{
                        'parenttype':'Sales Order',
                        'parentfield':'items',
                        'item_code':'Margarita Pizza',
                        'note':'',
                        'qty':1,
                        'rate':300,
                        'amount':300
                    }],
            'taxes':[{
                        'parenttype':'Sales Order',
                        'parentfield':'taxes',
                        'charge_type':'On Net Total',
                        'description':'CGST @ 2.5',
                        'account_head':'CGST - TMY',
                        'rate':2.5,
                        'included_in_print_rate':1
                    },
                    {
                        'parenttype':'Sales Order',
                        'parentfield':'taxes',
                        'charge_type':'On Net Total',
                        'description':'SGST @ 2.5',
                        'account_head':'SGST - TMY',
                        'rate':2.5,
                        'included_in_print_rate':1
                    },
                    {
                        'parenttype':'Sales Order',
                        'parentfield':'taxes',
                        'charge_type':'Actual',
                        'description':'Within 5 Kilometer',
                        'account_head':'Delivery Charge - TMY',
                        'rate':0,
                        'tax_amount':0
                    }],
            'coupon_code':'RS 120 OFF',
            'discount_amount':120
        }

This api is for a flutter application integration with frappe erpnext.

Make sure your using POST request

thanks for the reply. its already post request. did you spot any issue with the model data i used to insert the record?.Also, i’m not using frappe’s rest api. i’m using frappe instance to make custom api like this.

frappe.init(site='erpnext.local')
frappe.connect()

This is interesting, can you tell me more about your use case.

1 Like

i created a custom api like specified in this link : https://discuss.frappe.io/t/serverless-function-using-frappe-framework/75645 and successfully using the frappe instance using the above code. Also, i can create customer entry this way easily. But, not sales order.

I am not sure why you are using this method, but you can ask Revant about it. My experience is limited with that method.

1 Like

seems the implicit frappe.db.commit() not triggered / called at end of request/response session.

standard frappe Post endpoint will auto trigger frappe.db.commit.

1 Like

but, i tried creating customer via another endpoint like this.and it worked without any issue.

Thank you very much for helping. It worked. So, from now on i have to call frappe.db.commit on end of all request i think.