DEV Community

Nexpro Softwares Private Limited

Syncing a Custom Web App with Zoho CRM over REST: Patterns That Survive Production

Connecting a custom app to Zoho CRM looks easy in a demo: get a token, POST a lead, done. Trouble starts later, when tokens are minted on every request, retries create duplicate leads, and webhooks bounce changes back and forth.

These are the patterns we use when a client's own web app (an admission portal, a booking system, an order form) has to stay in sync with Zoho CRM. Examples use the v8 API and Node 18+ (native fetch), but the ideas apply to any recent version.

1. Treat the access token as a shared, cached resource

Zoho's OAuth tokens have limits that are easy to hit by accident. According to Zoho's token validity docs:

  • An access token is valid for one hour.
  • You can generate at most 10 access tokens from one refresh token in 10 minutes; past that you get an Access Denied error.
  • Only 15 active access tokens are kept per refresh token, and only 20 refresh tokens per user. Generating a 21st silently invalidates the oldest.

So: create the refresh token once (self-client or server-based flow), store it as a secret, and never mint an access token per request. Cache it, and make sure concurrent callers share one in-flight refresh:

const ACCOUNTS = process.env.ZOHO_ACCOUNTS_URL; // e.g. https://accounts.zoho.in for India DC
let cached = null;     // { token, apiDomain, expiresAt }
let inFlight = null;

async function getAccessToken() {
  if (cached && Date.now() < cached.expiresAt - 5 * 60_000) return cached;
  if (inFlight) return inFlight;

  inFlight = (async () => {
    const params = new URLSearchParams({
      refresh_token: process.env.ZOHO_REFRESH_TOKEN,
      client_id: process.env.ZOHO_CLIENT_ID,
      client_secret: process.env.ZOHO_CLIENT_SECRET,
      grant_type: 'refresh_token',
    });
    const res = await fetch(`${ACCOUNTS}/oauth/v2/token`, { method: 'POST', body: params });
    const json = await res.json();
    if (!json.access_token) throw new Error(`Token refresh failed: ${JSON.stringify(json)}`);
    cached = {
      token: json.access_token,
      apiDomain: json.api_domain, // use this, don't hard-code the API host
      expiresAt: Date.now() + json.expires_in * 1000,
    };
    return cached;
  })().finally(() => { inFlight = null; });

  return inFlight;
}
Enter fullscreen mode Exit fullscreen mode

Two details matter here. Use the accounts URL of the data centre the org lives in (.in, .com, .eu and so on), and read api_domain from the token response instead of assuming www.zohoapis.com. If you run several app instances, put the cache in Redis or your database so they don't each refresh independently.

2. Plan for credits and concurrency, not requests per minute

Zoho CRM doesn't limit you per minute. It uses a 24-hour rolling credit budget that depends on edition and user licences, plus concurrency limits per org per app (from 5 on Free to 25 on Ultimate, per the API limits page). Some heavier calls, including insert/update/upsert of more than 10 records, COQL queries and composite requests, also share a sub-concurrency limit of 10. Hitting either limit returns TOO_MANY_REQUESTS.

Practical consequences:

  • Batch writes. Insert/update/upsert accepts up to 100 records per call and costs 1 credit per 10 records, so one 100-record upsert is far cheaper than 100 single calls.
  • Cap your own concurrency below the edition limit, leaving room for other integrations and Deluge functions on the same org.
  • Back off on 429, with jitter, and alert if it keeps happening.
  • Watch the X-API-CREDITS-REMAINING header, which appears once you have used half the daily budget.
async function zoho(path, { method = 'GET', body } = {}, attempt = 0) {
  const { token, apiDomain } = await getAccessToken();
  const res = await fetch(`${apiDomain}/crm/v8${path}`, {
    method,
    headers: { Authorization: `Zoho-oauthtoken ${token}`, 'Content-Type': 'application/json' },
    body: body ? JSON.stringify(body) : undefined,
  });
  if (res.status === 429 && attempt < 5) {
    const wait = 2 ** attempt * 1000 + Math.random() * 500;
    await new Promise(r => setTimeout(r, wait));
    return zoho(path, { method, body }, attempt + 1);
  }
  if (res.status === 204) return null; // e.g. no records found
  return res.json();
}
Enter fullscreen mode Exit fullscreen mode

