softwerkab / fortnox-csharp-api-sdk

.NET SDK for Fortnox API.
MIT License
53 stars 65 forks source link

Update fortnox rate limits to latest version. #258

Closed itstodSiik closed 2 years ago

itstodSiik commented 2 years ago

Fortnox has changed the way they handle the ratelimits for the API. Suggested changes gets the SDK in line with new standards.

andersjerenvik commented 2 years ago

https://developer.fortnox.se/blog/fortnox-will-raise-its-api-rate-limit-and-make-changes-to-the-current-sliding-window/

richardrandak commented 2 years ago

Seems like the limit change was not yet applied on the server.. I am getting TooManyRequest errors now.

andersjerenvik commented 2 years ago

@richardrandak

The change is applied but the problem is that the ratelimiter doesn't handle the sliding window.

Please change the values to 5 requests per second instead.

richardrandak commented 2 years ago

I made a test to send 100 requests.. it fails even with the rate limiter set to 5 per 1 second. It does not fail with rate limiter set to 4 per 1 second..

andersjerenvik commented 2 years ago

We tried 1 per 0,2 second and that seems to work. Maybe thats the best implementation at the moment?

richardrandak commented 2 years ago

There might be a problem that the existing access tokens has still the old server side rate limit applied. I was trying with the one I am using in the tests and it was failing. So, this is might be true at least for the static auth tokens.

I made a new app and generated the standard auth token and the 5 request / 1 second works fine.

I will have to check with support how this actually work for existing tokens. For back-compatibility, I might have to make the rate limiter configurable.