Set up Late Fees in Zoho Books
This is a question that had been asked many times in the Zoho support forums with no clear answer. Here it is:
organizationId = "ADD YOUR ORGID";
// Use your actual organization ID
webhookUrl = "ADD YOUR WEBHOOK URL";
// Fetching all invoices from Zoho Books
invoiceresp = invokeurl
[
url :"https://books.zoho.eu/api/v3/invoices?organization_id=" + organizationId
type :GET
connection:"zbooks"
];
invoices = invoiceresp.get("invoices");
currentdate = zoho.currentdate;
for each ele in invoices
{
cf_due_date = ifnull(ele.get("due_date"),"");
if(cf_due_date != "")
{
due_date = cf_due_date.toDate();
if(due_date < currentdate)
{
// Checking if the invoice is overdue
invoice_id = ele.get("invoice_id");
grandTotal = ele.get("total");
// Prepare the payload for the webhook
// No need to convert map values to string here
payload = Map();
payload.put("invoiceID",invoice_id + "");
// Ensure it's treated as a string
payload.put("grandTotal",grandTotal + "");
// Ensure it's treated as a string
// Sending the payload via POST request to the Zoho Flow webhook
// Note: Directly pass the map, and specify application/json
postResponse = postUrl(webhookUrl,payload,{"Content-Type":"application/json"});
// Log the response for debugging
info postResponse.toString();
}
}
}