How would I update an existing invoice with an additional line item?
In order to edit the balance of the invoice, we want to be able to append negative line items to the invoice using a webhook.
How would I update an existing invoice with an additional line item?
In order to edit the balance of the invoice, we want to be able to append negative line items to the invoice using a webhook.
Hi,
Thereās an example for clients in the docs but invoices is basically the same. You need to pass in all of the fields so we recommend loading the record, changing it and then submitting it.
These are ALL of the fields that come back on the get request. Most of them donāt have any values in them. Do I need to explicitly assign every single parameter even if it doesnāt have a value? Or are there certain fields that you have to call out?
Id
data
account_key
is_owner
id
amount
balance
client_id
invoice_status_id
updated_at
archived_at
invoice_number
discount
po_number
invoice_date
due_date
terms
public_notes
private_notes
is_deleted
invoice_type_id
is_recurring
frequency_id
start_date
end_date
last_sent_date
recurring_invoice_id
tax_name1
tax_rate1
tax_name2
tax_rate2
is_amount_discount
false
invoice_footer
partial
partial_due_date
has_tasks
auto_bill
auto_bill_id
custom_value1
custom_value2
custom_taxes1
custom_taxes2
has_expenses
quote_invoice_id
custom_text_value1
custom_text_value2
is_quote
is_public
filename
invoice_design_id
account_key
is_owner
product_key
updated_at
archived_at
notes
qty
tax_name1
tax_rate1
tax_name2
tax_rate2
invoice_item_type_id
custom_value1
custom_value2
discount
If itās blank you can probably leave it blank but you may want to test it to confirm
Hi there,
Iāve been at this for a few days now and I just canāt figure out what Iām doing wrong. I run the following code and continue to get a 500 error.
This is me just trying to GET an invoice, and then do a PUT right after without changing anything. I just want to get the request to go through but keep getting a 500 response.
import requests
headers = {"Content-Type": "application/json",'X-Ninja-Token':'[TOKEN]',"Accept": "application/json"}
url = 'https://app.invoiceninja.com/api/v1/invoices/11'
r= requests.get(url,headers=headers)
results = r.json()
put_url = 'https://app.invoiceninja.com/api/v1/invoices'
r= requests.put(put_url,data =results, headers=headers)
final_results = r.json
r
Iāve tried so many variations of this, and always come back to the same error. You said that I have to send back all of the fields to the invoice, which I think Iām doing, but still just getting the error.
Is there any way at all that you can help with this?
Is this possible in Python? Iām not very familiar with CURL but it looks like all the docs seem to explain things with that.
Itās a REST API, you can use any language to access it.
Another option is to use the PHP SDK
Hi there,
Iām still having major issues with this topic.
At this point, I can settle for a simple put request to change the invoice number (so that I can delete and recreate a new invoice with same number)
Can you review my code above and tell me what is wrong with it?
Please check youāre sending back just the invoice not the ādataā index
r= requests.put(put_url,data =results, headers=headers)
Should probably be:
r= requests.put(put_url,data =results['data'], headers=headers)
@zmccarty56, Iām experiencing the same issue.
I can list (GET) and create (POST) invoices but I cannot update (PUT) invoices.
Iām also using python.
Did you get it working and if so do you have a sample bit of code I could look at?
Thanks,
JJ
@wavesailor so I did a bit of a wonky workaround for itā¦
Because I couldnāt figure out how to edit the existing invoice, I instead tried just deleting the invoice and creating a new one with the same number. Since you canāt create duplicate invoice numbers just change the number of the old invoice, delete it, and then recreate a new invoice that is updated
url = https://app.invoiceninja.com/api/v1/invoices/[invoice_id]
headers = {}
headers[Content-Type] = āapplication/jsonā
headers[X-Ninja-Token] = [API Token]
data = {āinvoice_numberā:āDELETE-[Invoice Number]-[Random Number]ā, āinvoice_itemsā:[{āproduct_keyā: āDELETEā,ānotesā: āDELETEā,ācostā: 1,āqtyā: 1}]}
I know this is likely not the solution you were looking for, but itās been working for me!
Thanks @zmccarty56 for your solution
I really would like to just update the invoice via the API if I can. The documentation is so thin.
PS. I see you put ādeleteā numbers in because invoice-ninja only soft deletes the records
Iām fighting with the same issue with invoice ninja 4, I guess I could make ninja 5 work since I can see the requests in the browser and replicate it.
But Iām stuck with ninja 4 because invoice ninja 5 can not print the page number on the pdf and Iāve wasted 2 hours to try to figure out why the put request does not work.
Even if I get the invoice record, and just send it back as is via PUT request I still get a 500 Error
deleting and recreating a new invoice isnāt really a nice solution and I would love to be able to just do a PUT to add a new line item.
@LcX_at @wavesailor Iāve actually figured out how to do this, let me share you.
This is how you need to structure the data
{āclient_idā:ā25ā,āinvoice_numberā:ā5811-Revisedā,āinvoice_dateā:ā2022-02-05ā, ādue_dateā:ā2022-02-20ā,āinvoice_itemsā:[{ānotesā: āblahā, āqtyā: ā1ā, ācostā: ā26ā, āproduct_keyā: āblahā, ācustom_value1ā: ā2022-02-05ā}]}
Headers:
X-Ninja-Token: token
Content-Type: application/json
X-Requested-With: XMLHttpRequest
Supported by Invoice Ninja and Event Schedule