Zoho payroll logo Help Docs
/

Functions Using Zoho Finance CLI

The primary method to write a function in Zoho Payroll is through the built-in Deluge editor. If you prefer to write functions in Java, Node.js, or Python, you can use the Zoho Finance CLI to write the code on your device and push it to Zoho Payroll.

Insight: A Command-Line Interface (CLI) is a text-based interface used to run programs and interact with applications. You provide inputs through the command prompt or terminal, and the computer executes them.

Prerequisite: To use the Zoho Finance CLI, you need Node.js version 16 or later installed on your device. This comes with npx installed. Once installed, run the following commands to verify the installation:

  • node -v
  • npx -v

Zoho Finance CLI Commands

The following commands are available in the Zoho Finance CLI:

CommandDescription
loginLog in to your Zoho account.
pullDownload the function created in Zoho Payroll to your device.
executeRun and verify that the function works as intended.
pushPush the code to Zoho Payroll and update the function.
logoutLog out of your Zoho account.

Log In to Your Zoho Account

To use the CLI, you must first log in to your Zoho account from the terminal or command prompt.

  • Open the terminal or command prompt on your device.
  • Enter the command:
npx @zohofinance/cli login
  • Select the DC (data centre) in which your Zoho account was created. Zoho redirects you to the Zoho Accounts login page.
  • Click Allow. You are now logged in to your Zoho account.

Download the Function

Before you can write code using the CLI, you must first create a function in Zoho Payroll and select a non-Deluge programming language (Java, Node.js, or Python). Then, download the function to your device.

  • Open the terminal or command prompt on your device.
  • Enter the command:
npx @zohofinance/cli pull "<URL>"

Replace <URL> with the download URL for your function. To get this URL, go to the function’s Edit page in Zoho Payroll and click Copy next to the CLI command. The URL contains your function’s ID and your organisation’s ID.


Write the Code in the Editor

After downloading the function, a folder is created in your current working directory containing the necessary files.

  • Open the downloaded folder.
  • Open the file with the .py, .js, or .java extension, depending on the programming language you selected when creating the function. For example, if the function’s name is sync_employee_data and the programming language is Java, the file is named sync_employee_data.java.
  • Write your function code in a code editor of your choice and save the file.

Context Methods

When writing functions in Java, Node.js, or Python, a context object is automatically passed to your function. This object provides methods that let you interact with platform features:

  • Log: Record entries for debugging and monitoring.
  • Cache: Store and retrieve data with a time-to-live (TTL) for quick access.
  • Queue: Send messages using an in-memory queue with persistent storage.
  • Store Files: Upload and manage files using Stratus, an internal file storage service.
  • Schedule: Set functions to run at a specific time or on a recurring basis using Docket.
  • Connect: Authenticate with third-party services using Connectors.

For detailed method references and code samples in Java, Node.js, and Python, see Context Methods.


Execute the Code

You can execute the function locally to verify that it works as intended before pushing it to Zoho Payroll.

  • Open the terminal or command prompt on your device.
  • Enter the command:
npx @zohofinance/cli execute
  • In the Enter the entity id field, enter the ID of a record in the module for which you created the function. You can find the entity ID in the URL when you open the record in Zoho Payroll.

Once the function is executed, the result is displayed in the terminal.


Push the Code to Zoho Payroll

After writing and testing the function, push it to Zoho Payroll to update the function in the application.

  • Open the terminal or command prompt on your device.
  • Enter the command:
npx @zohofinance/cli push

The function is now updated in your Zoho Payroll organisation.

Note: Functions created using the Zoho Finance CLI cannot be edited from within Zoho Payroll. They can only be edited in the terminal or command prompt. You can delete these functions directly from Zoho Payroll if needed.


Log Out of Your Zoho Account

After pushing the function, log out from your Zoho account.

  • Open the terminal or command prompt on your device.
  • Enter the command:
npx @zohofinance/cli logout