// Define the function to send data to Synthflow and handle the response
function sendToSynthflow(lead) {
// Set up headers with the API key
map headers = {"Authorization": "****"};
// Prepare the JSON data payload
map jsonData = {
"model" : "***",
"firstName" : lead.get("First_Name"),
"lastName" : lead.get("Last_Name"),
"phone" : lead.get("Phone"),
"additionalDetails" : {
"street" : lead.get("Street"),
"city" : lead.get("City"),
"state" : "WA",
"zip" : lead.get("Zip_Code"),
"fee" : "***",
"dateOfAuction" : lead.get("Auction_Date")
}
};
// API endpoint with /sync for synchronous response
string url = "****";
// Send the POST request and handle the response
response = postUrl(url, jsonData.toString(), headers);
if(response.getStatusCode() == 200) {
return "activated successfully.";
} else if(response.getStatusCode() == 408) {
return "Request timed out. Please try again.";
} else {
return "Error: HTTP Status " + response.getStatusCode();
}
}
// Custom Button main function
function checkLeadAndProcess() {
lead = zoho.crm.getRecordById("Leads", input.leadId);
// Check if all required fields are filled
if(lead.get("First_Name") != null && lead.get("Last_Name") != null && lead.get("Phone") != null &&
lead.get("Street") != null && lead.get("City") != null && lead.get("State") != null &&
lead.get("Zip") != null && lead.get("County") != null && lead.get("Auction_Date") != null &&
lead.get("Sold_For") != null && lead.get("Debt") != null) {
// Call the function to send data to Synthflow and get the result message
info sendToSynthflow(lead);
} else {
info "Please make sure all required fields are filled before activating.";
}
}
Writer is a powerful online word processor, designed for collaborative work.