Blog
2025-08-06 14:37

When the standard Zoho CRM and Books integration isn’t enough: a ready-to-use script for a custom solution

🧩 Custom Integration of Zoho CRM and Zoho Books: When Standard Solutions Aren’t Enough

Integration of Zoho CRM and Zoho Books is a task that seems to have already been solved within the Zoho ecosystem itself. There are standard connections, automatic synchronization of contacts and invoices. But in practice, there are often scenarios where this is not enough:

  • Additional fields need to be transferred to the invoice
  • Special logic for work with currencies is required
  • The client wants only active contacts or specific items to be transferred
  • It is necessary to choose when exactly to create an invoice, and do it manually via a button.

In such cases, Deluge and the Zoho API come to the rescue. Today, I’ll show you how to transfer an invoice from the Invoices module in Zoho CRM directly into Zoho Books using a custom scenario. The code is ready to use — you can copy, modify, and implement it in your setup.

📌 What the Script Does

  • Gets invoice data from Zoho CRM by ID
  • Finds the contact in Zoho Books by client name
  • Selects a product by name and currency by ISO code
  • Builds the line_items structure for Zoho Books
  • Creates a new invoice in Zoho Books with the required fields

🧠 What You Should Know Before Using It

  • The script uses Deluge and is executed through a button function
  • Connections (connection:"crm" and connection:"books") must be configured in advance in Zoho Connections
  • The organization_id of your Zoho Books account must be inserted, it must be obtained from the settings and replaced with your own
  • Works with fields from the standard Invoices module, if necessary, adapt to your structure
string button.SendInvoieToBooks(String ID)
{
    info ID;

    // Получаем инвойс из CRM
    Invoice = invokeurl
    [
        url :"https://www.zohoapis.com/crm/v8/Invoices/" + ID
        type :GET
        connection:"crm"
    ];
    Invoice = Invoice.get("data").get(0);

    AccountName = Invoice.get("Account_Name").get("name");
	
    // Ищем контакт в Zoho Books
    organization_id = "ВАШ_ORG_ID";
    response = invokeurl
    [
        url :"https://www.zohoapis.com/books/v3/contacts?organization_id=" + organization_id + "&contact_name=" + AccountName
        type :GET
        connection:"books"
    ];
    response = response.get("contacts");
    for each  rec in response
    {
        if(rec.get("status").contains("inactive") == false)
        {
            contactID = rec.get("contact_id");
        }
    }

    // Подготовка данных
    invoice_number = Invoice.get("Invoice_Number");
    date = Invoice.get("Invoice_Date");
    due_date = Invoice.get("Due_Date");
    Product_Details = Invoice.get("Invoiced_Items");
    Currency = Invoice.get("Currency");

    if(Currency == "USD") currency_id = "ID_ДЛЯ_USD";
    if(Currency == "RUB") currency_id = "ID_ДЛЯ_RUB";
    if(Currency == "EUR") currency_id = "ID_ДЛЯ_EUR";
    if(Currency == "AED") currency_id = "ID_ДЛЯ_AED";

    listVar = List();
    for each  rec in Product_Details
    {
        ProductName = rec.get("Product_Name").get("name");
        response = invokeurl
        [
            url :"https://www.zohoapis.com/books/v3/items?organization_id=" + organization_id + "&name_startswith=" + ProductName
            type :GET
            connection:"books"
        ];
        ProductID = response.get("item_id");

        mapVar = Map();
        mapVar.put("item_id",ProductID);
        mapVar.put("name",ProductName);
        mapVar.put("rate",rec.get("List_Price"));
        mapVar.put("quantity",rec.get("Quantity"));
        listVar.add(mapVar);
    }

    // Создаём инвойс в Zoho Books
    values = Map();
    values.put("invoice_number",invoice_number);
    values.put("customer_id",contactID);
    values.put("currency_id",currency_id);
    values.put("date",date);
    values.put("due_date",due_date);
    values.put("line_items",listVar);

    response = zoho.books.createRecord("Invoices",organization_id,values,"books");
    return response.get("message");
}

🛠 How to Set It Up

  1. Set up connections (crm and books) in the Connections section
  2. Replace organization_id and currency_id with your own
  3. Add the function as a button in the Invoices module
  4. Make sure that the products in the CRM have the correct name and price

📚 Conclusion

Integration between Zoho CRM and Zoho Books via Deluge provides full control over the process. This approach is especially useful when standard integration doesn’t reflect your business logic. You can adapt the code from this article to any task: tax accounting, custom statuses, additional verification, etc.

The script in this article can be customized for any purpose — tax handling, custom statuses, additional checks, and more.

If you need a more complex solution or integrations with other Zoho products — reach out to us. We help companies customize Zoho for their real business, not the other way around.