Jump to content

Error when creating a bill via API


 Share

Recommended Posts

Im getting the next error when I try to create a bill:

 

 

{'message':'Request failed with status code 500','name':'AxiosError','config':{'transitional':{'silentJSONParsing':true,'forcedJSONParsing':true,'clarifyTimeoutError':false},'transformRequest':[null],'transformResponse':[null],'timeout':0,'xsrfCookieName':'XSRF-TOKEN','xsrfHeaderName':'X-XSRF-TOKEN','maxContentLength':-1,'maxBodyLength':-1,'env':{},'headers':{'Accept':'application/json, text/plain, */*','Content-Type':'application/json','authorization':'Bearer eyJhbGciOiJSUzUxMiIsImtpZCI6IjFQWGpwTC05TWdXM0k0MkxITzhLdzYxN3RWUXdLTkRNQUNiQXRoSGtDRmc9In0.eyJqdGkiOiIxMzE2YmI2Yi03YWQ5LTRmZDUtYWU4MC05MGI0NzEzMGY1MWIiLCJpYXQiOjE2ODE4ODk0NjgsImV4cCI6MTY4MTg4OTc2OCwiaXNzIjoib2F1dGguYXdzLnNiYy1hY2NvdW50aW5nLnNhZ2UuY29tIiwic3ViIjoiZGQyZGUwZDYtOTcxZi1iNWQ2LTBhM2EtM2E3Y2Y3YzE4NDY1IiwiYXVkIjoiYXBpLnNiYy1hY2NvdW50aW5nLnNhZ2UuY29tIiwiYXpwIjoiNTdlMTgwOWYtNTM1NS00MGQ5LTg2N2YtNWE2NjI3ZWVhODQ4LzM0NDFiNDdjLWE2NDAtNDQxNi04MGE1LTc5ZTFiZjdlMmE4ZCIsImNvdW50cnkiOiJDQSIsInNjb3BlcyI6ImFjY291bnRpbmc6cncgY29yZTpydyIsInVzYWdlX3BsYW5fY29kZSI6ImV4dGVybmFsIn0.CxFVgS-suJRUkcTSiAJHRMYR7Pvr8cfRtGLvXnc7RYqP_N6F0ZyAT8kJ3xiGPriQ_Jwjw3hadfyWeUVXmzu2TtfLye5MfDEMqxhIHwV7-O9J5N9K84YgUvlX6ChkvzFTAKEoRupSGNIkt2-FUqNWf1ggMNfZQ8kaXw6TtxEZZiPq6Xn0sUMh45ALqddlcFeFQWIpEvuu0pWwhUHZqlwv65CZZV_isI8v93CV7d08zyA6ew95ScX9AjoxAuOVVonZTLahdRAhSu17hkVptCjGo7ByG4HWkYQT1uTAA2cjbUpNc7pNYhFE_SJ3ZLUwaUct0Sv-60WQP80D3feaknXqLboM7xDuaNrwh0vi6VFnVwWVSKW3rtPx-pNvypDIx3IzY9LP9JuvVdBln4ZPJgduz69umS-pNkleCvXk8Fg1tTmW3cY2_uXqYE3T5b_f6ZwSTxV5s5pCCuw3dMZXomXfvDdT4JOji48-5DicCsK6arR8qY_LKEjjEaLf2ITnXITDS0JTQntL3EWPAYNxRT8TqSaQSXKsPmHOmKAz_iY5arKHT6AxyHQoZLC6uSeXIknz-63SK5ZrPCFdY8KLeIYERXf2Ewe9IiSH8NKu_u9Qb1D_RfF8hNJA6TAMH0VrNoH61FOLXC-BVYn5pXxL3ql-Lsu6H-JIMS0tra_HuLQsqec','User-Agent':'axios/0.27.2','Content-Length':372},'url':'https://api.accounting.sage.com/v3.1/purchase_invoices','method':'post','data':'{\'purchase_invoice\':{\'due_date\':\'2024-04-19\',\'date\':\'2023-04-19\',\'contact_id\':\'5240dc26e0714437b797a9b083f32254\',\'exchange_rate\':\'1\',\'invoice_lines\':[{\'description\':\'cf85707a-5081-4251-ba0d-c96d142ff717\',\'unit_price\':125,\'quantity\':329,\'currency_tax_amount\':3.99,\'total_amount\':41125,\'ledger_account_id\':\'b4e9d889381d11ecbcc60e97dc3b579b\',\'tax_rate_id\':\'CA_GST_PST_BC\'}]}}'},'code':'ERR_BAD_RESPONSE','status':500}
 
 
 
The payload we are using is:
{
    "purchase_invoice": [
        {
            "due_date": "2024-04-19",
            "date": "2023-04-19",
            "contact_id": "9bb46a4136e64b36819f34f6a7f75952",
            "exchange_rate": "1",
            "invoice_lines": [
                {
                    "description": "cf85707a-5081-4251-ba0d-c96d142ff717",
                    "unit_price": 125,
                    "quantity": 329,
                    "currency_tax_amount": 3.99,
                    "total_amount": 41125,
                    "ledger_account_id": "b4e9d889381d11ecbcc60e97dc3b579b",
                    "tax_rate_id": "CA_GST_PST_BC"
                }
            ]
        }
    ]
}
 
 
 
Any idea?
 
Link to comment
Share on other sites

You would only need to pass an exchange_rate when using a currency_id different to the base currency of the business and you would never be setting the currency_tax_amount in the invoice_line only the tax_amount. It also looks as if you're trying to pass the tax_rate_id of a sales tax_rate and not that of a purchase.

To obtain a list of valid tax rates you can query the tax_rates API using the usage query paramater - tax_rates?usage=purchase&address_region_id=CA-BC. The address_region_id should be that of the registered business for purchases and the address_region_id for sales needs to be that of the customer.

{
    "purchase_invoice": {
        "contact_id": "9bb46a4136e64b36819f34f6a7f75952",
        "date": "2023-04-20",
        "due_date": "2023-05-20",
        "reference": "Internal Reference",
        "vendor_reference": "Vendor reference",
        "invoice_lines": [
            {
                    "description": "cf85707a-5081-4251-ba0d-c96d142ff717",
                    "unit_price": 125,
                    "quantity": 329,
                    "tax_amount": 4935,
                    "ledger_account_id": "b4e9d889381d11ecbcc60e97dc3b579b",
                    "tax_rate_id": "CA_GST_PST_BC"
            }  
        ]   
    }
}

Thanks

Mark

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...