Optimal Utilization of Custom Functions and APIs - Online Help | Zoho Desk

Optimal Utilization of Custom Functions and APIs

 
Developers can enhance the performance of software applications by writing code efficiently. In Zoho Desk, when integrating or customizing the Desk account, developers can minimize the frequency of API calls and redundancy in code by following the guidelines below.  

Optimizing code in custom functions

It is advisable to optimize code by verifying if the necessary data has already been fetched rather than rewriting code to fetch the data again. Always verify the value of the field before executing any operation. This approach helps eliminate redundancy in the code.

Perform a null check of the fields before any operation

When making API calls or function calls, it is crucial to check for null values consistently. It is considered a best practice to ensure the existence of a value in optional or relevant fields before carrying out any operations associated with those fields.
For instance, it is advisable to check if the custom field cf_category has a value or not before executing the code or updating the field.



Ensure data availability before any operation

 When making an API call, it is advisable to check the details of the retrieved results before fetching related or identical data. 
For instance, if the ticketList API is called and it includes both ticketId and ticketNumber, it is recommended to utilize the ticketNumber data already present in the ticketList when fetching the ticketNumber using a function.


Use the include option in API calls

Instead of making two separate API calls to retrieve ticket details like ticketOwner and assignee information, a more efficient approach would be to use a single API call with the include option. This option allows users to fetch the necessary additional details in a single API call instead of making multiple calls. Learn more about include options.


Check data values before any operation

Avoiding unnecessary modifications to records helps ensure efficiency.
For instance, if you wish to mark a ticket as closed, verify whether the ticket is already closed or not

Utilize the sendReply option for email threads

The limit for sending emails is 2,500 per day. When using the sendmail function, the emails sent will not be logged in the ticket thread. However, you can use the sendReply function without any limits for sending emails, and the emails will be recorded in the thread conversation.



Avoid unnecessary automation with feature flags

If necessary, automation can be bypassed. In the case of a ticket update, if an automation workflow is created, the automation engine will be activated whenever there is an update in the ticket. To prevent this, configure the featureFlag to skip the automation.

Retrieve field values directly from arguments

Instead of fetching a field value through a function or in code, it is possible to obtain it using arguments.
For example, if you want to get the value of a field in the variable splitTicket, you can directly use the arguments. The variable already contains the field value, so there is no need to fetch the ticketId and then retrieve the value for the variable.



Optimizing API calls

 Using a single API call to obtain the necessary data and execute or modify an action is a more effective approach than utilizing multiple API calls.

Utilize a dedicated updateMany API to update multiple tickets

To efficiently update multiple tickets, use the updateMany API. This allows you to use a single API call rather than repeatedly updating each ticket using a loop and causing unnecessary network activity.
For instance, instead of retrieving a list of tickets and updating them one by one in a loop, using the updateMany API to update multiple tickets at once will minimize the number of API calls required.
        
                      

Use a single API request to modify multiple attributes of an entity

It's possible to update multiple properties of an entity with a single API call. 
For example, instead of making separate API calls to update a ticket's status and assigneeId  fields, a single API call can update both at once.
     

                 

Utilize a dedicated API for retrieving the most recent thread

Instead of retrieving the list of threads for a ticket and then fetching the latest thread separately, you can simply use the latestThread API to obtain the most recent thread details for that ticket.


When using the upload API in a custom function for bulk attachments, make sure to call the API for each file individually.

This is because each time a file is uploaded, a unique ID is generated. If you try to upload the same file in bulk, only one ID will be created and assigned to the first attachment, leaving the rest without an ID.

To ensure every attachment is properly linked, use the upload API separately for each one.

Refer to the extension example code given below :