Zoho Deluge: Integrating Zoho Inventory with Zoho CRM – Simplified and Streamlined

Welcome to this easy-to-use script designed to bridge your Zoho Inventory and Zoho CRM platforms seamlessly. Our goal is to make your data management process as efficient as possible, ensuring that product information in Zoho Inventory reflects accurately in Zoho CRM.

Before You Begin:

  • Connection Setup: Ensure you have an active connection in your Zoho setup and have obtained the necessary refresh token.
  • CRM Custom Field: The script requires the “Zoho_inventory_ID” field in your Zoho CRM Products module. Please add this field before proceeding.
  • Customisation: There are highlighted sections within the script where you need to input your specific details.

It is advisable to run this in a Workflow in Zoho Inventory to trigger on the creation of a new product in Zoho Inventory

item_id = item.get("item_id");
item_info = invokeurl
[
url :"https://www.zohoapis.com.au/inventory/v1/items/" + item_id + "?organization_id=xxxxxxx"
type :GET
connection:"inventory_connection"
];
items = item_info.getJSON("item");
item_name = ifnull(items.getJSON("name"),"");
item_unit = ifnull(items.getJSON("unit"),"");
item_stat = ifnull(items.getJSON("status"),"");
if(item_stat == "active")
{
item_status = true;
}
item_description = ifnull(items.getJSON("description"),"");
item_manufacturer = ifnull(items.getJSON("manufacturer"),"");
item_purchase_account_name = ifnull(items.getJSON("purchase_account_name"),"");
item_purchase_description = ifnull(items.getJSON("purchase_description"),"");
item_product_type = ifnull(items.getJSON("product_type"),"");
item_stock_on_hand = ifnull(items.getJSON("stock_on_hand"),"");
item_Cost_Price = ifnull(items.getJSON("purchase_rate"),"");
item_selling_price = ifnull(items.getJSON("rate"),"");
item_actual_available_stock = ifnull(items.getJSON("actual_available_stock"),"");
item_SKU = ifnull(items.getJSON("sku"),"");
item_UPC = ifnull(items.getJSON("upc"),"");
item_EAN = ifnull(items.getJSON("ean"),"");
item_ISBN = ifnull(items.getJSON("isbn"),"");
item_sales_account_name = ifnull(items.getJSON("account_name"),"");
item_reorder_level = ifnull(items.getJSON("reorder_level"),"");
item_cf_category = ifnull(items.getJSON("custom_field_hash").getJSON("cf_category"),"");
item_dimension_unit = ifnull(items.getJSON("package_details").getJSON("dimension_unit"),"");
item_length = ifnull(items.getJSON("package_details").getJSON("length"),"");
item_width = ifnull(items.getJSON("package_details").getJSON("width"),"");
item_height = ifnull(items.getJSON("package_details").getJSON("height"),"");
item_dimension = item_length + " " + item_dimension_unit + " x " + item_width + " " + item_dimension_unit + " x " + item_height + " " + item_dimension_unit;
item_weight_unit = ifnull(items.getJSON("package_details").getJSON("weight_unit"),"");
item_weight = ifnull(items.getJSON("package_details").getJSON("weight"),"");
item_total_weight = item_weight + " " + item_weight_unit;
item_inventory_account_name = ifnull(items.getJSON("inventory_account_name"),"");
// ==============================================================
token_res = invokeurl
[
url :"https://accounts.zoho.com.au/oauth/v2/token?refresh_token=xxxx&client_id=xxxx&client_secret=xxxx&grant_type=refresh_token"
type :POST
];
access_token = token_res.get("access_token");
header = Map();
header.put("Authorization","Bearer " + access_token);
products_map = Map();
products_map.put("Zoho_inventory_ID",item_id);
products_map.put("Product_Name",item_name);
products_map.put("Usage_Unit",item_unit);
products_map.put("Product_Active",item_status);
products_map.put("Unit_Price",item_Cost_Price);
products_map.put("Selling_Price",item_selling_price);
products_map.put("Manufacturer",item_manufacturer);
products_map.put("Sales_Account",item_sales_account_name);
products_map.put("Purchase_Account",item_purchase_account_name);
products_map.put("Description",item_purchase_description);
products_map.put("Inventory_Type",item_product_type);
products_map.put("Stock_on_Hand",item_stock_on_hand);
products_map.put("Qty_in_Stock",item_actual_available_stock);
products_map.put("Product_Code",item_SKU);
products_map.put("UPC",item_UPC);
products_map.put("EAN",item_EAN);
products_map.put("ISBN",item_ISBN);
products_map.put("Reorder_Level",item_reorder_level);
products_map.put("Product_Category",item_cf_category);
products_map.put("Dimension",item_dimension);
products_map.put("Weight",item_total_weight);
products_map.put("Inventory_Account",item_inventory_account_name);
data = Map();
data.put("data",products_map.toList());
crm_response = invokeurl
[
url :"https://www.zohoapis.com.au/crm/v3/Products"
type :POST
parameters:data.toString()
headers:header
];