# Asynchronous invoice creation exposes a FreeAgent API bug

**URL:** <https://api-discuss.freeagent.com/t/asynchronous-invoice-creation-exposes-a-freeagent-api-bug/844>\
**Category:** Uncategorized\
**Created:** [27 October 2017 10:31 UTC](https://api-discuss.freeagent.com/t/asynchronous-invoice-creation-exposes-a-freeagent-api-bug/844 "2017-10-27T10:31:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![gregharvey](https://api-discuss.freeagent.com/user_avatar/api-discuss.freeagent.com/gregharvey/32/156_2.png) [@gregharvey](https://api-discuss.freeagent.com/u/gregharvey)\
**Post date:** [27 October 2017 10:31 UTC](https://api-discuss.freeagent.com/t/asynchronous-invoice-creation-exposes-a-freeagent-api-bug/844/1 "2017-10-27T10:31:20Z")

</div>

Hi,

I made a node app (here, if you’re interested - [https://github.com/codeenigma/billder](https://github.com/codeenigma/billder)) to create invoices based on customer AWS usage. I have one small problem. Sometimes, because node is asynchronous, it creates two invoices at almost the same time. While the invoice ID safely auto-increments, the invoice title (e.g. “Invoice 002”) does not always. It’s possible to get two or three invoices created with the same title number. Take a look:

 ![](https://freeagent-api-discuss-assets-production.s3.dualstack.eu-west-1.amazonaws.com/original/1X/7ec69c61772aa11240b9bed9beb62c2d30eb2dcf.png)

For now I’ll fix this by putting a random timer in to dramatically reduce the chances of two invoice creations happening in the same second.

Thanks,

Greg
