'Xero - Creating Multiple invoices via API

In my Laravel/VueJS system I have a routine that i called to create invoices from our system into Xero.

I've a two fold issue, one is that when I have 300+ invoices, I get a 504 timeout error BUT all the invoices seem to transfer and are created.

The second is that I sometimes get a Xero API timeout as I've called it too many times in a 60 second period.

What I do at the moment is:-

Read my invoices
Create a new invoice
Call Xero and find the contacts ContactID from Xero
Pause a second
Add all the data to the new invoice
Save the new invoice to Xero
Wait a second
Repeat until the end

But, is there a way I can do the following:-

Read my invoices
Create a new invoice
Call Xero and find the contacts ContactID from Xero
Pause a second
Add all the data to the new invoice
Wait a second
Repeat until the end
Save all the invoices to Xero

Therefore, is it possible to create a variable called $batchInvoices, store each invoice in that variable, then push $batchInvoices to Xero?

Any help would be gratefully appreciated.

Carl.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source