Custom Functions Using Zoho Finance CLI
In Zoho Books, the primary method to write a custom function’s code is using the built-in Deluge editor. With the Zoho Finance CLI, you can write the code for custom functions in popular programming languages such as Java, Node.js, and Python. Once you write the code, you can easily push it to Zoho Books.
Insight: A Command-Line Interface (CLI) is a text-based User Interface (UI) used to run programs, manage computer files, and interact with the computer. Inputs are provided to the CLI through the command prompt or terminal and are then executed by the computer.
Prerequisite: To use the Zoho Finance CLI, you need to download Node.js. Download Node.js version 16 on your device. This comes with npx installed. Once installed, enter the following commands to verify if they were installed properly.
-
node -v
-
npx -v
ON THIS PAGE
Zoho Finance CLI Commmands
Refer to the commands listed below to use the Zoho Finance CLI toolkit.
- login: Log in to your Zoho account.
- pull: Download the custom function created in Zoho Books to your device.
- execute: Execute and verify if the custom function is working as intended.
- push: Push the code to Zoho Books and update the custom function.
- logout: Log out of your Zoho account.
Log In to Your Zoho Account
You need to login to your Zoho account using the terminal or command prompt. Here’s how:
-
Open the terminal or command prompt on your device.
-
Enter the command:
npx @zohofinance/cli login
-
Select the DC in which your Zoho account was created. You’ll be redirected to the Zoho Accounts login page.
-
Click Allow. You’ll be logged in to your Zoho account.
Download the Custom Function
You need to create a custom function in Zoho Books and download it on your device to enter the required code using CLI. Here’s how:
- Open the terminal or command prompt on your device.
- Enter the command:
npx @zohofinance/cli pull "https://www.zohoapis.com/books/integrations/customfunctions/xxxxxxxxxxxxxxxxx/download?organization_id=yyyyyyyy&entity=invoice"
Here, xxxx… represents the custom function’s ID, and yyyy…. represents your organisation’s ID. Click Copy next to the command to use the prefilled custom function ID and organisation ID.
Write the Code in the Editor
You can write the custom function’s code in a code editor. After downloading a custom function, a folder will be downloaded to your current working directory, containing the necessary files for the custom function.
To write the custom function’s code:
- Open the downloaded folder.
- Open the file with the .py, .js, or .java extension, based on the programming language you selected when creating the custom function. For example, if the custom function’s name is sample_custom_function and the programming language is Java, the file will be named, sample_custom_function.java.
- Enter the custom function’s code in this file from a code editor and save it.
Execute the Code
You can execute the custom function’s code to verify if it’s working as intended. Here’s how:
- Open the terminal or command prompt on your device.
- Enter the command:
npx @zohofinance/cli execute
- Enter the ID of a record in the module for which you created the custom function in the Enter the entity id field. The entity ID will be available in the URL. For example, if you created the custom function for the Invoices module in Zoho Books, select an invoice and copy the part of the URL that appears after ‘invoices/’. This is the entity ID.
Once the custom function is executed, the result will be displayed.
Push the Code to Zoho Books
Once you’ve written and executed the custom function’s code, you can push it to Zoho Books to update the custom function in the app. Here’s how:
- Open the terminal or command prompt on your device.
- Enter the command:
npx @zohofinance/cli push
With this, the custom function will be pushed and updated in your Zoho Books organisation.
Note: Custom functions created using the Zoho Finance CLI cannot be edited from Zoho Books. They can only be edited in the terminal or command prompt. However, you can delete these functions directly from Zoho Books if needed.
Log Out of Your Zoho Account
After you’ve pushed the custom function’s code to Zoho Books, you need to log out from your Zoho account. Here’s how:
- Open the terminal or command prompt on your device.
- Enter the command:
npx @zohofinance/cli logout