## Zoho Billing - Product, solutions, integrations, support, and resources Index

Access the complete documentation index at:
https://www.zoho.com/billing/llms.txt

Use this file to discover all available documentation pages before proceeding.

# Automation

Automation allows you to create a set of rules for modules of Zoho Billing based on which appropriate actions would be performed. A good example would be the case where a congratulatory e-mail is sent automatically to the team members when a quote for goods worth over $1000 gets accepted by a client.

In the next few steps, you will be learning about:

*   Creating and describing a Workflow.
*   Deciding on when to execute a workflow.
*   Setting the conditions for executing a workflow.
*   Associating actions such as email alerts, and webhooks with a workflow.
*   Connecting to an external web service provider using Webhooks.

## Workflow Scenarios

Workflows can come in handy if you wish to get things done automatically in Zoho Billing. Following are some of the scenarios where workflows come into play.

**Note:** Workflow actions including email alerts, webhooks and custom functions, that are configured based on customer creation events will not be triggered for new customers who sign up via the hosted payment pages, or customers created along with subscriptions via API.

*   [Scenarios for Email Alerts](/billing/help/settings/automation.html#email-alerts)
*   [Scenarios for Webhooks](/billing/help/settings/automation.html#web-hooks)
*   [Scenarios for Custom Functions](/billing/help/settings/automation.html#custom-functions)
*   [Scenarios for In-App Notifications](/billing/help/settings/automation.html#in-app-notifications)

### Scenarios for Email Alerts

**Scenario 1**

Dillion Inc. is a garment export company. The VP of sales wants to receive email alerts when an employee raises a quote for an amount greater than $10,000 for one of their top customers. This will help them offer their best services. In that case, a workflow can be designed to automatically trigger email alerts when the following conditions are met.

  
**Execute When**: Created  
**Rule Criteria**: Total amount due is greater than $10,000.  
**Immediate Action**: Email alert to the VP of the Sales/ Finance team.  
**Time Based Action**: —-

* * *

**Scenario 2**

Whenever a new lead fills out an inquiry form regarding home or office security solutions, Greg wants to ensure they receive a warm welcome email instantly.

  
**Execute When**: Created  
**Rule Criteria**: When Contact Type is Lead  
**Immediate Action**: Send an Email Alert containing a welcome message, company introduction, and links to book a consultation.  
**Time-Based Action**: ——–

* * *

**Scenario 3**

Joseph, the CTO of Bookworm.com, an online bookstore wants to implement a system wherein an alert message should be triggered to the packing section, upon raising an invoice for an order placed by the customer. The Email Alerts feature allows him to accomplish this by creating a workflow rule with the following parameters.

  
**Execute When**: Created or Edited  
**Rule Criteria**: Contact Name is XYZ  
**Immediate Action**: —–  
**Time Based Action**: Email alert to the packing section upon raising an invoice.

* * *

* * *

### Scenarios for Webhooks

**Scenario 1**:

Greg is the Public Relations manager for a Home & Office Security company. A first time customer had asked for a quotation for setting up security systems for his office in Boston. Greg wants to make a good impression by promptly sending a ‘Thank You’ SMS as soon as he accepts the quote. The webhooks feature in automation can do that by setting the following parameters and connecting to a SMS gateway.

  
**Execute When**: Created or Edited  
**Rule Criteria**: When Contact Name is “XYZ” and Contact Type is “Customer”.  
**Immediate Action**: SMS alert using a webhook with SMS gateway.  
**Time Based Action**: —

* * *

**Scenario 2**:

Frank is the financial controller of a Stock Brokerage firm. Most of the company’s revenue is credited into the company’s official Stripe account. He wants to be notified of any high value deposits or withdrawals towards invoices or expenses from that account via Email or SMS, on a weekly basis. He can achieve that by setting up a webhook using the following parameters.

  
**Execute When**: Created or Edited  
**Rule Criteria**: When Total Amount>=$10,000  
**Immediate Action**: —  
**Time Based Action**: Trigger Email Alert 7 days after Rule Trigger Date

* * *

### Scenarios for Custom Functions

**Scenario 1**:

**Applying a 10% discount if your invoice total exceeds $2500**

Sarah runs a supermarket and she wishes to provide discounts to celebrate her store’s 10th Anniversary. She decides to give a 10% discount for anybody who makes a purchase for $2500 or more. It would be a painful task to include discount everytime she creates an invoice.

With the help of custom functions, she can write a small piece of code to execute this action.

Sarah can set a condition where if the total of the invoice exceeds $2500, the function will be executed and a 10% discount will be applied.

Now, let’s look at how the custom function would look for this scenario.

**Custom function name:** Discount

**Description:** Apply a 10% discount when the invoice total exceeds $2500

**Module:** Invoice

**Script:**

```
//create a variable and get invoice total
total = invoice.get("total").toDecimal();
orgID = organization.get("organization_id").toString();
invoiceID = invoice.get("invoice_id").toLong();
//set a condition: when invoice amount is >= 2500
if ( total >= 2500.00 )
{
	adjustment = invoice.get("adjustment").toDecimal();
	adjustment = adjustment - total * 0.10;
	jsonMap = Map();
	jsonMap.put("adjustment", adjustment);
	jsonMap.put("reason", "discount");
	// To update the current record
	result = zoho.invoice.update("invoices", orgID, invoiceID, jsonMap);
	info result.toMap().get("message") ;
}
```

She then creates a workflow rule with the following parameters.

**Workflow Rule Name:** Anniversary discount

**Module:** Invoice

**Workflow type:** Event based

**When an invoice is:** Created

**Triggers:** When total >= 2500

**Actions:** Custom functions - Discount

Now, when the invoice total is greater than or equal to $2500, the workflow will be triggered and the custom function will be executed.

* * *

**Scenario 2**:

**Adding a 5% latefee when an invoice becomes overdue**

Dennis runs a self-storage facility in Manhattan where customers can store anything in a box, small enough to safely store documents and, big enough to store an expensive car. He charges his customers the option to pay on a daily, weekly, monthly or even a yearly basis. He offers them a 10-day grace period from the invoice date to make the payment after which, he charges an additional 5% of the invoiced amount as late fees.

Using Zoho Billing, he writes a small code using Custom Functions to automatically calculate the late fees and add it as adjustments in the invoices when the invoices become Overdue.

Now, let’s look at how the custom function would look for this scenario.

**Custom function name:** Latefee

**Description:** Apply a 5% late fees on the invoice amount

**Module:** Invoice

**Script:**

```
//create a variable to get invoice total and add a 5% discount
latefee = invoice.get("total").toDecimal() * 0.05;
orgID = organization.get("organization_id").toString();
invoiceID = invoice.get("invoice_id").toLong();
//display the value stored in the latefee variable
info latefee;
//add late fee and adjustment and store the total amount in the variable 'adjustment'
adjustment = invoice.get("adjustment").toDecimal() + latefee;
jsonMap = Map();
jsonMap.put("adjustment",adjustment);
jsonMap.put("reason","Late fee");
// To update the current record
result = zoho.invoice.update("invoices",orgID,invoiceID,jsonMap);
info result.toMap().get("message");
```

He then creates a workflow rule with the following parameters.

**Workflow Rule Name:** Late fee

**Module:** Invoice

**Workflow type:** Date based

**Date of Execution:** 0 day(s) after Due Date

**Execution time:** Enter the time of execution

**Execution cycle:** Once

**Triggers:** When > Status > isn’t > Paid > AND > Status > isn’t > Partially Paid

**Actions:** Custom functions - Latefee

Now, when the invoice due date exceeds the set date (in the workflow rule), the workflow will be triggered and the custom function will be executed.

* * *

**Scenario 3**:

**Provide discount if payment for the invoice is made before the due date**

Donna runs a design firm that creates promotional materials for websites on a monthly basis. This involves designing brochures, banner ads, and other promotional materials. Donna sends invoices at the end of each month and often receives payment only after the credit period, which is 30 days. To receive funds immediately, she decides to offer a discount if the invoice amount was paid before the invoice due date.

In order to implement this, she adds a discount of 5% to her invoices and in the customer notes section she mentions that the discount would be applicable only if the payment is made before the due date.

To make this work, Donna writes the following custom function.

```
//if payment for the invoice is received after the invoice due date then discount won't be applied
orgID = organization.get("organization_id").toString();
invoiceID = invoice.get("invoice_id").toLong();
jsonMap = Map();
jsonMap.put("discount", 0);
jsonMap.put("reason", "reached due date.");
result = zoho.invoice.update("invoices", orgID, invoiceID, jsonMap);
info result.toMap().get("message") ;
```

Once done, she creates a workflow to execute ths custom function. The parameters of the workflow rule is mentioned below:

**Workflow rule name:** Discount for early payment

**Module:** Invoice

**Workflow type:** Date based

**Date of Execution:** 0 day(s) after **Due Date**

**Execution time:** Enter the time of execution

**Execution cycle:** Once

**Trigger:** When > Status > isn’t > Paid

**Actions**

**Type:** Custom function and **Name:** Name of your custom function

So, if an invoice reaches the due date, the workflow will be triggered and the custom function will add 0% discount instead of the actual 5%

* * *

**Scenario 4**:

**Automatically set due date for an invoice as 30 days before the event date (that is entered via a custom field)**

Tom is a creative wedding photographer. His client book for his services 2-3 months prior to the wedding date (event date.) And, Tom would confirm the date only if the client pays the full amount 30 days before the wedding date. In order to streamline this process, Jake, one of the members of Tom’s studio writes a small custom function.

To start with, Jake creates a custom field named “Wedding Date” with the **date** datatype and writes the following custom function

```

orgID = organization.get("organization_id").toString();
invoiceID = invoice.get("invoice_id").toLong();
customFieldList = invoice.get("custom_fields").toList();
cfDate = null;
for each  customField in customFieldList
{
	customFieldMap = customField.toMap();
	if(customFieldMap.get("label") == "Date")
	{
		cfDate = customFieldMap.get("value");
		break;
	}
}
duedate = cfDate.toTime().subMonth(1);
info duedate;
duedate = duedate.year() + "-" + text(duedate.month(),"00") + "-" + text(duedate.day(),"00");
jsonMap = Map();
jsonMap.put("due_date", duedate);
jsonMap.put("reason", "Auto due date.");
result = zoho.invoice.update("invoices", orgID, invoiceID, jsonMap);
info result.toMap().get("message");
```

After creating the custom function, Jake creates a workflow rule to trigger it. The parameters of the workflow rule are as follows:

**Workflow name:** Payment 30 days before the wedding

**Module:** Invoice

**Workflow type:** Event based

**When invoice is:** Created

**Actions**

**Type:** Custom function and **Name:** Name of your custom function

While creating an invoice, if Tom mentions the wedding date in the custom field, the workflow will be triggered and the custom function will set the due date of the invoice to 30 days before the wedding date.

* * *

**​Scenario 5**:

**Automatically cancel an quote if its not accepted within 10 days from the date of creation.**

Katherine owns a company that supplies automotive spare parts to several automobile service stations. Several customers ask her for a quote, but a portion of them fail to communicate their decision by neither accepting nor rejecting the quote. To avoid this, Katherine decides to decline the quote if she doesn’t hear back from the client within 10 days from the receipt of the quote. To implement this, she writes a custom function

```
//get quote and organization ID
quoteid = quote.get("quote_id");
orgid = organization.get("organization_id");

//convert the status of the quote to 'declined'
result = invokeUrl
[
url: "https://billing.zoho.com/api/v3/quotes/" + quoteid + "/status/declined?organization_id=" + orgid
type: POST
connection: "billing_api_connection"
];
```

Now, to trigger the execution of this custom function, she creates a workflow rule with the following parameters.

**Workflow Name:** Decline quote after 10 days of receipt

**Module:** Quote

**Workflow type:** Date Based

**Date of Execution:** 10 day(s) after **Created Time**

**Execution time:** Enter the time of execution

**Execution cycle:** Once

**Criteria:** When > Quote Status > is > Sent > AND > Quote Status > is > not approved

**Actions**

**Type:** Custom function and **Name:** Name of your custom function

Now, when the quote exceeds 10 days from its created time, the workflow will be triggered and the custom function will be executed to change the status of the quote to declined.

* * *

**Scenario 6**:

**Extend due date by 7 days if the customer pays 50% of the invoice amount on or before the initial due date**

Diane owns a store that supplies printing paper and office stationery for offices in her area. She wants to extend the due date of the invoice by a week if customers pay 50% of the invoice amount on or before the initial due date.

In order to do that, she writes the following custom function:

```
//Getting invoice total, balance after the partial payment, and due date
inv_total = invoice.get("total").toDecimal();
inv_balance = invoice.get("balance").toDecimal();
inv_duedate = invoice.get("due_date").toDate();
orgid = organization.get("organization_id").toString();
invid = invoice.get("invoice_id").toLong();
//Condition to check if the amount paid is 50% of the invoice amount
if(inv_balance == inv_total / 2)
{
	inv_duedate = inv_duedate.addDay(7);
	inv_duedate = inv_duedate.year() + "-" + text(inv_duedate.month(),"00") + "-" + text(inv_duedate.day(),"00");
	//Update the due date by 7 days
	jsonMap = Map();
	jsonMap.put("due_date", inv_duedate);
	jsonMap.put("reason", "Increased due date");
	result = zoho.invoice.update("invoices", orgid, invid, jsonMap);
	info result.toMap().get("message") ;
}
```

Once done, Diane creates a workflow rule to execute the custom function.

**Workflow name:** Extend due date

**Module:** Invoice

**Workflow type:** Event based

**When invoice is:** Edited

**Execute the workflow** When any field is updated

**Just once or Everytime?** Just once

**Triggers** When > Status > is > Partially paid

**Type:** Custom function and **Name:** Name of your custom function

Now, when a customer pays 50% of the invoice amount by the initial due date, a grace period of 7 days will be given for him to pay the balance amount.

* * *

### Scenarios for In-App Notifications

**Scenario 1**:

KYZ shoe company decides to offer freebies to all the customers who purchase from them. The finance team should be notified each time an invoice is paid, so that they can send out the freebies. They created a workflow that would internally notify the finance team whenever an invoice moves to the paid status.

*   **Execute When:** Created or Edited
*   **Rule Criteria:** Status changes to Paid
*   **Immediate Action:** In-app notification to the Finance team.
*   **Time Based Action:** —

**Scenario 2**:

Peter is the head of ABC organization. Whenever a credit note is raised, Peter would like to notify the head of the production department. This will help the production team to work on their shortcomings and improve their service. For this, they will need to create a workflow to notify the production department.

*   **Execute When**: Created
*   **Rule Criteria**: —-
*   **Immediate Action**: Notification to the Production Team’s Head.
*   **Time Based Action**: —

* * *

## Setting Up a New Workflow Rule

A workflow rule consists of  actions that comprises of emails alerts, , and Webhooks that play an essential role in executing a task. A workflow rule may employ one or more actions to accomplish the task. To set up a workflow rule in Zoho Billing, navigate to _Settings_ > _Automation_ > _Workflow Rules_.

*   [Name Your Workflow](/billing/help/settings/automation.html#name-your-workflow)
*   [Choose When To Trigger a Workflow](/billing/help/settings/automation.html#choose-when-to-trigger-a-workflow)
*   [Workflow Types](/billing/help/settings/automation.html#workflow-type)
*   [Filter the Triggers](/billing/help/settings/automation.html#filter-the-triggers)
*   [Actions](/billing/help/settings/automation.html#actions)
*   [Other Actions](/billing/help/settings/automation.html#other-actions)
*   [Email Alerts](/billing/help/settings/automation.html#email)

### Name Your Workflow

**Field**

**Description**

**Workflow Rule Name**

Give a unique name for the workflow rule.

**Module**

Select the module for which you wish to create a workflow.

**Description**

Give a small description for your workflow rule.

### Choose When To Trigger a Workflow

You can choose when to trigger the workflow based on the parameters you select in the following fields.

### Workflow Type

There are two types of workflows:

*   Event Based
*   Date Based

**Event Based:**

If the workflow is **Event Based**, then the workflow is triggered when a module is:

*   Created
*   Edited
*   Created or Edited
*   Deleted

When a module is **Edited** or **Created or Edited**, additional fields appear.

**Field**

**Description**

**Execute the workflow when**

There are 3 options to choose from  
\-When any field is updated.  
\-When any selected field is updated.  
\-When all selected field are updated.  
If you select **When any selected field is updated** or **When all selected fields are updated** in the drop-down, an additional box will appear where you can select any 3 fields of the module.

**Just Once or Overtime?**

**Just Once-** The workflow would be executed when the criteria is met for the first time.  
**Everytime-** The workflow would be executed everytime the criteria is met.

**Date Based:**

If the workflow is **Date Based**, the following fields appear.

**Field**

**Description**

**Date of Execution**

Select the workflow to be triggered on any number of days before or after **Module Date**, **Expiry Date** or **Created Time** from the drop down.

**Execution Time**

You may choose the exact time of execution by selecting the corresponding **hh** or **mm** of your organisation’s time zone.

**Execution Cycle**

You may choose the frequency of triggering a workflow by choosing **Once**, **Monthly** or **Yearly** from the drop down.

### Filter the Triggers

**Filter the Triggers** section allows you to set one or more conditions based on which the action will be executed.

**Field**

**Description**

**Condition**

The filter will be triggered based on the criteria you set. You can also add multiple criteria by clicking on **\+ Add Criteria** based on which the workflow rule will be executed.  
The condition for the next criteria may be **AND** or **OR** depending on whether you wish to include both or either one of the criteria. Also, you can change the criteria pattern as you want by selecting **Change Criteria**.

**Field Attributes**

The field is used to select an attribute from the list that broadly covers the terms that are related to the module.

**Rules**

Select the rules based on which the system should filter the trigger.

**Value Field**

Enter the value of the attribute for which the filter must be applied.

**Editing Criteria Pattern:**

You can edit the criteria pattern to suit your requirements by selecting **Change Criteria**. The editor allows you to define a pattern of your choice using simple AND/OR logic. For example, if you wish to trigger the workflow rule **When Quote Number is 1 AND either Quote Status isn’t Invoiced OR Total is equal to 500**,

The pattern is **(((1)AND 2) OR 3)**. If you feel the criteria pattern does not match your requirement, you can edit it to be **(1AND (2 OR 3))**.

Click **Save** to continue.

**Note:** You can have a maximum of 10 criteria for each Workflow Rule.

### Actions

Once the rules have been set, the actions to be taken upon encountering the conditions has to be decided. You can customize the actions to suit your business needs and program it to act immediately or at a particular time.

**Immediate Actions:**

**Field**

**Description**

**Type**

Select one of the three types of actions,  
\-Email Alerts  
\-Webhooks  
You can also add multiple actions by clicking on **+Add New Actions**.

**Name**

The field should contain the name of the Email Alert, or Webhooks. For example, in the case of an email alert, you can either pick the ones from the list you have already created or you can add a new one by selecting **\+ Add New Email Alert**.  
Follow the same steps for and Webhooks.

**Details**

The details of the action is displayed here.

**Time Based Actions:** If you wish to schedule actions for a particular time, select the check box next to **Would you like to add time based actions?**. This will display additional fields to enter the desired time.

**Field**

**Description**

**Execution Time**

Enter the desired number of days before or after,  
\-Rule Trigger Date  
\-Module Date  
\-Expiry Date  
\-Created Time  
\-Modified Time

Next, select the type of action that you wish to take. It can be an Email Alert, Field Update or a Webhook. You can also add multiple time based actions by selecting **+Add New Time Based Action**.

**Note:** You can add a maximum of 5 time-based actions. Also, each time-based action can have a maximum of 5 actions.

Finally, click **Save** to create the workflow rule to implement it for the modules in Zoho Billing.

### Other Actions

You can also mark your workflow rules as **Active** or **Inactive**. To do so, hover the cursor and select **Mark as Active** or **Mark as Inactive**. To delete the workflow rule, click the Trash icon.

**Edit a workflow rule:** You can edit a workflow rule by simply clicking on one of the workflow rules from the list or by hovering over a workflow rule and select **edit**.

**Filter workflow rules:** To filter the workflow rules list, follow these steps:

*   Navigate to _Settings_ > _Automation_ > _Workflow Rules_.
*   Under _Module_, select one from the drop down to filter the workflows based on the module for which the workflow has been created.

You can also filter workflow rules based on whether they are active or inactive. Based on your selection, the corresponding workflow rules will be displayed as a list.

**Note:** You can create a maximum of 10 Workflow Rules for each module.  
Workflow Rules cannot be applied on invoices that have been imported into Zoho Billing.

* * *

### Email Alerts

The following steps will explain how to set up an email alert for any module in Zoho Billing.

**Creating a New Email Alert:**  
To set up an email alert:

*   Go to _Settings_ **\> Automation > Email Alerts** and click on **\+ New Email Alert**.
*   Complete the following fields in the Email Alert creation page.

**Field**

**Description**

**Name**

Give a unique name for the email alert.

**Module**

Select the module for which you wish to create an email alert.

**Email Template**

You can pick a template from the drop down or click **\+ Add New Email Template** if you wish to create a new one.  

**Email Recipients**

Pick customers from the drop down, to whom you wish to send the email alerts.

**Additional Recipients**

If you wish to send out email alerts to more people, enter their email addresses separated by a comma. Please note that you can add a maximum of 10 additional recipients.

*   Click on **Save** to create a new email alert. You can now select one of the many email alerts created, from the drop down, to notify you when a workflow is triggered.

#### Other Actions in Email Alerts

**Delete an Email Alert:**

To delete an email alert:

*   Go to _Settings_ **\> Automation > Email Alerts**.
*   Hover the cursor next to an email alert on the list and click on the **Delete** icon.

**Filter Email Alert:**

To filter the email alerts list:

*   Go to _Settings_ **\> Automation > Email Alerts**.
*   Under **Module**, select a module from the drop down for which the email alert has been created.

Based on your selection, the corresponding email alerts will be displayed as a list.

**Notes:** You can create a maximum of 5 email alerts for each workflow rule.  
A maximum of 500 email alerts can be triggered per day.

* * *

### Webhooks

Webhooks facilitate communication with third-party applications by sending instant web notifications every time an event occurs in Zoho Billing. With Webhooks, you can configure HTTP & HTTPS URLs and associate them with workflow rules to automate the notification process.

For general information about webhooks, visit [webhooks.org](http://webhooks.org).

#### Create a Webhook

To set up a webhook:

*   Navigate to _Settings_ > _Automation_.
*   Select **Webhooks**.
*   Click **\+ New Webhook**.

*   On the _New Webhook_ page, enter the following details:
    
    *   Enter a name for the webhook in the **Name** field.
    *   Select the module for which you want to create the webhook from the dropdown next to the **Module** field.
    *   Add a description about the webhook in the **Description** field, if required.
*   In the **URL & Parameters** field, select the HTTP method and enter the URL of the third-party application. The HTTP methods available in Zoho Billing are listed below:
    
    *   **Post**: Requests that the data sent must be considered as new.
    *   **Put**: Requests that the data sent should be considered as a modified version of the one already present.
    *   **Delete**: Requests that the data must be deleted.
    
    ```
    <div class="tips-insight-img"></div>
    <b>Insight:</b>You can also add additional query parameters by clicking **Add Parameters** and entering the required values in the **Key** and **Value** fields. You can add custom parameters like Auth Token, Security Token, API Key, etc. 
    ```
    
*   Check **I want to secure this webhook** box if you want to secure your webhook. Enter the secret key in the **Secret Token** field. This will help to verify whether the webhook was sent from Zoho Billing. It should be alphanumeric and range between 12-50 characters.
    
    ```
    <div class="tips-note-img"></div>
    <b>Note:</b>You cannot edit or view the secret token later.
    ```
    
    ```
    <div class="tips-note-img"></div>
    <b>Note:</b> The secret token will be used to compute a hash value, so, you will have to ensure that the same token is available on your server to compute a similar hash value.
    ```
    
*   In the Headers section, you can include any additional information that you want to be included in the HTTP request. Click **\+ Add New Headers** if you want to add additional headers.
    
*   In the _Authorization Type_ section, choose how you want to authorize the webhook.
    
    *   **Self-Authorization**: Select this option to set up your webhook by providing the authorization details manually.
    *   **Connections**: Select this option to set up your webhook using a connection.
*   In the _Body_ section, choose how you want to send the data. You can choose between **Default Payload**, **x-www-form-urlencloded**, and **Raw** body parameters.
    
    *   **Default Payload**: In the default payload format, all the parameters associated with the module will be sent to the request body in the application/json format content type.
    *   **x-www-form-urlencoded**: In the x-www-urlencoded format, the data will be encoded and sent to the server.
    *   **Raw**: In the raw format, you can choose the parameters sent to the request body. The content type will be application/json.
*   Click **Save and Execute** to check if the webhook works properly, or click **Save** if you want to execute it later.
    
    **Note:** When you set up webhooks, all your customers’ details in your Zoho Billing organization (name, phone number, address, and email address) will be shared with the URL you want to notify.
    

#### Secure Your Webhooks

Securing your webhooks can help verify that the webhooks were sent from Zoho Billing. To do this, you have to set up your server so that it listens for webhooks from Zoho Billing. When your server receives a webhook from Zoho Billing, a hash value must be generated based on the payload and your secret token. Once done, check if it matches the hash value from Zoho Billing and thereby validate the source of the webhook. This can add a layer of security by enabling your server to disregard third-party webhooks pretending to originate from Zoho Billing.

#### Validate Webhooks

When your server receives the webhook, a hash value will have to be generated for the payload in the same way that Zoho Billing generated it. This is necessary to produce the same hash value to validate the webhook.

The following parameters (if available) are used to generate the hash value:

*   Query string parameters.
*   Default payload or customized raw JSON payload.
*   x-www-form-urlencoded payload (key-value pairs).

Construct a string by sorting the payload’s key-value pairs in alphabetical order. The pairs must be sorted in alphabetical order with respect to their keys.

*   If your webhook contains **query string parameters**, ensure that those key-value pairs are sorted along with the payload’s key-value pairs.
*   There cannot be any spaces between the key-value pairs.

Once you’ve sorted the key-value pairs and constructed the string, append the raw JSON to the end of the string.

**Examples**

1\. **Default Payload**

Query string parameters’ key-value pairs:

```
subscription\_id=90343, name=basic
```

Default payload/raw JSON:

```
{"created\_date":"2023-10-11","event\_id":"5675"}
```

The constructed string would be:

```
namebasicsubscription\_id90343{"created\_date":"2023-10-11","event\_id":"5675"}
```

2\. **x-www-form-urlencoded**

Query string parameters’ key-value pairs:

```
customer\_name=Brandon, status=active
```

x-www-form-urlencoded payload’s key-value pairs:

```
addon\_description=Monthly addon, quantity=1
```

The constructed string would be:

```
addon\_descriptionMonthly addoncustomer\_nameBrandonquantity1statusactive
```

**Pro Tip**

*   If your payload is in the x-www-form-urlencoded format, the entire string must be decoded before generating the hash value.
*   If one of the key value pairs contains spaces, the spaces must also be included in the constructed string.

The hash value can be computed by applying the HMAC-SHA256 algorithm on this string, along with the secret token that was used in Zoho Billing.

You can then validate the webhook by checking if the hash value computed from your side matches the one in the header (X-Zoho-Webhook-Signature) of the webhook from Zoho Billing.

### Configuring SMS Gateways 

You can set up webhooks to send and receive message alerts through SMS gateways. All you have to do is configure the SMS gateways using the URL and follow the steps provided below.

#### Bulk SMS

Bulk SMS is a popular SMS Gateway and is compatible with over 800 mobile network providers, worldwide.

```
URL: https<nolink>://bulksms.vsms.net/eapi/submission/send_sms/2/2.0?username=`%username%`&password=`%password%`&msisdn=${CONTACT.CONTACT_MOBILE_PHONE}&message=%message_content%</nolink>
```

To configure the URL for Bulk SMS:

*   Navigate to _Settings_ > _Automation_ > _Webhooks_.
*   Click **\+ New Webhook**.
*   Copy the above URL into **URL to notify**.
*   Replace **%username%** and **%password%** placeholders in the URL with the username and password of your Bulk SMS account.
*   Type your message at the end of the URL, i.e. after “**message=**". 
*   Replace all the blank spaces in your message content by **%20** and all the commas by **%2C**.

**Note**: If there are other punctuations in your message content, you can check how to replace them with modifiers from [this website](https://meyerweb.com/eric/tools/dencoder/). However, ensure that you do not replace punctuations that are essential to the message’s syntax.

After formatting your message with %20 for blank spaces and %2C for commas, it should look like this:

```
> URL: https<nolink>://bulksms.vsms.net/eapi/submission/send_sms/2/2.0?username=`%username%`&password=`%password%`&msisdn=${CONTACT.CONTACT_MOBILE_PHONE}&message=Hello%20${CONTACT.CONTACT_NAME}.Thank%20you%20for%20the%20purchase%20of%20${INVOICE.INVOICE_TOTAL}</nolink>
```

**Similarly, other SMS gateways can be configured, with only the URL being different.** 

#### SMS-Magic

SMS gateways such as SMS-Magic requires you to enter additional entity parameters to configure the webhook.

To configure SMS-Magic:

*   Enter the URL **https://sms-magic.in/smapi/post** in the **URL** to notify field.
*   Click **+Add Entity Parameter**.
*   Enter the following text in the parameter field:

```
<?xml version="1.0"?>
<m:Library xmlns:m="http://screen-magic.com" xmlns="http://www.defns.com">
<userid>**User_ID**</userid>
<senderid>**%Sender_ID**</senderid>
<accountid>**%Account_ID**</accountid>
<hashkey>**%hashkey%**</hashkey>
<message mobilenumber="${CONTACT.CONTACT_MOBILE_PHONE}" >
<![CDATA[${INVOICE.INVOICE_TOTAL}]]>
</message>
</m:Library>
```

Replace the placeholders in the URL with the User ID, Sender ID and Account ID of your SMS-Magic account. The hashkey refers to a standard hashed md5 value of a string that is a concatenation of your User ID, Password, Account ID and Sender ID.

**Note:** To generate the hashed md5 value, you can visit [this site](https://www.md5hashgenerator.com/). 

#### Text Local

Text Local requires an entity parameter and a custom parameter to function.

To configure Text Local:

*   Enter the URL **http://api.textlocal.in/send/** in the **URL to notify** field.  
*   Click **\+ Add Custom Parameter**.
*   Add the **sender** and **apikey** parameter and replace the placeholders in the URL with the relevant information from Text Local.
*   Click **\+ Add Entity Parameter**.
*   Give a name for the parameter and select the required conditions from the dropdown menu. Example: numbers = ${CONTACT.CONTACT\_MOBILE\_PHONE} 
*   Select **Add User Defined Parameters** and enter the message to be sent along with all the necessary place holders. 
*   Click **Save**.

#### Other Actions

##### Delete Webhooks

To delete a webhook:

*   Navigate to _Settings_ > _Automation_ > _Webhooks_.
*   Hover over the webhook that you want to delete.
*   Click **Delete**.
*   In the pop up that appears, click **Yes**.

The webhook will be deleted. If you’ve used in the webhook in a workflow rule, ensure that you update the workflow rule as the workflow rule might not get triggered.

##### Filter Webhooks

To filter the webhooks list, follow these steps:

*   Navigate to _Settings_ > _Automation_ > _Webhooks_.
*   Under Module, select a module from the drop down for which the webhook has been created.

Based on your selection, the corresponding webhook will be displayed as a list.

*   You can create only 1 webhook for each workflow rule.
*   A maximum of 500 webhooks can be triggered per day.

* * *

## Events

_Events_ enables you resend/check the status of your webhooks in Zoho Billing.

To check the status of your webhook:

*   Use the filter to sort your webhooks based on their status.

To resend a webhook,

*   Navigate to _Events_ tab and click the event for which the webhook has to be sent again.
    
*   Click **Resend** to resend the webhook.
    

* * *

## Custom Functions

*   [What is Deluge?](/billing/help/settings/automation.html#what-is-deluge)
*   [Creating and Executing a Custom function](/billing/help/settings/automation.html#create-execute-custom-function)
*   [Default fields](/billing/help/settings/automation.html#default-fields)
    *   [User](/billing/help/settings/automation.html#user)
    *   [Organization](/billing/help/settings/automation.html#organization)
    *   [Quote](/billing/help/settings/automation.html#quote)
    *   [Invoice](/billing/help/settings/automation.html#invoice)
    *   [Customer](/billing/help/settings/automation.html#customer)
    *   [Recurring Invoice](/billing/help/settings/automation.html#recurring-invoice)
    *   [Expense](/billing/help/settings/automation.html#expense)
    *   [Item](/billing/help/settings/automation.html#item)

**Custom Functions** in Zoho Billing allows you to write small pieces of code to automate your business processes. Be it providing a special discount on your customers’ invoice, or adding a late fee when an invoice becomes overdue, all you have to do is write a piece of code using Deluge script and link it to a workflow rule and automation of the process will be taken care of.

### What is Deluge?

**Deluge(Data Enriched Language for the Universal Grid Environment)** is an online scripting language integrated with Zoho Creator. It enables users to add logic to the application, incrementally, making it more powerful and robust.

### Creating and Executing a Custom Function

To setup a custom function,

*   Navigate to _Settings_ > _Automation_ > _Custom Functions_ and click **\+ New Custom Function**.
*   Enter a name for your custom function and provide a small description.
*   Choose the module for which you wish to create the custom function.
*   Now, type in or drag the parameters that are mentioned on the left side of the script-box.
*   Choose the parameters of your choice and set the conditions for your custom function.
*   Once done, click **Save** for the changes to take effect.

Now, the next step is to create a workflow rule using the newly created custom function.

*   Head back to _Automation_ and click **Workflow Rules**.
*   Create a new workflow and set the triggers.
*   Now, under the _Actions_ tab, choose **Custom functions** and select your newly created custom function.
*   Click **Save**.

Now, whenever the criteria is met, the workflow rule will be triggered, which in turn will trigger the custom function.

### Default Fields

As of now, custom functions support User, Organization, Quote, Invoice, Customer, Recurring Invoice, Expense and Item modules.

These modules will have the following fields from which you can get the necessary parameters for your custom function.

#### User

The user field supports the following parameters:

Key Fields

Description

name

Name of the user

zuid

ZUID of the user

#### Organization

The organization map supports the following fields:

Key Fields

Description

organization\_id

Your organization ID

name

Organization name

time\_zone

Time zone of your organization

language\_code

Organization’s language

date\_format

Your organization’s date format

currency\_id

Currency ID

currency\_code

Currency code

currency\_symbol

Currency symbol

address

Organization address

phone

Organization’s contact number

fax

Fax number

website

Organization URL

email

Email address

portal\_name

Portal name of your organization

**Sample Map:**

```
{
	"time_zone": "Asia/Calcutta",
	"language_code": "en",
	"currency_id": "7605000000000099",
	"phone": "99999999999",
	"fax": "check",
	"website": "",
	"email": "charles@zylker.com",
	"address": {
		"zip": "624001",
		"country": "India",
		"city": "New Delhi",
		"street_address2": "Block 15",
		"street_address1": "6/35 Garden Lane,",
		"state": "Delhi"
	},
	"organization_id": "12345678",
	"name": "Zlyker Industries",
	"date_format": "dd MMM yyyy",
	"currency_symbol": "Rs.",
	"portal_name": "zylkerindustry",
	"currency_code": "INR"
}
```

#### Quote

The quote map supports the following fields:

Key Fields

Description

quote\_id

Quote ID

quote\_number

Your quote number

date

Quote date

reference\_number

Reference number of your Quote

status

Status of your quote

customer\_id

ID of the customer who is assigned to the quote

customer\_name

Your customer name

currency\_id

Currency ID

currency\_code

Currency code

currency\_symbol

Currency symbol

exchange\_rate

Exchange rate involved in the quote

expiry\_date

Expiry date of the quote

discount\_amount

Discount amount

discount

Discount

shipping\_charge

Shipping charge entered in the quote

adjustment

Adjustments

sub\_total

Sub total of the quote

total

Quote total

tax\_total

Total tax amount in the quote

billing\_address

Billing address of the customer

shipping\_address

Shipping address of the customer

notes

Notes

terms

Terms and conditions

custom\_fields

Quote custom fields

salesperson\_id

ID of the salesperson

salesperson\_name

Name of the salesperson

**Sample Map:**

```
{
	"total": "12000.0",
	"terms": “checking",
	"quote_id": "7605000000320001",
	"date": "2016-06-03",
	"quote_number": "EST-000026",
	"shipping_address": {
		"zip": "94588",
		"country": "USA",
		"address": "4910 Hopyard Rd",
		"city": "Pleasanton",
		"state": "CA",
		"fax": “Fax Number”
	},
	"salesperson_name": “Salesperson”,
	"adjustment": "0.0",
	"currency_symbol": "Rs.",
	"salesperson_id": "7605000000336089",
	"currency_code": "INR",
	"shipping_charge": "0.0",
	"custom_fields": [
		{
			"customfield_id": "7605000000190011",
			"is_active": true,
			"show_in_all_pdf": false,
			"value_formatted": "Check-6",
			"data_type": "autonumber",
			"index": 1,
			"label": "auto number",
			"show_on_pdf": false,
			"value": "Check-6"
		}
	],
	"currency_id": "7605000000000099",
	"exchange_rate": "1.0",
	"status": "invoiced",
	"sub_total": "12000.0",
	"customer_name": “Customer”,
	"discount_amount": "0.0",
	"discount": "0.0",
	"tax_total": "0.0",
	"reference_number": “Ref number”,
	"notes": "Looking forward for your business.",
	"expiry_date": "2016-06-03",
	"customer_id": "7605000000258011",
	"billing_address": {
		"zip": "94588",
		"country": "USA",
		"address": "4910 Hopyard Rd",
		"city": "Pleasanton",
		"state": "CA",
		"fax": "Fax Number"
	}
}
```

#### Invoice

The invoice map supports the following fields:

Key Fields

Description

due\_date

Invoice due date

payment\_expected\_date

Expected payment date for the invoice

reference\_number

Reference number of the invoice

customer\_id

Customer ID

customer\_name

Name of the customer who is assigned to the invoice

currency\_id

Currency ID

currency\_code

Currency code

currency\_symbol

Currency symbol

exchange\_rate

Exchange rate involved in the invoice

discount\_amount

Discount amount involved in the invoice

discount

Discount involved in the invoice

shipping\_charge

Shipping charge entered in the invoice

adjustment

Adjustments

sub\_total

Sub total of the invoice

tax\_total

Total tax amount in the invoice

total

Total amount

balance

Balance

price\_precision

Number of Decimal places

billing\_address

Billing address of the customer

shipping\_address

Shipping address of the customer

notes

Notes

terms

Terms and conditions

custom\_fields

Invoice custom fields

salesperson\_id

ID of the salesperson

**Sample Map:**

```
{
	"total": "0.0",
	"payment_terms": "0",
	"terms": “Checking”,
	"price_precision": "2",
	"payment_expected_date": "2016-06-31”,
	"date": "2016-06-30",
	"shipping_address": {
		"zip": "94588",
		"country": "USA",
		"address": "4910 Hopyard Rd",
		"city": "Pleasanton",
		"state": "CA",
		"fax": "Fax Number"
	},
	"balance": "0.0",
	"adjustment": "0.0",
	"currency_symbol": "Rs.",
	"salesperson_id": “7605000000336089”,
	"currency_code": "INR",
	"shipping_charge": "0.0",
	"custom_fields": [
		{
			"customfield_id": "7605000000336081",
			"is_active": true,
			"show_in_all_pdf": false,
			"value_formatted": "INV-8",
			"data_type": "autonumber",
			"index": 1,
			"label": "AutoNumber",
			"show_on_pdf": false,
			"value": "INV-8"
		},
		{
			"customfield_id": "7605000000351027",
			"is_active": true,
			"show_in_all_pdf": true,
			"value_formatted": "01 Aug 2016",
			"data_type": "date",
			"index": 2,
			"label": "Date",
			"show_on_pdf": true,
			"value": "2016-08-01"
		}
	],
	"currency_id": "7605000000000099",
	"exchange_rate": "1.0",
	"status": "draft",
	"sub_total": "12000.0",
	"customer_name": “Customer”,
	"invoice_number": "INV-000087",
	"discount_amount": "12000.0",
	"discount": "100.00%",
	"tax_total": "0.0",
	"reference_number": “checking”,
	"due_date": "2016-06-30",
	"invoice_id": "7605000000369043",
	"notes": "Thanks for your business.",
	"customer_id": "7605000000258011",
	"billing_address": {
		"zip": "94588",
		"country": "USA",
		"address": "4910 Hopyard Rd",
		"city": "Pleasanton",
		"state": "CA",
		"fax": "Fax Number"
	}
}
```

#### Customer

The customer map supports the following fields:

Key Fields

Description

owner\_id

ID of associated owner

billing\_address

Billing address associated to customer

source

Source of the customer

contact\_id

Contact ID

payment\_terms

Payments terms associated to customer

currency\_code

Currency code

language\_code

Language code

contact\_type

Type of the contact

twitter

Twitter info

zcrm\_contact\_id

ID of the contact in Zoho CRM

shipping\_address

Shipping address associated to customer

pricebook\_id

ID of pricebook associated

contact\_name

Name of contact

website

Website of contact

owner\_name

Name of contact owner

currency\_symbol

Currency symbol

zcrm\_account\_id

ID of Zoho CRM account

custom\_fields

Custom fields associated with customer

facebook

Facebook info

pricebook\_name

Name of pricebook associated

primary\_contact\_id

ID of orimary contact

company\_name

Name of the company

contact\_salutation

Contact salutation

crm\_owner\_id

ID of CRM owner

currency\_id

Currency ID

payment\_terms\_label

Payment terms label

status

Status

**Sample Map:**

```
{
	"owner_id": "",
	"shipping_address": {
		"zip": "94588",
		"country": "USA",
		"address": "4910 Hopyard Rd",
		"city": "Pleasanton",
		"state": "CA",
		"fax": "Fax Number"
	},
	"source": "user",
	"contact_id": "7605000000197147",
	"payment_terms": "0",
	"currency_code": "INR",
	"language_code": "en",
	"contact_type": "customer",
	"twitter": "",
	"zcrm_contact_id": "",
	"billing_address": {
		"zip": "94588",
		"country": "USA",
		"address": "4910 Hopyard Rd",
		"city": "Pleasanton",
		"state": "CA",
		"fax": "Fax Number"
	},
	"pricebook_id": "",
	"contact_name": "Arun",
	"website": "www.zoho.com",
	"owner_name": "",
	"currency_symbol": "Rs.",
	"zcrm_account_id": "418070000000135001",
	"custom_fields": [
		{
			"customfield_id": "7605000000063049",
			"is_active": true,
			"show_in_all_pdf": false,
			"value_formatted": "1234",
			"data_type": "number",
			"index": 1,
			"label": "Unpaid Invoices",
			"show_on_pdf": false,
			"value": "1234"
		}
	],
	"facebook": "",
	"pricebook_name": "",
	"primary_contact_id": "7605000000197149",
	"company_name": "Zoho",
	"contact_salutation": "",
	"crm_owner_id": "",
	"currency_id": "7605000000000099",
	"payment_terms_label": "Due on Receipt",
	"status": "active"
}
```

### Expense

The expense map supports the following fields:

Key Fields

Description

date

Date

payment\_mode

Mode of payment

custom\_fields

Expense custom fields

is\_billable

Billability of the expense

line\_items

Line items in the expense

project\_name

Name of the project involved

reference\_number

Reference number of the expense

currency\_code

Currency code

total

Total

project\_id

ID of the project involved

sub\_total

Sub-total on the expense

customer\_name

Name if the customer involved

customer\_id

ID of the customer involved

expense\_id

Expense ID

currency\_id

Currency ID

**Sample Map:**

```
{
	"date": "2016-10-08",
	"payment_mode": "Cash",
	"custom_fields": "[]",
	"is_billable": "true",
	"line_items": [{"tags":[],"tax_name":"Standard Rate","item_order":1,"tax_type":"tax","account_id":"348960000000000400","description":"Notes","tax_amount":16.67,"product_type":"goods","tax_id":"348960000000044037","line_item_id":"348960000000184015","tax_percentage":20,"item_total":83.33,"account_name":"Office Supplies"}],
	"project_name": "",
	"reference_number": "12345",
	"currency_code": "GBP",
	"total": "100.0",
	"project_id": "",
	"sub_total": "83.33",
	"customer_name": "Accounts",
	"customer_id": "348960000000111017",
	"expense_id": "348960000000184003",
	"currency_id": "348960000000000103"
}
```

### Item

The item map supports the following fields:

Key Fields

Description

item\_id

Item ID

custom\_fields

Item custom fields

tax\_name

Name of the tax involved

zcrm\_product\_id

ID of the product in Zoho CRM

tax\_id

ID of the tax involved

unit

Unit of the item

account\_id

Sales account ID

tax\_type

Type of the tax involved

rate

Sales rate of the item

account\_name

Name of the sales account involved

name

Name of the item

tax\_percentage

Percentage of tax involved

pricebook\_rate

Pricebook rate

sku

SKU of the item

status

Status of the item

**Sample Map:**

```
{
	"item_id": "348960000000051011",
	"custom_fields": [{"value_formatted":"100","index":1,"is_active":true,"data_type":"decimal","show_on_pdf":true,"value":100,"show_in_all_pdf":true,"label":"Profit","customfield_id":"348960000000134003"}],
	"tax_name": "",
	"zcrm_product_id": "1665395000000205001",
	"tax_id": "",
	"unit": "1",
	"account_id": "348960000000000388",
	"tax_type": "",
	"rate": "1000.0",
	"account_name": "Sales",
	"name": "Item",
	"tax_percentage": "0",
	"pricebook_rate": "1000.0",
	"sku": "SKU",
	"status": "active"
}
```

A few example explaining how these fields would help in fetching the necessary paramters:

**Example 1:**

To fetch quote id, use:

```
quoteid = quote.get("quote_id");
```

**Example 2:**

To fetch your organization name, use:

```
orgid = organization.get("name");
```

**Example 3:**

To fetch a user’s name and ZUID, use:

```
username = user.get("name");
zuid = user.get("zuid");
```

To know more about different scenarios where custom functions could be useful, refer our [**Custom Function Scenarios**](/billing/help/settings/automation.html#custom-functions) page.

* * *

## In-App Notifications

The In-app Notification feature allows you to automatically send notifications to the users within your organization regarding a specific action. The notification can be sent either once or every time an action is carried out.

You can create an in-app notification and set up the workflow in such a way that, every time a particular action occurs, the workflow gets carried out and the in-app notification flashes within the product.

To create an in-app notification,

*   Navigate to _Settings_ > _Automation_ > _In-app Notifications_.
*   Click **\+ New In-app Notification**.
*   Provide a name for your In-app notification in the **Name** field.
*   Choose the target module from the _Module_ drop-down. The in-app notification will be triggered when the defined action gets carried out here.
*   Choose the users who need to be notified from the **Recipients** field.
*   Enter the message that needs to be to appear as a notification. You can add placeholders to your messages by choosing them from **Insert Placeholders** drop down.
*   Click **Save**.

This is how the notification appears within the product.

* * *

## Schedules

Zoho Billing lets you create and run predefined tasks at the specified time intervals using Schedules. You can create your tasks using a deluge script and schedule this task to be executed at a particular time or on a recurring basis.

**Note:** This feature is currently available only in certain plans. Reach out to our support team at \[support@zohobilling.com\](mailto:support@zohobilling.com).

*   [Scenarios](/billing/help/settings/automation.html#scenario)
*   [Creating New Schedules](/billing/help/settings/automation.html#scheduler)
*   [Sample Function](/billing/help/settings/automation.html#sample)

### Scenarios

Here are a few scenarios where schedules can be created to execute custom actions. However, you can create schedules based on your firm’s requirements.

**Scenario 1:** Peter runs a supermarket. At the end of every month, he wants to give a 10% off on the Next Purchase to customers whose total purchase for the month exceeds a certain amount, let's say 1000. Peter creates a schedule to email this to selective customers on the last day of the month.

**Scenario 2:** Peter uses a third party application for maintaining customer and employee database internally. He would like to sync all data from Zoho Billing to the other application periodically. To do so, he creates a custom schedule to sync the data at 6 pm every day.

**Scenario 3:** Peter sets a quarterly sales target for his territorial managers. Every four months, he has to send them their Profit and Loss reports and a congratulatory email when they have achieved their target or a motivating email for them to perform better. He writes a function and schedules it to be sent to his staff once every 4 months.

### Creating New Schedules

To create a new schedule:

*   Navigate to _Settings_ > _Automation_ > _Schedules_ > **\+ New Schedule**.
    
*   Enter a **Name** for your schedule.
    
*   Set the **Frequency** and recurrence pattern for the schedule to be executed. This can be daily, weekly, monthly or yearly.
    
    **Insight:** The recurrence pattern lets you decide when the schedule should be executed. You can choose to execute it on the set frequency.
    
*   Select how frequently the task should be executed.
    
    *   **Daily**: The task will be executed every day (or based on your recurrence pattern). You can choose to exclude the weekends.
        
    *   **Weekly**: The task will be executed once a week. Select the day of the week on which the task should be executed.
        
    *   **Monthly**: Task will be executed once a month. This can be a specific date or a day in a month. For example, you can choose to execute it on the 5th of every month or the Second Saturday of every month.
        
    *   **Yearly**: Task will be executed once a year. You can select the month and specify the date of execution or specify the day. For example, the task can be executed on the first Sunday in January or just January 5.
        
*   Set the **Start Date and Time**.
    
    **Warning:** The start date of a schedule cannot be more than one year from the creation date.
    
*   Select when the schedule should expire. It can expire after a number of executions or on a set date or not expire at all.
    
*   Drag and drop options to create a [**Deluge function**](/deluge/help/) that will help to create your function.
    
    **Insight:** Deluge (Data Enriched Language for the Universal Grid Environment) is an online scripting language integrated with Zoho Services. It enables you to write your own functions that lets you modify the application to suit your needs, incrementally, making it more powerful and robust.
    
*   Click **Save** or **Save and Execute** to run it.
    
    **Insight:** You can create a maximum of 10 schedules.
    

### Sample Function:

Here’s a sample function for [Scenario 1](#scenario):

```
organizationID = organization.get("organization_id");
name = organization.get("name");
orgEmail = organization.get("email");
salesResponse = invokeUrl
 [
 url: "https://billing.zoho.com/api/v3/reports/salesbycustomer?organization_id=" + organizationID + "&from_date=" + toStartOfMonth(today).toString("YYYY-MM-dd") + "&to_date=" + eomonth(today,0).toString("YYYY-MM-dd")
 type: GET
 connection: "billing_api_connection"
 ];
salesDetails = salesResponse.get("sales").toList();

for each  sales in salesDetails
{
	amount = sales.get("sales_with_tax");
	if(amount > "<ENTER AMOUNT>")
	{
		customerName = sales.get("customer_name");
    customerResponse = invokeUrl
     [
     url: "https://billing.zoho.com/api/v3/customers/" + sales.get("customer_id") + "?organization_id=" + organizationID
     type: GET
     connection: "billing_api_connection"
     ];
    customerDetails = customerResponse.get("contact");
		customerEmail = customerDetails.get("email");
		sendmail
		[
			from :zoho.adminuserid
			to :customerEmail
			subject :"Thank you for shopping! Here's a 10% discount!"
			message :"<div>Dear&nbsp;" + customerName + ",<br></div><div><br></div><div>We just wanted to take a moment of our time to thank you for your continuous support.<br></div><div><br></div><div> Based on your recent purchases, we'd like to offer you a 10% off on your next purchase with us.&nbsp;<br></div><div><br></div><div>Please show this email during billing to avail this discount!<br></div><div><br></div><div>Regards,<br></div><div>" + name + "<br></div><div><br></div><div><br></div><div><br></div><div><br></div>"
		]
	}
}
```