## Documentation Index Access the complete documentation index at: https://www.zoho.com/qa/books/help/llms.txt Use this file to discover all available documentation pages before proceeding. # Functions Using Zoho Finance CLI In Zoho Books, the primary method to write a function’s code is using the built-in Deluge editor. With the Zoho Finance CLI, you can write the code for 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. You provide inputs to the CLI through the command prompt or terminal, and the computer executes them. **Prerequisite:** To use the Zoho Finance CLI, you need to download Node.js. Download [Node.js](https://nodejs.org/en/download/package-manager) 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 ### Zoho Finance CLI Commands Refer to the commands listed below to use the Zoho Finance CLI toolkit. * **login**: Log in to your Zoho account. * **pull**: Download the function created in Zoho Books to your device. * **execute**: Execute and verify if the function is working as intended. * **push**: Push the code to Zoho Books and update the 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: ```sh npx @zohofinance/cli login ``` * Select the **DC** 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 You need to [create a function](/qa/books/help/settings/automation.html#create-and-execute-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: ```sh npx @zohofinance/cli pull "https://www.zohoapis.com/books/integrations/customfunctions/xxxxxxxxxxxxxxxxx/download?organization_id=yyyyyyyy&entity=invoice" ``` Here, xxxx… represents the function’s ID, and yyyy…. represents your organisation’s ID. Click **Copy** next to the command on the function’s Edit page to use the prefilled function ID and organisation ID. * * * ### Write the Code in the Editor You can write the function’s code in a code editor. After [downloading a function](/qa/books/help/settings/custom-functions-using-zoho-finance-cli.html#download-custom-function), your system downloads a folder to your current working directory, containing the necessary files for the function. To write the 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 function. For example, if the function’s name is _sample\_custom\_function_ and the programming language is _Java_, the file is named **sample\_custom\_function.java**. * Enter the function’s code in this file from a code editor and save it. * * * ### 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: * **Log** entries for debugging and monitoring. * **Cache** data for quick retrieval with a TTL. * **Queue** messages using an in-memory queue with persistent storage. * **Store files** using Stratus, an internal file storage service. * **Schedule** functions to run at a specific time or periodically using Docket. * **Connect** to third-party services using Connectors. For the complete list of available context methods and code samples, refer to the [Functions - Context Methods](/qa/books/help/settings/custom-functions-context-methods.html) help document. * * * ### 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: ```sh npx @zohofinance/cli execute ``` * Enter the ID of a record in the module for which you created the function in the **Enter the entity id** field. The entity ID will be available in the URL. For example, if you created the 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 function’s code, you can push it to Zoho Books to update the function in the app. Here’s how: * Open the terminal or command prompt on your device. * Enter the command: ```sh npx @zohofinance/cli push ``` With this, Zoho Books receives and updates the custom function in your organisation. **Note:** 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 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: ```sh npx @zohofinance/cli logout ``` * * * ## Related Topics * [Functions](/qa/books/help/settings/automation.html#custom-functions) * [Functions - Context Methods](/qa/books/help/settings/custom-functions-context-methods.html)