Handle Rate Limits

Read the rate limit headers on each response, tell the spike limit from the hourly limit, and wait the right amount.

Overview

This is sample code, not a supported library. It shows one way to build the pattern, so review, test, and secure it before you use it in production. Procore provides it as is, without warranty or support, and may change it at any time.

Most Procore API responses carry one set of rate limit headers, usually for the 10-second spike limit. The hourly limit typically shows up only once it’s used up. This page shows sample code that reads those headers, works out which limit they describe, and pauses your requests until it resets.

The sample uses fetch and runs in Node.js 18 or later. Adapt it to your own stack. For how limits work, see Rate Limiting.


Tell the Spike and Hourly Limits Apart

The headers don’t say which limit they describe. The time until X-Rate-Limit-Reset does: the spike window is 10 seconds long, so a reset 10 seconds away or less is the spike limit. Anything further out is the hourly limit.

Measure from the response’s Date header, not your server’s clock, so clock drift can’t skew the result.

const SPIKE_WINDOW_SECONDS = 10;

function readRateLimit(response) {
  const remaining = response.headers.get('X-Rate-Limit-Remaining');
  const reset = response.headers.get('X-Rate-Limit-Reset'); // Unix seconds
  if (remaining === null || reset === null) return null;

  const now = Date.parse(response.headers.get('Date')) / 1000 || Date.now() / 1000;
  const secondsToReset = Math.max(0, Number(reset) - now);

  return {
    limit: Number(response.headers.get('X-Rate-Limit-Limit')),
    remaining: Number(remaining),
    secondsToReset,
    window: secondsToReset <= SPIKE_WINDOW_SECONDS ? 'spike' : 'hourly',
  };
}

Some responses, such as a 401, have no rate limit headers, so readRateLimit returns null for them. In the last 10 seconds of an hourly window, it reports the spike limit. That’s harmless, because the right move is the same: wait until the reset.


Wait Before You Retry

Wrap your API calls so every request waits while a limit is spent. Procore doesn’t send a Retry-After header on a 429, so the wrapper waits until X-Rate-Limit-Reset, plus up to a second of random delay so retries don’t all land at once.

let pausedUntil = 0; // Shared by every request that uses the same limit
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

async function procoreFetch(url, options = {}, maxRetries = 3) {
  for (let attempt = 0; ; attempt++) {
    await sleep(Math.max(0, pausedUntil - Date.now()));
    const response = await fetch(url, options);

    // Heavy load: Procore says how long to wait.
    if (response.status === 503 && attempt < maxRetries) {
      await sleep(Number(response.headers.get('Retry-After') || 1) * 1000);
      continue;
    }

    const rateLimit = readRateLimit(response);
    if (response.status === 429 || rateLimit?.remaining === 0) {
      // A 429 without headers: assume the spike window.
      const seconds = rateLimit ? rateLimit.secondsToReset : SPIKE_WINDOW_SECONDS;
      const waitMs = (seconds + Math.random()) * 1000;
      if (pausedUntil <= Date.now()) {
        console.warn(`Procore ${rateLimit?.window ?? 'rate'} limit reached. Pausing ${Math.ceil(waitMs / 1000)}s.`);
      }
      pausedUntil = Math.max(pausedUntil, Date.now() + waitMs);
    }

    if (response.status !== 429 || attempt >= maxRetries) return response;
  }
}

Call it in place of fetch:

const response = await procoreFetch('https://api.procore.com/rest/v1.0/me', {
  headers: { Authorization: `Bearer ${accessToken}` },
});

Keep one pausedUntil for each count Procore keeps for your app: one per user, covering every company they work in, or with Service Account Authentication, one per company. If your app runs several workers, share it through your job queue or a store such as Redis.


Act on Which Limit You Hit

Log the window value. Over time it tells you what to fix.

Limit What it means What to do
Spike Your requests arrive in bursts. Spread them out. Lower concurrency, or queue work and send it at a steady pace.
Hourly Your app used its whole hourly allowance. The headers only show the hourly limit once it’s spent, so the pause lasts until the hour resets. Make fewer calls: use webhooks instead of polling, cache results, and fix failing requests. If you still need more, request a higher limit.

See Also

Was this page helpful? Thanks for your feedback!