Paul Cowan Posted March 13, 2022 Share Posted March 13, 2022 I'm new to the Sage API and I'm trying to create an invoice but I'm getting an error and I don't see how to fix it. The error says "$message: "This field is required", $source: "line_items.tax_rate_id" and "$message: "This field is required.", $source: "line_items.tax.rate". In the API documentation I do not see a "line_items" member - there is "invoice_lines" member. Here is the Json I'm using to create the invoice: {"sales_invoice":{"contact_id":"e69235e7f37e462dbc5e038b57b7d13d","date":"2022-03-13","net_amount":207.60,"tax_amount":26.99,"total_amount":234.59,"invoice_number":"1","tax_address_region_id":"CA-ON","invoice_lines":[{"description":"Test","ledger_account_id":"29fc0490a21411ecbcc60e97dc3b579b","product_id":null,"service_id":"0dc3d4f44f6e421b9e134b9fda48e793","unit_price":173.0,"quantity":1.2,"net_amount":207.60,"tax_amount":26.99,"total_amount":234.59,"tax_rate":{"id":"CA_HST_ON","displayed_as":null}}]}} Any help is appreciated Link to comment Share on other sites More sharing options...
Administrators Ben Smith Posted March 14, 2022 Administrators Share Posted March 14, 2022 Hi Paul, So it looks to me that the only issue is that you are passing the tax_rate_id as an array. When making a POST request, use the attribute tax_rate_id, and pass your string as its value: { "sales_invoice":{ "contact_id":"e69235e7f37e462dbc5e038b57b7d13d", "date":"2022-03-13", "net_amount":207.60, "tax_amount":26.99, "total_amount":234.59, "invoice_number":"1", "tax_address_region_id":"CA-ON", "invoice_lines":[ { "description":"Test", "ledger_account_id":"29fc0490a21411ecbcc60e97dc3b579b", "product_id":null, "service_id":"0dc3d4f44f6e421b9e134b9fda48e793", "unit_price":173.0, "quantity":1.2, "net_amount":207.60, "tax_amount":26.99, "total_amount":234.59, "tax_rate_id":"CA_HST_ON" } ] } } When you view it on the API reference, you can open the arrays such as invoice_lines and see that the tax rate is specified as a tax_rate _id: I'll update our documentation, as that is a required field and not marked as such! My apologies for that. Hope that makes things a bit clearer, Ben Link to comment Share on other sites More sharing options...
Steel, Mark Posted March 14, 2022 Share Posted March 14, 2022 Hi Paul, welcome to the community and thanks for reaching out to us. I can see why the terminology used in the error description could be confusing. When creating a sales or purchase artefact such as a sales_invoice we must send the values of line items in the invoice_lines[] array. This is where the term line_item is created, the wording does not relate directly to the API reference as you have found. You'll need to change the JSON to support the below format. { "sales_invoice": { "contact_id": "e69235e7f37e462dbc5e038b57b7d13d", "date": "2022-03-13", "net_amount": 207.60, "tax_amount": 26.99, "total_amount": 234.59, "invoice_number": "1", "tax_address_region_id": "CA-ON", "invoice_lines": [{ "description": "Test", "ledger_account_id": "29fc0490a21411ecbcc60e97dc3b579b", "product_id": null, "service_id": "0dc3d4f44f6e421b9e134b9fda48e793", "unit_price": 173.0, "quantity": 1.2, "net_amount": 207.60, "tax_amount": 26.99, "total_amount": 234.59, "tax_rate_id": "CA_HST_ON" }] } } Thanks Mark Link to comment Share on other sites More sharing options...
Paul Cowan Posted March 14, 2022 Author Share Posted March 14, 2022 Thanks, that was it, I got it working! 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now