API: tax for invoice instead of item?

Hi,

I know that I can set the tax name and value for invoice items in the json call, for example:
{“client_id”:2,“invoice_items”:[{“qty”:1,“tax_name1”:“USt.”,“tax_rate1”:“16%”,“notes”:“Renew domain.com”,“product_key”:“DE-DOMAIN”}],“email_invoice”:0}

In the invoices, I see that there is alternatively the option to set the tax rate on the whole invoice instead of every single item. Setting tax_name1 and tax_rate1 next to the client_id doesn’t work.

Since I’m unable to find a complete API documentation, how can I archive to set the tax to the invoice instead of every single item?

This would help a lot since it seems the only way to work around the tax rounding errors of Invoice Ninja.

Have you enabled invoice taxes on Settings > Tax Rates?

Yep

So, when creating invoices in the frontend, I can select tax for the invoice instead of every single item.
Problem is, that I don’t know how to do the same when using the JSON API.
When I’m setting the tax_rate1 in the invoice_items array, it works, but with the problem that rounding errors occur because tax is added to every item, then rounded, then summarized.
When I omit the tax_rate1 in the items, no tax is added at all. So I assume I have somehow to add the tax_rate1 to the invoice itself, but I can’t find out, how exactly to do this.

I’m not sure, you should just need to set tax_rate1/tax_name1 on the invoice rather than the item

I wouldn’t ask if I wouldn’t have tried that already :slight_smile:

Tried my test submit:
{“tax_name1”:“USt.”,“invoice_items”:[{“notes”:“Renew domain.com [Reg.: 2009-07-24]”,“product_key”:“DE-DNS”,“qty”:1}],“email_invoice”:0,“client_id”:2,“tax_rate1”:“16%”}
Invoices successfully generated: 0
Error sending items, API returned: 500 Internal Server Error

Did ‘16%’ work as a line item rate? I assume it needs to be ‘16’.

Also what causes the 500 error, is it just by adding the two tax fields?

Yep, “16%” for tax_rate1 works fine with JSON API. Shouldn’t a developer know this? :slight_smile:

And the 500 error comes when I add tax_rate1 and tax_name1 to the invoice object instead to the invoice_items object.

Can you check for details about the error in the logs in storage/logs/laravel-error.log

Unfortunately, there is no error message for this in the mentioned log (and none in the other ones).

But, based on your “you sure that it’s 16% instead of 16” statement I tried with setting this without the percent sign, and that works.

So: setting tax_rate1 to 16% works for some reason within invoice_items, but not within invoice. Good to know.

I try to rebuild my item collection framework to use invoice tax instead of item tax, perhaps that solves some of my many invoice ninja headaches.

Nice, progress…

Thanks for the update!

This would help a lot since it seems the only way to work around the tax rounding errors of Invoice Ninja.

FWIW, you’re probably not going to be able to use the tax numbers from IN anyway.

In NY, the state calculates “what you owe” based on total sales for the period, not the total of what you collected on each invoice.

Because each sale almost certainly rounds up or down a little, if you add up the tax from each invoice, it’s probably not going to to match what the state wants, which is based on total sales.

I ended up writing a SQL Query that I run at sales-tax time.

So, as expected, now I got problems with my tax accountant.
As already stated, I can use “tax on summary instead of single items” on invoices generated via API call, but unfortunately this doesn’t work with recurring invoices.
Now I have hundreds of recurring invoices where tax is calculated per-item, rounded, and then summarized, which means that most of them are calculated wrong.
Is there any way how to fix that?
And why doesn’t this bother anyone else?

Well, I’m in Germany - I get grey hair from Invoice Ninja because lots of german special cases simply can’t be realized with this software.

It doesn’t bother me because the error is very small.