softwerkab / fortnox-csharp-api-sdk

.NET SDK for Fortnox API.
MIT License
52 stars 64 forks source link

Connection issue when making multiple requests #147

Closed DroPpeLoPpeN closed 3 years ago

DroPpeLoPpeN commented 3 years ago

I am testing my (web)integration on a test account at Fortnox. I create several invoices against the same customer with the same articles and the same price in each invoice. After I've created a couple of invoices, it seems that the connection to Fortnox stops working. The page just keeps on loading and no invoice is created at Fortnox. I get as far as to the InvoiceConnector.Create request, so that's where it stops working. Have you heard of this issue before or do you have a solution?

Have also had the same problem before, when I tried looping through my articles and for each article make a request to Fortnox to see if it existed or create it if it did not exist.

It seems like Fortnox does not allow me to make multiple requests. Do I have to disconnect in any way before making a new request?

richardrandak commented 3 years ago

Hello, are you saying a bunch of invoices are created successfully and then suddenly it stops working? What NuGet version are you using?

DroPpeLoPpeN commented 3 years ago

Yes, not a bunch, but at least 2-3 are created successfully before it stops working. I'm using Fortnox.Net.SDK 4.0.6. Updated from 4.0.5. today. Same issue with both versions.

DroPpeLoPpeN commented 3 years ago

` var createInvoice = new Invoice() { CustomerNumber = invCustomerNumber, InvoiceRows = invoiceRows, OurReference = invOurReference, Remarks = invRemarks }; var invoice = invoiceConnector.Create(createInvoice);

`

I don't think there is much that I could have coded wrong. I've made a list of InvoiceRows which is included when I create my Invoice object, but when I get to the "invoiceConnector.Create" call it stops working.

Could it be because i'm running it on a test account? Or maybe the connection stays open? Is there any way to "disconnect" from Fortnox after my invoice is created?

richardrandak commented 3 years ago

By test account you mean a sandbox? It should have no impact. The rate limit is also handled by SDK.

There was an issue reported several times about the program getting stack at the requests. It was due to using awaiters internally. If it is not much work for you, could you try using the async method? var invoice = await invoiceConnector.CreateAsync(createInvoice);

DroPpeLoPpeN commented 3 years ago

I've now tried CreateAsync, but same result. Able to create 2-3 invoices, but then stops working until I restart my web server.

richardrandak commented 3 years ago

Well.. the rate limiter is set to 4 requests per second per access token, then it "cools down". But no idea why that would be an issue. Could you, by any chance share your code? (without the credentials of course, I will use my sandbox) You could send it to me by mail -> richard.randak@softwerk.se

DroPpeLoPpeN commented 3 years ago

Ok, then maybe I run too many requests. I start by checking if the company exists, otherwise I create it. Then the same with the articles to be included in the invoice. Finally, I create the invoice. I'll split it up and see if it helps.

richardrandak commented 3 years ago

It is a long-shot, but can you try https://www.nuget.org/packages/Fortnox.NET.SDK/4.0.7-preview ?