XeroAPI / xero-ruby

Xero Ruby SDK for OAuth 2.0 generated from XeroAPI/Xero-OpenAPI
http://developer.xero.com/
MIT License
58 stars 91 forks source link

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

Closed cameronbourgeois closed 1 year ago

cameronbourgeois commented 1 year ago

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".

cameronbourgeois commented 1 year ago

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.