Zoho cliq oauth refresh token issue

Hi there, I am trying to make pack which can send data to the zoho cliq channel through their api. Now i have got the authentication working and i am able to get the flow working but their access token gets expired after one hour, i am also getting a refresh token but even after that my pack is not fetching the new access token by using refresh token

export const pack = coda.newPack();
import * as coda from "@codahq/packs-sdk";
import { ValueType } from "@codahq/packs-sdk";

// Define the pack to send data to Zoho Cliq
pack.addFormula({
name: "SendMessageToCliq",
description: "Send a message to a Zoho Cliq channel.",
isAction:true,
parameters: [
      coda.makeParameter({
      name: "message",
      description: "The message to send to the Zoho Cliq channel.",
      type: coda.ParameterType.String,  // Correct parameter type usage
    }),
    coda.makeParameter({
      name: "channel",
      description: "The Zoho Cliq channel name or id.",
      type: coda.ParameterType.String,  // Correct parameter type usage
    }),],
execute: async([message, channel],context) => {
const url=`https://cliq.zoho.in/company/{redacted by me}/api/v2/channelsbyname/${channel}/message`;

// Send POST request to Zoho Cliq
try{
const response=await context.fetcher.fetch({
method: "POST",
url: url,
body: JSON.stringify({
text: message
})
});
return "Success";
}
catch(e:any){
  if(e.toString().includes("401"))
  throw new coda.UserVisibleError(`Unauthorized`) 
}
},
resultType: ValueType.String
});
pack.addNetworkDomain("cliq.zoho.in")
pack.setUserAuthentication({
  type: coda.AuthenticationType.OAuth2,
  postSetup:[],
  authorizationUrl: "https://accounts.zoho.in/oauth/v2/auth",
  tokenUrl: "https://accounts.zoho.in/oauth/v2/token",
  scopes: ["ZohoCliq.Webhooks.CREATE"],
  tokenPrefix:"Zoho-oauthtoken",
  additionalParams:{
    "access_type":"offline",
    "prompt":"consent"
  }
});

I think its setup correctly but its not fetching new access token. Since this is an automation, i dont want to login after every 1 hour. Need help

Hi @Rishabh_Bajpai - Welcome to the Coda community! I suspect the issue is your try/catch around the Fetcher request. As mentioned in the documentation, the refresh token flow only happens if your code throws a 401 StatusCodeError. Your try/catch seems to be converting those into UserVisibleError which won’t trigger the refresh flow. If you remove the try catch, or at least re-throw 401’s that are due to expired token, then it should refresh correctly.

Hi @Eric_Koleda , I tried it and it works now!!. So what would you suggest to make this code better?Please let me know and thank you for such a prompt reply.

Glad to hear that worked! I don’t have any other suggestions at the moment, but let us know if you run into any other issues or challenges.