# Rate limits

Turn on QuickBooks Online's per-realm request limits, so a request past a limit returns QuickBooks' 429 throttle fault.

Test how your integration backs off when QuickBooks throttles a company's requests. With [`rate_limits: real`](https://www.rystic.ai/docs/network-profiles.md) on, the simulator applies the limits [Rate limits](https://www.rystic.ai/docs/simulators/quickbooks.md#rate-limits) lists. Each realm keeps its own allowance, and each limit's window opens at its first request. Control routes such as `/_rystic/network` count toward neither.

With the limits off, the default, 12 reads in one second all return 200. Wait out that second and turn the limits on. Then send 11 reads to one realm, a 12th whose body you keep and a read of another realm, all in one second over one connection. Last, reset and create a customer:

```bash
R=4620816365320737870
URL="$RYSTIC_URL/v3/company/$R/customer/1"
OTHER="$RYSTIC_URL/v3/company/9341452000000001/companyinfo/9341452000000001"
BODY=$(mktemp); HEADERS=$(mktemp)
curl -s -H 'Authorization: Bearer placeholder' -w '%{http_code}\n' $(for i in $(seq 12); do echo "-o /dev/null $URL"; done) | sort | uniq -c | awk '{print $2, $1}'
# -> 200 12
sleep 1
curl -s -X POST "$RYSTIC_URL/_rystic/network" -o /dev/null -w '%{http_code}\n' -d '{"rate_limits": "real"}'
# -> 204
curl -s -H 'Authorization: Bearer placeholder' -D "$HEADERS" -w '%{http_code}\n' $(for i in $(seq 11); do echo "-o /dev/null $URL"; done) -o "$BODY" "$URL" -o /dev/null "$OTHER" | sort | uniq -c | awk '{print $2, $1}'
# -> 200 10
# -> 403 1
# -> 429 2
jq -c '{type: .Fault.type, code: .Fault.Error[0].code, Message: .Fault.Error[0].Message}' "$BODY"
# -> {"type":"SERVICE","code":"3001","Message":"message=ThrottleExceeded; errorCode=003001; statusCode=429"}
awk 'tolower($0) ~ /^retry-after:/ {n++} END {print n+0}' "$HEADERS"
# -> 0
curl -s -X POST "$RYSTIC_URL/_rystic/reset" -o /dev/null -w '%{http_code}\n'
# -> 204
curl -s "$RYSTIC_URL/_rystic/network" | jq -r .rate_limits
# -> real
curl -s -H 'Authorization: Bearer placeholder' -H 'Content-Type: application/json' "$RYSTIC_URL/v3/company/$R/customer" -d '{"DisplayName":"Maple Cafe"}' | jq -c '.Customer | {Id, DisplayName}'
# -> {"Id":"1","DisplayName":"Maple Cafe"}
```

The other realm's read was not throttled: it returned the 403 a realm with no company returns. A refused request returns a fault whose `Fault.type` is `SERVICE` and whose code is `3001`, with no `Retry-After` header. A reset empties the company and restores every allowance while the setting stays on.

---

Source: https://www.rystic.ai/docs/simulators/quickbooks/features/rate-limits · Markdown: https://www.rystic.ai/docs/simulators/quickbooks/features/rate-limits.md
