Home / Token Setup / Zoho
Token Setup: Zoho
Zoho Mail through TokenBroker. Completed 2026-11-28; accounts and search verified end to end the same day.
Zoho facts that shape the setup
- Access tokens expire after 1 hour.
- A refresh token can mint at most 10 access tokens per 10 minutes; the function caches and refreshes 5 minutes early to stay well under this.
- Refresh tokens do not expire on a schedule; they die only if revoked or if the client is deleted. Zoho allows up to 20 refresh tokens per client; each bootstrap adds one, so clean up old ones if bootstraps pile up.
- API calls carry the header
Authorization: Zoho-oauthtoken <token>. - Accounts host:
https://accounts.zoho.com. Mail host:https://mail.zoho.com.
The client
A dedicated Self Client in the Zoho API Console (https://api-console.zoho.com), created for TokenBroker alone. Do not reuse the server-based client that belongs to the Muse Zoho connector; that client and its secret stay untouched.
Scopes (exactly these six):
ZohoMail.accounts.READ,ZohoMail.messages.READ,ZohoMail.messages.CREATE,ZohoMail.messages.DELETE,ZohoMail.messages.UPDATE,ZohoMail.folders.READ
Vault secrets
In kv-tokenbroker-example, names exactly:
| Secret | What it is |
|---|---|
zoho-client-id |
Self Client id |
zoho-client-secret |
Self Client secret (typed into the portal by the owner, never in chat) |
zoho-refresh-token |
Written by the exchange script during bootstrap |
Configuration (in appsettings.json, not app settings):
Providers:Zoho:AccountsBase = https://accounts.zoho.com,
Providers:Zoho:MailBase = https://mail.zoho.com, plus
KeyVaultUri in the gitignored appsettings.Local.json pointing at
the vault.
Bootstrap steps (the one-time ceremony)
Part A and B are done once. Part C is repeated only if the refresh token is ever lost or revoked.
Part A: the Self Client. In the API Console, open (or create) the TokenBroker Self Client and note its Client ID and Client Secret.
Part B: id and secret into the vault. Azure portal, vault
kv-tokenbroker-example, Objects, Secrets, Generate/Import, manual:
create zoho-client-id and zoho-client-secret with the values from
Part A.
Part C: the grant code. In the Self Client, Generate Code tab: paste the six-scope line above, choose the longest duration (10 minutes), description "TokenBroker bootstrap", Create. The code is single-use and expires in minutes: pass it to the exchange step immediately.
Exchange. Run an exchange script (a small shell script kept with
the operator's tooling, not in this repo) with the grant code. The
script reads the id and secret from the vault (printing only their
lengths), posts grant_type=authorization_code to
https://accounts.zoho.com/oauth/v2/token, and on success stores the
refresh token as zoho-refresh-token. It prints no token values.
Endpoints the function exposes
All require the x-functions-key header.
| Route | Proxies to |
|---|---|
GET /api/zoho/mail/accounts |
Zoho mail accounts list |
GET /api/zoho/mail/search?accountId=..&q=..&limit=.. |
Zoho message search |
GET /api/zoho/mail/read?accountId=..&folderId=..&messageId=.. |
One message |
POST /api/zoho/mail/send (JSON: accountId, fromAddress, toAddress, subject, content) |
Zoho send |
Routes were originally /api/mail/*; they were namespaced per
provider in the 2026-11-28 refactor, before any caller depended on
them.
Verification (2026-11-28)
- GET accounts returned HTTP 200 and the account (with its four mail
addresses), first on the original
/api/mail/accountsroute, then again after the refactor on/api/zoho/mail/accounts. - A search call returned HTTP 200 with real messages, both times.
- Without the function key the same URL returns 401, as expected.
After the refactor the old
/api/mail/*routes return 404.
Troubleshooting
- 401 INVALID_OAUTHTOKEN from Zoho directly: an expired access token being used without refresh. That is the failure TokenBroker exists to absorb; if it appears through the function, check the function logs and confirm the vault secrets are present and enabled.
- First bootstrap attempt (2026-11-28): the exchange succeeded but
az keyvault secret setfailed with HTTP 411 (Length Required) through the VM's egress proxy, and the refresh token was lost with the failed process. The exchange script now stores the secret through the vault REST API with curl (which sets Content-Length). Lesson: pre-test the vault write path with a dummy secret before spending a grant code. - Function key lookup: on Flex Consumption,
az functionapp keys listreturns the key underfunctionKeys.default, nothostKeys.default. - Cold start: the first call after idle can take some seconds on Flex Consumption. Retry once before treating a timeout as a failure.