Note the header format: Zoho-oauthtoken <token>, not Bearer.

3. Make every write idempotent with upsert and your own key

Retries are guaranteed: timeouts, deploys, queue redeliveries. If your sync uses plain insert, every retry risks a duplicate lead. Instead:

  1. Create a custom field in CRM, say App_Lead_ID, and mark it "Do not allow duplicate values".
  2. Always write with the Upsert API, passing that field first in duplicate_check_fields.
async function upsertLeads(rows) {
  const res = await zoho('/Leads/upsert', {
    method: 'POST',
    body: {
      data: rows.map(toZohoLead),
      duplicate_check_fields: ['App_Lead_ID'],
      trigger: [], // skip workflows/approvals/blueprints for sync writes if you don't want them firing
    },
  });
  // Results come back in input order; partial failure returns HTTP 207
  res.data.forEach((r, i) => {
    if (r.status !== 'success') console.error('Upsert failed', rows[i].id, r.code, r.details);
  });
  return res;
}
Enter fullscreen mode Exit fullscreen mode

Because the key is yours, running the same batch twice gives the same CRM state. Store the returned Zoho id against your local row too, so later updates and deletes don't depend on a lookup.

Whether to pass trigger: [] is a business decision. If sales relies on a workflow that assigns owners or sends an alert on new leads, leave triggers on for inserts and think carefully about updates.

4. Keep field mapping explicit and checked

Zoho fields are addressed by API name, which can differ from the label people see. Keep a single mapping function and validate it against the Fields Metadata API at startup or in CI, especially picklists:

function toZohoLead(row) {
  return {
    App_Lead_ID: String(row.id),
    Last_Name: row.lastName || row.fullName,  // Last_Name is mandatory on Leads
    First_Name: row.firstName || undefined,
    Email: row.email || undefined,
    Mobile: row.phone,
    Lead_Source: mapSource(row.utmSource),    // must match an existing picklist value
    City: row.city,
  };
}
Enter fullscreen mode Exit fullscreen mode

When an admin renames a picklist value or adds a mandatory field, you want a failing check, not a quiet stream of INVALID_DATA and MANDATORY_NOT_FOUND errors at 2 a.m.

5. Inbound changes: notifications are a signal, not a payload

For CRM-to-app sync, the Notifications API (POST /crm/v8/actions/watch) lets you subscribe to events like Leads.edit or Deals.all. A few things to design around:

  • The callback contains record ids, the operation, your channel_id and the token you set. Verify both on every call before doing anything.
  • channel_expiry can be at most one week ahead; if you omit it, the default is one hour. Renew it with a scheduled job, and run a periodic catch-up pull (GET records with If-Modified-Since) so gaps during downtime are filled.
  • Respond fast and process in a queue. Fetch the records by ID in the worker.
app.post('/hooks/zoho', express.json(), async (req, res) => {
  const { token, channel_id, ids, operation, module } = req.body;
  if (token !== process.env.ZOHO_WATCH_TOKEN || String(channel_id) !== process.env.ZOHO_CHANNEL_ID) {
    return res.sendStatus(401);
  }
  await queue.add('zoho-sync', { module, operation, ids });
  res.sendStatus(200);
});
Enter fullscreen mode Exit fullscreen mode

6. Break the echo loop

Two-way sync has a classic bug: your app writes to Zoho, Zoho notifies your app, your app writes back, and so on. Simple guards that work:

  • Run the integration as a dedicated CRM user and ignore changes where Modified_By is that user.
  • Or store a hash of the last synced field values on both sides and skip writes when nothing has actually changed.

Wrapping up

Most Zoho integration bugs come from treating it as a one-off script instead of a small distributed system. Cache tokens, respect credits and concurrency, make writes idempotent, keep field mapping explicit, and treat webhooks as hints backed by a periodic reconciliation.

Integrations like this are part of our CRM software development work. Limits can change, so check the current Zoho docs for your API version and data centre.

Written by the engineering team at Nexpro Softwares Private Limited, Rasulgarh, Bhubaneswar.

Top comments (0)