Closed saboter closed 3 years ago
Hey @saboter - Instead of having 2 functions createInvoice
and createInvoices
we opted to err on the side of bulk optionality to every endpoint, as that is the nature of what the Xero API supports for all endpoints.
https://xeroapi.github.io/xero-ruby/accounting/index.html#api-Accounting-createInvoices
It does create a bit more verbosity in how you structure calls, it lends itself to the pattern of how the API was created a bit more accurately.
invoices = {
invoices: [invoice]
}
Sorry I re-read the question and missed a piece. Some endpoints will accept a single object, or an array of objects, such as POST invoice.
However to your point, I tested in our sample rails app the update_or_create_invoices
method with an array of invoices and that worked okay. If you check the history tab in your API dashboard you should be able to see if the API Invoice POST payload looks as expected as well.
def invoices_create
trackingcategories = xero_client.accounting_api.get_tracking_categories(current_user.active_tenant_id).tracking_categories
category = trackingcategories.first
account = xero_client.accounting_api.get_accounts(current_user.active_tenant_id).accounts.sample
account_code = account.code
contacts = xero_client.accounting_api.get_contacts(current_user.active_tenant_id).contacts
invoices = {
invoices: [
{
type: XeroRuby::Accounting::Invoice::ACCREC,
contact: {
ContactId: contacts.sample.contact_id
},
LineItems: [
{
description: "Acme Tires Desc",
quantity: 32.0,
unit_amount: BigDecimal("20.99"),
account_code: account_code,
tax_type: XeroRuby::Accounting::TaxType::NONE,
tracking: [
{
tracking_category_id: category.tracking_category_id,
name: category.name,
option: category.options.sample.name
}
]
}
],
date: "2019-03-11",
due_date: "2018-12-10",
reference: "Website Design",
status: XeroRuby::Accounting::Invoice::DRAFT
}
]
}
@invoices = xero_client.accounting_api.update_or_create_invoices(current_user.active_tenant_id, invoices).invoices
end
Thank you very much for explanation @SerKnight .
My problem was that I did not used this format (just array was on input):
invoices = {
invoices: [invoice]
}
Hi,
just wondering if is there some specific reason why there is "plural" naming for some methods which indicates that there should/could be array of objects on input.
Example (https://github.com/XeroAPI/xero-ruby/blob/master/lib/xero-ruby/api/accounting_api.rb#L17040):
create_invoices method accepts invoices array, but update_or_create_invoices fails with:
No data has been processed for this endpoint. This endpoint is expecting Invoice data to be specifed in the request body.
It works if single invoice model object is used on input.
Thanks