I have refactored the code to better handle the errors. Below is a code snippet of what I am trying to do when I get the JWT Error.
// Get loggedInAgent to verify as Administrator
client.data.get("loggedInAgent").then(
(data) => {
console.log(data);
let loggedInAgent = data.loggedInAgent.id;
// Make API call with agent id to obtain Agent Role
let headers = {
Accept: "application/json",
Authorization: "Bearer <%= (iparam.apiKey) %>",
"Content-type": "application/json",
};
const options = {
headers: headers,
};
let url = "https://api.freshchat.com/v2/agents/" + loggedInAgent;
client.request
.get(url, options)
.then((data) => {
let responseBody = data.response;
console.log(responseBody);
let obj = JSON.parse(responseBody);
let agentRole = obj.role_id;
console.log(agentRole);
if (agentRole === "ACCOUNT_ADMIN") {
getAgentIdNameAndSetStatus();
}
})
.catch((error) => {
client.interface.trigger("showNotify", {
type: "danger",
message: "Unable to retrieve agent role",
});
console.log("Exception - ", error);
});
},
(error) => {
console.log("Exception - ", error);
}
);
I have tried changing the Authorization to Authorization: "Basic <%= encode(iparam.apiKey) %>"
or Authorization: "Bearer <%= encode(iparam.apiKey) %>"
but those return an error regarding improper authorization header.
Again, when I run fdk run
navigate to apps > custom apps, I can see the application with “in dev” next to the app. I click install and then enter the API Token from freshchat admin settings. Go to a conversation and then append ?dev=true to the end of the url, reload and the app runs without issues.
But, when I package the app and upload to the developer portal, then install the app from the app gallery, load a conversation in production, I get the JWT Error mentioned above.
Any help would be greatly appreciated. I have spent a while trying to debug this.
Thank you!