I have an application that posts invoices to Xero.
In the Xero API spec for invoices it lists Due Date as an 'optional' field - see here: https://developer.xero.com/documentation/api/accounting/invoices
However if I exclude the invoice field from my API JSON Request, I get the following error.
"ValidationErrors": [ { "Message": "Due Date cannot be empty" }
Doesn't appear that the Xero API behaves according to the API spec.
My solution, is to capture and store the payments terms when creating/updating contacts. Here is a sample of the payments terms that are returned when using the Contacts API:
"PaymentTerms": { "Sales": { "Day": 15, "Type": "OFFOLLOWINGMONTH" } }
I will also have to use the Organisation API to return the default PaymentTerms.
I then have to build some logic in my app something to the effect of:
IF MyStoredContact PaymentTerms = BLANK, THEN Use OrgPaymentTerms, ELSE Calculate DueDate from InvoiceDate using Contact PaymentTerms
This is not ideal, as I have to update my database, store additional information, testing etc.
My questions are:
- Is there a better way of doing this?
- If DueDate is a mandatory field in the invoices API, then why does this logic not already exist within Xero?
Any help would be appreciated.
As above, I tried to exclude the DueDate field from my API Request, however I get the following validation error back from Xero API:
"ValidationErrors": [ { "Message": "Due Date cannot be empty" }