Refreshing Your Access Token

Refreshing Your Access Token

Refreshing Your Access Token (Automating the Handshake)

An Access Token is like a temporary pass—it expires after one hour. To maintain a continuous connection between your software and Zoho Books without asking the user to log in again, you must use the Refresh Token obtained in Step 3.

At Kalki LLP, we design all our integrations to handle this "silent refresh" in the background, ensuring 24/7 uptime for your financial workflows.


1. The Refresh Token Request (POST)

To get a new Access Token, send a POST request to the Zoho Accounts URL for your region:

Payload Parameters

This request uses the refresh_token grant type. Unlike Step 2, this does not require a browser or user consent.

ParameterValueDescription
refresh_token{your_refresh_token}The permanent token stored in your database.
client_id{your_client_id}Your app's unique ID.
client_secret{your_client_secret}Your app's private secret.
grant_typerefresh_tokenTells Zoho you are renewing an existing session.

2. Understanding the JSON Response

If the refresh is successful, Zoho returns a new access_token. Note that a new refresh_token is not usually returned; you continue using the original one.

JSON
{
"access_token": "1000.new.access.token",
"api_domain": "https://www.zohoapis.in",
"token_type": "Bearer",
"expires_in": 3600
}

3. Implementation Logic for Kalki LLP Developers

We recommend a "Try-Catch-Refresh" logic in your code to handle token expiration gracefully:

  1. Attempt API Call: Use your stored access_token.

  2. Catch Error: If the API returns a 401 Unauthorized or code: 57, it means the token has expired.

  3. Trigger Refresh: Immediately call the Refresh Token endpoint.

  4. Update Storage: Save the new access_token in your database/cache.

  5. Retry API Call: Re-run the original request with the new token.


4. Error Logs & Troubleshooting Step 4

If your refresh request fails, check these specific error logs:

Error LogProbable CauseFix
invalid_tokenThe Refresh Token was revoked or is incorrect.The user may have removed your app's access in their Zoho settings. You must re-authorize (Step 2).
invalid_clientClient ID/Secret mismatch.Ensure you aren't using credentials from a different Zoho environment.
too_many_requestsYou are refreshing too frequently.Only refresh when the expires_in time is nearly up or after receiving a 401 error.
code: 57Calling the wrong Data Center.If your token is for .in, you cannot call .com endpoints.

5. Security Checkpoint: Revoking Tokens

If a project ends or a security breach is suspected, you should revoke the refresh token using the /token/revoke endpoint.

Deluge Tip for Kalki Clients:

When using Zoho Connections in Deluge, Zoho handles Step 4 automatically. You never have to write "refresh" logic if you use the connection parameter in invokeurl. This is why Kalki LLP recommends the "Connections" method for all internal Zoho automations.


Stop Dealing with "Unauthorized" Errors

Does your Zoho integration stop working every hour? The Kalki LLP technical team can implement a robust OAuth manager for your business that handles token rotations and error logging automatically.

    • Related Articles

    • Generating Access and Refresh Tokens

      Generating Access and Refresh Tokens In this step, your server makes a secure back-end request to Zoho's authorization server. Unlike Step 2, this is a POST request that happens entirely behind the scenes—no user interaction is required. At Kalki ...
    • Generating the Grant Token

      Generating the Grant Token (The Authorization Request) Once your application is registered, the next step is to obtain a Grant Token (also known as an Authorization Code). This is a short-lived token (valid for only 1 minute) that you will later ...
    • Zoho Books API v3: Enabling Client Portal Access

      Zoho Books API v3: Enabling Client Portal Access The Enable Portal Access API allows you to programmatically invite your customers to the Zoho Books Client Portal. This action sends an automated invitation email to the primary contact person ...
    • Guide to Zoho Books OAuth 2.0

      The Ultimate Guide to Zoho Books OAuth 2.0: Setup, Scopes, and Troubleshooting Authentication is the foundation of any secure integration. The Zoho Books API v3 uses the OAuth 2.0 protocol to ensure that your financial data is accessed securely ...
    • Zoho Books API: Get an Organization Details

      Zoho Books API: Get an Organization Details The Get an Organization API is used to retrieve the complete profile and configuration settings of a specific organization in Zoho Books. Unlike the "List Organizations" endpoint, this provides granular ...