We use a Python script to import (create) invoices. This has worked well for years, but has just started failing with the following error:
Error: 422 Client Error: Unprocessable Entity for url: https://api.freeagent.com/v2/invoices
Have there been changes on the FreeAgent API?
faInvoice = {
"invoice": {
"contact":"https://api.freeagent.com/v2/contacts/" + faContactId,
"dated_on":invoice["date"],
"payment_terms_in_days":int(invoice_due_in_days),
"reference":invoice["invoiceNumber"],
"client_contact_name":invoice["attention"] if "attention" in invoice else None,
"payment_terms":invoice["billingTerms"]["name"],
"comments":"%s" % (faInvoiceComment),
'send_reminder_emails': True,
"payment_methods": {
"gocardless_preauth":True,
"stripe":True
},
"invoice_items":
[
{
"description":invoiceText,
"price":invoice["subtotal"],
"quantity":1,
"sales_tax_rate":20,
"category":nominalCode
}
]
}
}
# Post to FA
print("Posting invoice " + invoice["invoiceNumber"] + " for " + invoice["company"]["name"]+" to FreeAgent...")
try:
response = fa.post("invoices",faInvoice)
except:
print("*FreeAgent-InvoiceSync* could not post invoice to FreeAgent.\n```%s```" % (faInvoice))
raise