XeroAPI/xero-ruby

Insufficient data returned from create_invoices when 1 or more invoices fail validation

cameronbourgeois opened this issue · 1 comments

accounting_api.create_invoices fails to return data regarding any successful invoices when 1 or more of the invoices within the same payload fail validation.

My code:

invoice_params = {
  invoices: [
    { reference: '001', ...some valid params... }
    { reference: '002', ...some invalid params... }
  ]
}

begin
  api_response = xero_client.accounting_api.create_invoices(stored_tenant_id, invoice_params, unitdp: 4)
rescue XeroRuby::ApiError => e
  error_response = JSON.parse(e.message.split('Response body: ')[1])
end

# error_response => contains data only about failed invoice ref 002
# api_response => is nil

The result of the above code is that error_response contains data pertaining only to the failed invoice with ref 002.
The invoice with ref 001 has been successfully created in Xero, but api_response is nil so I immediately lose track of the invoice that was created.

Note that the validation error that is triggering the XeroRuby::ApiError is an invalid item_code: "Item code 'X' is not valid".

Wow, ok, so I need to add summarize_errors: false to my call, like so:

api_response = xero_client.accounting_api.create_invoices(stored_tenant_id, invoice_params, unitdp: 4, summarize_errors: false)

Now the XeroRuby::ApiError is not raised, and the api_response does contain the successful invoices as expected.