Your Image Alt Text
Jazzed Technology Blog

How to Authenticate with Zoho Desk API Using OAuth for a Next.js App

🔐 How to Authenticate with Zoho Desk API Using OAuth for a Next.js App

By Jazzed Technology

Integrating Zoho Desk into your Next.js application can unlock powerful support features — from ticket automation to real-time contact management. But like many OAuth-based APIs, the initial setup can be a bit tricky, especially when it comes to getting the scopes right.

In this post, we’ll walk you through how to generate and configure the following values for your .env file:

ZOHO_CLIENT_ID=
ZOHO_CLIENT_SECRET=
ZOHO_REFRESH_TOKEN=
ZOHO_API_BASE_URL=https://desk.zoho.com
ZOHO_ORG_ID=
ZOHO_DEPARTMENT_ID=
ZOHO_DEFAULT_CONTACT_ID=
ZOHO_DEFAULT_PRODUCT_ID=
ZOHO_ACCOUNTS_URL=https://accounts.zoho.com
ZOHO_REDIRECT_URI=https://jazzgrewal.com
ZOHO_SCOPES=Desk.tickets.ALL,Desk.contacts.ALL,Desk.settings.READ,Desk.basic.READ,aaaserver.profile.READ

🧱 Step 1: Create a Zoho Self Client

  1. Go to the Zoho API Console.
  2. Click Add Client → Select Self Client.
  3. Fill in the following:
    • Client Name: (e.g., JazzGrewal Desk Integration)
    • Client Domain: https://jazzgrewal.com
    • Redirect URI: https://jazzgrewal.com
  4. Click Create.
  5. You’ll receive your ZOHO_CLIENT_ID and ZOHO_CLIENT_SECRET.

🧾 Step 2: Generate a Grant Token

  1. Within your Self Client, click Generate Code.

  2. Use the following scopes (these are accurate for Zoho Desk):

    Desk.tickets.ALL,Desk.contacts.ALL,Desk.settings.READ,Desk.basic.READ,aaaserver.profile.READ
    

    ❗ Common Mistake: Avoid using outdated scopes like ZohoDesk.tickets.ALL — these will throw an “invalid scopes” error.

  3. Once generated, copy the one-time-use grant token.


🔄 Step 3: Exchange Grant Token for Refresh Token

Send this POST request using curl, Postman, or in code:

POST https://accounts.zoho.com/oauth/v2/token
Content-Type: application/x-www-form-urlencoded

client_id=YOUR_CLIENT_ID
&client_secret=YOUR_CLIENT_SECRET
&grant_type=authorization_code
&code=YOUR_GRANT_TOKEN
&redirect_uri=https://jazzgrewal.com

✅ If successful, you’ll receive:

{
  "access_token": "1000.xxxxx",
  "refresh_token": "1000.xxxxx",
  "expires_in": 3600,
  "token_type": "Bearer"
}

Store the refresh_token securely — this allows your Next.js backend to generate new access tokens programmatically.


🔎 Step 4: Fill in Remaining Values

Use your access token to fetch these:

Organization ID

GET https://desk.zoho.com/api/v1/organizations
Authorization: Zoho-oauthtoken ACCESS_TOKEN

Department ID

GET https://desk.zoho.com/api/v1/departments
Authorization: Zoho-oauthtoken ACCESS_TOKEN

Default Contact/Product IDs

These are up to your app logic — you can either create them manually or list them:

GET https://desk.zoho.com/api/v1/contacts
GET https://desk.zoho.com/api/v1/products

🛠 Sample Axios Requests

Here's how you can make authorized requests to the Zoho Desk API using Axios in a Next.js app:

POST Request Example: Create a Ticket

import axios from "axios";

const createTicket = async () => {
  const response = await axios.post(
    "https://desk.zoho.com/api/v1/tickets",
    {
      subject: "Sample Ticket",
      contactId: "1234567890",
      departmentId: "0987654321",
      description: "This is a sample ticket created via API",
    },
    {
      headers: {
        Authorization: `Zoho-oauthtoken YOUR_ACCESS_TOKEN`,
      },
    }
  );
  console.log(response.data);
};

GET Request Example: Fetch Tickets

import axios from "axios";

const fetchTickets = async () => {
  const response = await axios.get("https://desk.zoho.com/api/v1/tickets", {
    headers: {
      Authorization: `Zoho-oauthtoken YOUR_ACCESS_TOKEN`,
    },
  });
  console.log(response.data);
};

⚙️ Summary

Once your .env is fully configured, your Next.js app can securely communicate with the Zoho Desk API by:

  1. Generating access tokens using the refresh token.
  2. Performing authorized requests for tickets, contacts, and settings.
  3. Integrating desk features into your workflow or admin dashboard.

For more detailed information, refer to the Zoho Desk API Documentation.


📩 Need Help?

At Jazzed Technology, we specialize in building integrations to help businesses streamline their support stack. Whether you’re using Zoho, Salesforce, or a custom CRM — we’ve got you covered.

👉 Contact us for help integrating Zoho Desk into your platform or any other Web and IT Support needs.

Toggle Theme:

Our mission is to deliver high-quality web design, SEO, and IT support services in Vancouver, tailored to the unique needs of our clients. We aim to be your trusted partner, providing exceptional customer service that exceeds your expectations.

© 2023 Jazzed Technology | Vancouver Web Design, SEO & IT Support Company. All rights reserved.