Implementing Retries for Failed API Calls in a Freshdesk Custom App

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:

  1. Does $request.invokeTemplate provide built-in retry functionality, or does it need to be implemented manually?

  2. 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?
  1. 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! :blush:

Hey @tim.hofmann

There is a built in feature, but it may not help a lot as you can only retry for max 5 times with a delay of max 1.5 seconds: Freshworks Developer Docs | Use request method to place secure HTTP calls (check for the options object in request.json).

There has been a pretty decent developer’s call a while ago which was exactly on that topic.
But neither I can’t remember if it was recorded nor am I able to find it here.

What I remember is, that the logic was to create a scheduled event (you can create a lot of scheduled events with a minimum of 6 minutes from now: Freshworks Developer Docs | Configure scheduled events

Another option was to put data of the failed event into a key value storage and to read it after a while (this may be helpful if you could do bulk updates for example).

Can anyone else remember if this session of 1 or 2 years ago was recorded?

Tomas

Hey @ThomasH ,

thanks for your response!

I’m going to look into the scheduled events - maybe this is something I can work with :slight_smile:

Tim