Hi Freshworks Community,
we have a Freshdesk Custom App that integrates Freshdesk with our internal CRM system via API calls. The app triggers API requests whenever specific events occur, such as ticket creation, ticket updates, and user modifications.
Problem Statement:
- If our CRM system is temporarily unavailable (e.g., during maintenance), the API calls fail and are not retried.
- Once the CRM is available again, there is no automatic retry of previously failed requests.
- We need a retry mechanism to ensure that no data is lost when the CRM system is temporarily down.
Current Setup:
Our requests.json
defines the API request template:
{
"createCrmEvent": {
"schema": {
"method": "POST",
"host": "<%= iparam.host %>",
"path": "/api/path",
"headers": {
"Authorization": "*********",
"Content-Type": "application/json"
}
}
}
}
Below is a simplified example of our current event handler for onTicketCreateCallback
, which directly invokes the API call using $request.invokeTemplate
in server.js
:
exports = {
async onTicketCreateCallback(payload) {
const ticket = payload.data.ticket;
const requester = payload.data.requester;
const requestBody = {
payload: {
id: ticket.id,
subject: ticket.subject,
description: ticket.description,
description_text: ticket.description_text,
type: ticket.type,
status: ticket.status,
priority: ticket.priority,
contact_person: requester.email,
created_at: ticket.created_at
}
};
try {
const response = await $request.invokeTemplate("createCrmEvent", {
body: JSON.stringify(requestBody),
});
console.info("[New Ticket] API Response:", response);
} catch (e) {
console.error("[New Ticket] API Error:", JSON.stringify(e));
}
}
};
Questions:
-
Does
$request.invokeTemplate
provide built-in retry functionality, or does it need to be implemented manually? -
What is the best approach for implementing retries?
- Should we implement exponential backoff within our Freshdesk Custom App?
- Would an alternative Freshworks mechanism (e.g., background jobs) be better suited?
- Has anyone successfully implemented a retry system in a Freshdesk Custom App and can share best practices?
Expected Outcome:
- If the API call fails, it should retry automatically instead of failing permanently.
- Once the CRM is back online, all failed API requests should be processed to ensure data consistency.
Any insights or recommendations would be greatly appreciated!
Thanks in advance!