Getting Server Error while creating Invoices through the API

Hello all,
I am having a weird problem for more than a month now. First of all let me tell you my scenario, I have an external payment provider that charges my customers on a recurring basis, and whenever the payment in the third party provider is done it sends a webhook request to my application. In my application’s webhook handler it automatically creates an invoice for each payment through the Invoice Ninja API and it has been working great.
The only problem is that sometimes some invoices don’t get created at all and when I look in my application logs I see that the endpoint “https://invoicing.co/api/v1/invoices/” returned “message”: “Server Error”.

literally from around 10 invoices it happens randomly to one or two of them and always a different invoice or a different client. so it can’t be a permission problem because most invoices work except one or two. and the invoice which returned an error during creation I can still see it in the UI as a “Pending” invoice which doesn’t have a number

I have tried everything to debug this problem but I can’t debug it since it’s initiated from a webhook to my server and everytime I do it manually all the invoices get created normally!

do you have any info on this? thank you

Hi,

@david do you have any ideas to debug?

Here is a screenshot, all invoices got created successfully except two

@had

How fast as you sending requests in to the server? You may be hitting a rate limiter if you are sending requests in too fast.

Hello David
thanks for your reply. probably too fast because the webhook gets fired almost instantly for every recurring payment we receive. and for every payment I send 2 requests
1- to create the invoice
2- to mark the invoice as paid, since I found no way of doing that in the create invoice request and have to issue a separate request for that -would also appreciate your help on this side problem-

how many requests can I send to the server per which unit of time, If I know this information I might be able to slow it down a little bit by adding a queue or something but first I need to know the rate with which I am allowed to communicate with the server.

Thank you

so i think the solution here is when you create the invoice, just pass the query parameter ?mark_paid=true

that will save you the additional request.

this should resolve the issue.

If you can also insert some delay into your requests this will improve your chance of not being rate limited…

hi David,
I tried passing the query parameter but it get’s completely disregarded and the invoice doesn’t get marked as paid!
I have been having this problem for a while, since we only create invoices if the payment is confirmed so we always want to create the invoice as paid and I have tried it through the API and it always doesn’t work.
The only way I got it to work is using the endpoint "/api/v1/invoices/bulk" and passing the invoice id and the action “mark_paid”
if you have any other suggestion it would be very appreciated since it’s already a pain in the neck for us.

Also, I don’t think the rate is the problem since sometimes the first request is the one creating a problem and sometimes more than 5 invoices are created in the same split second with no problem.

this issue is driving me crazy! and I can’t publish our new version without making sure that every invoice that would be sent to our customers is ready otherwise it will be a problem for us.

@had

Send us an email to contact@invoiceninja.com from the email address you use to log into invoiceninja, we’ll try and see if there is something in the logs that could explain this.