Sub topic 3
The daily API request limit
This chapter assumes you can make authenticated HTTP requests to a REST API and have a working access token and instance URL for a Salesforce org. It builds on the previous chapters' overview of limit categories.
What the limit measures
The daily API request limit caps the total number of API calls your org can make in a rolling 24-hour period. Salesforce exposes it as DailyApiRequests.
"Rolling" matters. The counter does not reset at midnight. Each call counts against the org for 24 hours after it was made. If you spend 10,000 calls at 14:00, that capacity returns gradually starting at 14:00 the next day.
The limit belongs to the whole org, not to a user or an integration. A busy nightly sync, a third-party app, and a developer's script all draw from the same pool.
How the maximum is set
The maximum depends on your edition and your purchased user licenses. Larger editions and more licenses raise it, and you can buy add-on capacity. Developer Edition orgs and sandboxes have lower allowances than production orgs. Do not hardcode a number. Read the actual maximum from the org, as shown below.
What counts
Calls through the main APIs count, including REST, SOAP, and Bulk API requests. Bulk API counts by batch rather than by record, which is one reason bulk operations save capacity. Calls made from inside Apex to other Salesforce APIs also count if they go through an API endpoint.
Check the current Salesforce documentation for the exact list of exclusions. Do not assume a call is free because it feels internal.
Reading the remaining capacity
The Limits resource returns the maximum and remaining value for each limit:
curl -s -H "Authorization: Bearer $ACCESS_TOKEN" \
"$INSTANCE_URL/services/data/v60.0/limits"
# The response is a JSON object keyed by limit name. For example:
# { "DailyApiRequests": { "Max": 15000, "Remaining": 14980 }, ... }The next script turns that into a percentage. It also reads the Sforce-Limit-Info header, which comes back on API responses and reports usage without an extra call:
import os
import requests
instance_url = os.environ["INSTANCE_URL"]
token = os.environ["ACCESS_TOKEN"]
resp = requests.get(
f"{instance_url}/services/data/v60.0/limits",
headers={"Authorization": f"Bearer {token}"},
timeout=30,
)
resp.raise_for_status()
daily = resp.json()["DailyApiRequests"]
used = daily["Max"] - daily["Remaining"]
percent = 100 * used / daily["Max"]
print(f"Daily API requests used: {used}/{daily['Max']} ({percent:.1f}%)")
# Every API response also carries the usage header, e.g. "api-usage=25/15000"
header = resp.headers.get("Sforce-Limit-Info", "")
if "api-usage=" in header:
current, maximum = header.split("api-usage=")[1].split("/")[:2]
print(f"From header: {current} of {maximum}")How a call is counted
When the limit is reached
Once the org is over its allowance, API calls fail with the error code REQUEST_LIMIT_EXCEEDED. This affects every integration in the org at once. A runaway script can therefore take down an unrelated, business-critical sync. Production orgs may get some leeway before hard blocking, but treat the maximum as a hard ceiling when you plan.
Common mistakes
- Assuming the counter resets at midnight. It is a rolling window, so recovery is gradual.
- Checking only one integration's usage. The limit is org-wide.
- Calling the Limits resource in a tight loop.
- Hardcoding the maximum instead of reading
Maxfrom the response. - Using one API call per record when a bulk or composite request would do.
Exercise
Your script reads DailyApiRequests and gets Max 100000 and Remaining 25000. What percentage has been used? Also, at 09:00 you stop all traffic. Will Remaining return to 100000 at midnight?
Show answer
Used is 75000, which is 75.0%. Remaining will not jump back at midnight. The window is a rolling 24 hours, so each call stops counting 24 hours after it was made, and capacity returns gradually as old calls age out.