it would be pretty unlikely for users to start the api workflow at exactly the same time and get the same invoice number - especially if you are doing invoice numbers per account.

generally I’d also store the invoice number as a number on an “account” data.

ie create invoice for account (user account/company), get accounts invoice number+ 1, update accounts invoice number +1

this achieves a few things
1 - account is known so no need to search for it ie faster response
2 - invoice number is known and not needed to be calculated - faster response
3 - invoice numbers are sequential even if invoices are deleted - standard accounting practice

account in this respect is a users account ie your account at quickbooks.

an account may have multiple users but all the users to the account only see that accounts data/invoices and cannot see other accounts data. the invoice number is also counted per account.

you’re doing
search for all invoices > invoice number >truncated > converted > max + 1

I’d suggest
current users account > invoice number + 1