### Assign Zone and Owner based on Country Source: https://github.com/zohodesk-developers/custom-function-samples/blob/master/Ticket/Email content based update/Update ticket from email content.txt Conditionally assigns a 'zone' and 'ProductPreSalesOwner' based on the extracted country. This example specifically checks if the country belongs to Europe and sets the owner accordingly. Additional country-to-zone mappings can be added. ```Zoho Flow if(country.equalsIgnoreCase("Albania") || country.equalsIgnoreCase("Andorra") || country.equalsIgnoreCase("Belarus") || country.equalsIgnoreCase("Bosnia") || country.equalsIgnoreCase("Croatia") || country.equalsIgnoreCase("Faroe Islands") || country.equalsIgnoreCase("Gibraltar") || country.equalsIgnoreCase("Iceland") || country.equalsIgnoreCase("Jersey") || country.equalsIgnoreCase("Kosovo") || country.equalsIgnoreCase("Liechtenstein") || country.equalsIgnoreCase("Macedonia") || country.equalsIgnoreCase("Moldova") || country.equalsIgnoreCase("Monaco") || country.equalsIgnoreCase("Montenegro") || country.equalsIgnoreCase("Norway") || country.equalsIgnoreCase("San Marino") || country.equalsIgnoreCase("Serbia") || country.equalsIgnoreCase("Svalbard and Jan Mayen Islands") || country.equalsIgnoreCase("Switzerland") || country.equalsIgnoreCase("Turkey") || country.equalsIgnoreCase("Ukraine") || country.equalsIgnoreCase("Vatican City State") || country.equalsIgnoreCase("Austria") || country.equalsIgnoreCase("Belgium") || country.equalsIgnoreCase("Bulgaria") || country.equalsIgnoreCase("Cyprus") || country.equalsIgnoreCase("Czech Republic") || country.equalsIgnoreCase("Czech republic") || country.equalsIgnoreCase("Denmark") || country.equalsIgnoreCase("Estonia") || country.equalsIgnoreCase("Finland") || country.equalsIgnoreCase("France") || country.equalsIgnoreCase("Germany") || country.equalsIgnoreCase("Greece") || country.equalsIgnoreCase("Hungary") || country.equalsIgnoreCase("Ireland") || country.equalsIgnoreCase("Italy") || country.equalsIgnoreCase("Latvia") || country.equalsIgnoreCase("Lithuania") || country.equalsIgnoreCase("Luxembourg") || country.equalsIgnoreCase("Malta") || country.equalsIgnoreCase("Netherlands") || country.equalsIgnoreCase("Poland") || country.equalsIgnoreCase("Portugal") || country.equalsIgnoreCase("Romania") || country.equalsIgnoreCase("Slovakia") || country.equalsIgnoreCase("Slovenia") || country.equalsIgnoreCase("Spain") || country.equalsIgnoreCase("Sweden") || country.equalsIgnoreCase("United kingdom") || country.equalsIgnoreCase("United Kingdom")) { zone = "Europe"; ProductPreSalesOwner = "Gunasekaran U"; } ``` -------------------------------- ### Prepare and Add Contact Details to Zoho Creator Source: https://github.com/zohodesk-developers/custom-function-samples/blob/master/Desk Integration/Desk to Creator/push contact to creator.txt Prepares contact data in a map format and adds it to a specified Zoho Creator form. Requires the 'creatoroperation' connection with ZohoCreator.form.CREATE scope. Replace placeholders like , , and with your actual values. ```Zoho param = Map(); param.put("Contact_Person",lastName.trim()); param.put("Email",semail.trim()); param.put("Phone",phone.trim()); param.put("Mobile",mobile.trim()); param.put("Type",type.trim()); param.put("Account_Name",accountName.trim()); param.put("Twitter",twitter.trim()); param.put("Facebook",faceBook.trim()); param.put("Contact_Owner",contactOwner.trim()); param1=Map(); param1.put("data",param); addDetails = invokeurl [ url :"https://creator.zoho.com/api/v2///form/" type :POST parameters:param1 connection:"creatoroperation" ]; creatorID = addDetails.get("id").toString(); ``` -------------------------------- ### Get Ticket History and Agent Info Source: https://github.com/zohodesk-developers/custom-function-samples/blob/master/Ticket/Assign Ticket/MoveDepartment_update_agentinfo_WhoMovedTicket.txt Fetches the history of a ticket to find department move events and retrieves agent details based on the agent ID found in the history. Ensure the 'deskoperation' connection is set up with appropriate scopes. ```Zoho Flow orgId = "644088596";//Replace ORGID getTicketHistory = invokeurl [ url :"https://desk.zoho.com/api/v1/tickets/" + ticketID + "/history" type :GET connection : "deskoperation" ]; //info getTicketHistory; ticketHistory = getTicketHistory.toList(); info ticketHistory; for each history in ticketHistory { if(history.get("name").toString().equalsIgnoreCase("Department_Moved")) { agentId = history.get("agentId"); name1 = history.get("name"); break; } } info name1; info agentId; getAgentInfowihtID = invokeurl [ url :"https://desk.zoho.com/api/v1/agents/" + agentId + "?include=profile,role,associatedDepartments,associatedChatDepartments" type :GET connection : "deskoperation" ]; AgentName = getAgentInfowihtID.get("firstName") + " " + getAgentInfowihtID.get("lastName"); AgentName = AgentName.trim(); ProfileName = getAgentInfowihtID.get("profile").get("name").trim(); jsonString = {"customFields":{"Profile Name":ProfileName,"Agent Name":AgentName}}; info jsonString; updateTicket = invokeurl [ url :"https://desk.zoho.com/api/v1/tickets/" + ticketID type :PATCH parameters:jsonString.toString() connection : "deskoperation" ]; info updateTicket; ``` -------------------------------- ### Create Project from Ticket Details Source: https://github.com/zohodesk-developers/custom-function-samples/blob/master/Desk Integration/DESK - Projects/project_creation.txt This function creates a project in Zoho Projects using details from a Zoho Desk ticket. Ensure the 'orgId' and 'portalname' are replaced with your actual values. The date format for 'start_date' and 'end_date' must be MM:DD:YYYY. ```zoho /* This Function create project from desk sample code. MODULE : Ticket ARGUMENT : Name : ticketID - Value : Ticket Id SAMPLE CODE: */ orgId = 644088596;//replace DESK ORGID //portal_id = "650161438"; getTicketDetails = zoho.desk.getRecordById(orgId,"tickets",ticketID); info getTicketDetails; name = getTicketDetails.get("subject"); description = "TEst projects"; start_date = "10-17-2018";//date must be this format MM:DD:YYYY end_date = "10-17-2019"; strict_project = "1"; projectDetails = Map(); projectDetails.put("name",name); projectDetails.put("description",description); projectDetails.put("start_date",start_date); projectDetails.put("end_date",end_date); projectDetails.put("strict_project",strict_project); getportal = zoho.projects.createProject("portalname",projectDetails);//replace project portal name (portalname) info getportal; ``` -------------------------------- ### Get Ticket History and Update Owner Source: https://github.com/zohodesk-developers/custom-function-samples/blob/master/Ticket/Assign Ticket/Ticket closed agent as Ticket Owner.txt This snippet retrieves the history of a specific ticket to check for status changes. It then updates the ticket to assign the agent who closed it as the new owner. Ensure the 'deskoperation' connection is set up with the necessary scopes (Desk.tickets.READ, Desk.tickets.UPDATE). ```Zoho Deluge orgId = "644088596";//replace ORGID getTicketHistory = invokeurl [ url :"https://desk.zoho.com/api/v1/tickets/" + ticketID + "/history" type :GET connection:"deskoperation" ]; //info getTicketHistory; ticketHistory = getTicketHistory.toList(); //info ticketHistory; for each history in ticketHistory { if(history.get("name").toString().equalsIgnoreCase("Ticket_Updated")) { name1 = history.get("changes").toString().get("field"); newstatus = history.get("changes").toString().get("newValue"); if(name1=="Status" && newstatus=="Closed"){ AgentID=history.get("agentId"); break; } } } info name1; info agentId; jsonString = {"assigneeId":agentId}; //info jsonString; updateTicket = invokeurl [ url :"https://desk.zoho.com/api/v1/tickets/" + ticketID type :PATCH parameters:jsonString.toString() connection:"deskoperation" ]; info updateTicket; ``` -------------------------------- ### Download Multiple Attachments Source: https://github.com/zohodesk-developers/custom-function-samples/blob/master/Ticket/Send Mail/sendattachment.txt This demonstrates downloading multiple attachments sequentially using the `invokeurl` task. Each attachment is assigned to a unique variable. ```Zoho Functions downloadFile1 = invokeurl [ url :attachmentUrl1 type :GET connection:"deskoperation" ]; downloadFile2 = invokeurl [ url :attachmentUrl2 type :GET connection:"deskoperation" ]; downloadFile3 = invokeurl [ url :attachmentUrl3 type :GET connection:"deskoperation" ]; downloadFile4 = invokeurl [ url :attachmentUrl4 type :GET connection:"deskoperation" ]; downloadFile5 = invokeurl [ url :attachmentUrl5 type :GET connection:"deskoperation" ]; downloadFile6 = invokeurl [ url :attachmentUrl6 type :GET connection:"deskoperation" ]; downloadFile7 = invokeurl [ url :attachmentUrl7 type :GET connection:"deskoperation" ]; downloadFile8 = invokeurl [ url :attachmentUrl8 type :GET connection:"deskoperation" ]; downloadFile9 = invokeurl [ url :attachmentUrl9 type :GET connection:"deskoperation" ]; downloadFile10 = invokeurl [ url :attachmentUrl10 type :GET connection:"deskoperation" ]; downloadFile11 = invokeurl [ url :attachmentUrl11 type :GET connection:"deskoperation" ]; downloadFile12 = invokeurl [ url :attachmentUrl12 type :GET connection:"deskoperation" ]; downloadFile13 = invokeurl [ url :attachmentUrl13 type :GET connection:"deskoperation" ]; downloadFile14 = invokeurl [ url :attachmentUrl14 type :GET connection:"deskoperation" ]; ``` -------------------------------- ### Download Attachment using invokeurl Source: https://github.com/zohodesk-developers/custom-function-samples/blob/master/Ticket/Send Mail/sendattachment.txt This snippet shows how to download a single attachment using the `invokeurl` task. Ensure the `connection` is correctly configured. ```Zoho Functions downloadFile = invokeurl [ url :attachmentUrl type :GET connection:"deskoperation" ]; ``` -------------------------------- ### Send Email with Pre-downloaded Attachments Source: https://github.com/zohodesk-developers/custom-function-samples/blob/master/Ticket/Send Mail/sendattachment.txt This snippet sends an email with a predefined list of downloaded attachments. It assumes `downloadFile` through `downloadFile10` have already been populated. ```Zoho Deluge sendmail [ from :zoho.adminuserid to :"navinhereforyou@gmail.com,vijaytest2607@gmail.com,vijayakumar.b@zohocorp.com" subject :"Test for SubTab attachments send on tikcet closure" message :emailcontent content type :HTML Attachments :file:downloadFile,file:downloadFile1,file:downloadFile2,file:downloadFile3,file:downloadFile4,file:downloadFile5,file:downloadFile6,file:downloadFile7,file:downloadFile8,file:downloadFile9,file:downloadFile10 ] ``` -------------------------------- ### Search and Create Zoho Desk Account via API Source: https://github.com/zohodesk-developers/custom-function-samples/blob/master/Ticket/Email content based update/Update ticket from email content.txt This code searches for an account by domain using the Zoho Desk API. If no account is found, it proceeds to create a new account with specified details. ```Deluge else { domain = email.subText(email.indexOf("@") + 1,email.toString().length()); searchAccountByDomain = invokeurl [ url :"https://desk.zoho.com/api/v1/accounts/search?limit=99&_all=" + domain type :GET connection : “deskoperation” ]; //info searchAccountByDomain; listofAccounts = searchAccountByDomain.get("data"); if(searchAccountByDomain.get("data") == "" || searchAccountByDomain.get("data") == null) { domain = email.subText(email.indexOf("@") + 1,email.indexOf(".")); if(commonDomain.containsIgnoreCase(domain.trim())) { accountname = "ZROP -onpremise Public account"; accountownID = "66440000000047090"; } else { accountname = domain.trim(); accountownID = "66440000000047090"; } param = Map(); param.put("accountName",accountname); param.put("ownerId",accountownID); param.put("customFields",customData); createaccount = invokeurl [ url :"https://desk.zoho.com/api/v1/accounts" type :POST parameters:param.toString() connection : “deskoperation” ]; info createaccount; newAccountID = createaccount.get("id"); } else { for each account in listofAccounts { domainname = account.get("customFields").get("Domain Name").toString(); ``` -------------------------------- ### Fetch Ticket Attachments and Send Email (5 Attachments) Source: https://github.com/zohodesk-developers/custom-function-samples/blob/master/Ticket/Send Mail/sendattachment.txt Retrieves five attachments from a ticket and sends them via email. Ensure the 'deskoperation' connection is properly configured. ```Zoho Flow ORGID = "644088596"; emailcontent = "This is test email from zoho. please ignore this email"; //replace email text body i = 0; getTicketAttachment = invokeurl [ url :"https://desk.zoho.com/api/v1/tickets/" + ticketID + "/attachments?limit=15" type :GET connection:"deskoperation" ]; //info getTicketAttachment.get("data"); countattachment = getTicketAttachment.get("data").size(); attachment = getTicketAttachment.get("data"); //info countattachment; currentTime = zoho.currenttime.toString("yyyy-MM-dd'T'HH:mm:ss'.00Z'","GMT"); hour = currentTime.subText(currentTime.indexOf("T") + 1,currentTime.indexOf(":")); hour = hour.toNumber(); info hour; for each attach in attachment { currentTime = zoho.currenttime.toString("yyyy-MM-dd'T'HH:mm:ss'.00Z'","GMT"); hour = currentTime.subText(currentTime.indexOf("T") + 1,currentTime.indexOf(":")); hour = hour.toNumber(); cTime = attach.get("createdTime").toString(); //info cTime; hour1 = cTime.subText(cTime.indexOf("T") + 1,cTime.indexOf(":")); hour1 = hour1.toNumber(); info hour1; if(hour1 == hour) { i = i + 1; } } info i; countattachment = i; if(countattachment == 5) { attachmentUrl = attachment.get("0").getJSON("href"); attachmentUrl1 = attachment.get("1").getJSON("href"); attachmentUrl2 = attachment.get("2").getJSON("href"); attachmentUrl3 = attachment.get("3").getJSON("href"); attachmentUrl4 = attachment.get("4").getJSON("href"); downloadFile = invokeurl [ url :attachmentUrl type :GET connection:"deskoperation" ]; downloadFile1 = invokeurl [ url :attachmentUrl1 type :GET connection:"deskoperation" ]; downloadFile2 = invokeurl [ url :attachmentUrl2 type :GET connection:"deskoperation" ]; downloadFile3 = invokeurl [ url :attachmentUrl3 type :GET connection:"deskoperation" ]; downloadFile4 = invokeurl [ url :attachmentUrl4 type :GET connection:"deskoperation" ]; } ``` -------------------------------- ### Associate Contact and Update Ticket by Domain Source: https://github.com/zohodesk-developers/custom-function-samples/blob/master/Contact/Account website domain based contact account association_v1.txt Use this code to find an account based on a domain extracted from a subject line, associate the contact with that account, and update the ticket with the domain value. Ensure the 'deskoperation' connection is set up with appropriate scopes (Desk.search.READ, Desk.contacts.READ, Desk.contacts.UPDATE, Desk.tickets.UPDATE). ```Zoho Deluge ORGID = "644088596";//Replace ORGID domainSuffix = subj.subString(subj.indexOf("No:") + 3,subj.indexOf("is")-1); domainValue = domainSuffix.trim(); info domainValue; accountID=""; searchAccountByDomain = invokeurl [ url :"https://desk.zoho.com/api/v1/accounts/search?limit=100&_all=" + domainValue type :GET connection:"deskoperation" ]; info searchAccountByDomain; //domain=""; accountdetails = searchAccountByDomain.get("data").toString(); count=accountdetails.size(); if(count > 0){ for each account in accountdetails { domain=account.get("customFields").get("Order ID").toString(); if(domain.contains(domainValue)){ accountID=account.get("id"); } } } jsonString = {"accountId":accountID}; updatecontact = invokeurl [ url :"https://desk.zoho.com/api/v1/contacts/" + contactID type :PATCH parameters:jsonString.toString() connection:"deskoperation" ]; info updatecontact; jsonString1 = {"cf":{"cf_custom_field":domainValue}}; updateTicket = invokeurl [ url :"https://desk.zoho.com/api/v1/tickets/" + ticketID type :PATCH parameters:jsonString1.toString() connection:"deskoperation" ]; info updateTicket; ``` -------------------------------- ### Download Multiple Attachments and Send Email (13 Attachments) Source: https://github.com/zohodesk-developers/custom-function-samples/blob/master/Ticket/Send Mail/sendattachment.txt This snippet downloads up to 13 attachments and sends them with an email. Ensure the 'deskoperation' connection is configured. ```Zoho Deluge if(countattachment == 13) { attachmentUrl = attachment.get("0").getJSON("href"); attachmentUrl1 = attachment.get("1").getJSON("href"); attachmentUrl2 = attachment.get("2").getJSON("href"); attachmentUrl3 = attachment.get("3").getJSON("href"); attachmentUrl4 = attachment.get("4").getJSON("href"); attachmentUrl5 = attachment.get("5").getJSON("href"); attachmentUrl6 = attachment.get("6").getJSON("href"); attachmentUrl7 = attachment.get("7").getJSON("href"); attachmentUrl8 = attachment.get("8").getJSON("href"); attachmentUrl9 = attachment.get("9").getJSON("href"); attachmentUrl10 = attachment.get("10").getJSON("href"); attachmentUrl11 = attachment.get("11").getJSON("href"); attachmentUrl12 = attachment.get("12").getJSON("href"); downloadFile = invokeurl [ url :attachmentUrl type :GET connection:"deskoperation" ]; downloadFile1 = invokeurl [ url :attachmentUrl1 type :GET connection:"deskoperation" ]; downloadFile2 = invokeurl [ url :attachmentUrl2 type :GET connection:"deskoperation" ]; downloadFile3 = invokeurl [ url :attachmentUrl3 type :GET connection:"deskoperation" ]; downloadFile4 = invokeurl [ url :attachmentUrl4 type :GET connection:"deskoperation" ]; downloadFile5 = invokeurl [ url :attachmentUrl5 type :GET connection:"deskoperation" ]; downloadFile6 = invokeurl [ url :attachmentUrl6 type :GET connection:"deskoperation" ]; downloadFile7 = invokeurl [ url :attachmentUrl7 type :GET connection:"deskoperation" ]; downloadFile8 = invokeurl [ url :attachmentUrl8 type :GET connection:"deskoperation" ]; downloadFile9 = invokeurl [ url :attachmentUrl9 type :GET connection:"deskoperation" ]; downloadFile10 = invokeurl [ url :attachmentUrl10 type :GET connection:"deskoperation" ]; downloadFile11 = invokeurl [ url :attachmentUrl11 type :GET connection:"deskoperation" ]; downloadFile12 = invokeurl [ url :attachmentUrl12 type :GET connection:"deskoperation" ]; sendmail [ from :zoho.adminuserid to :"naveen.gs@zohocorp.com,vijaytest2607@gmail.com" subject :"Test for SubTab attachments send on tikcet closure" message :emailcontent content type :HTML Attachments :file:downloadFile,file:downloadFile1,file:downloadFile2,file:downloadFile3,file:downloadFile4,file:downloadFile5,file:downloadFile6,file:downloadFile7,file:downloadFile8,file:downloadFile9,file:downloadFile10,file:downloadFile11,file:downloadFile12 ] } ``` -------------------------------- ### Fetch Ticket Attachments and Send Email (4 Attachments) Source: https://github.com/zohodesk-developers/custom-function-samples/blob/master/Ticket/Send Mail/sendattachment.txt Retrieves four attachments from a ticket and sends them via email. Ensure the 'deskoperation' connection is properly configured. ```Zoho Flow ORGID = "644088596"; emailcontent = "This is test email from zoho. please ignore this email"; //replace email text body i = 0; getTicketAttachment = invokeurl [ url :"https://desk.zoho.com/api/v1/tickets/" + ticketID + "/attachments?limit=15" type :GET connection:"deskoperation" ]; //info getTicketAttachment.get("data"); countattachment = getTicketAttachment.get("data").size(); attachment = getTicketAttachment.get("data"); //info countattachment; currentTime = zoho.currenttime.toString("yyyy-MM-dd'T'HH:mm:ss'.00Z'","GMT"); hour = currentTime.subText(currentTime.indexOf("T") + 1,currentTime.indexOf(":")); hour = hour.toNumber(); info hour; for each attach in attachment { currentTime = zoho.currenttime.toString("yyyy-MM-dd'T'HH:mm:ss'.00Z'","GMT"); hour = currentTime.subText(currentTime.indexOf("T") + 1,currentTime.indexOf(":")); hour = hour.toNumber(); cTime = attach.get("createdTime").toString(); //info cTime; hour1 = cTime.subText(cTime.indexOf("T") + 1,cTime.indexOf(":")); hour1 = hour1.toNumber(); info hour1; if(hour1 == hour) { i = i + 1; } } info i; countattachment = i; if(countattachment == 4) { attachmentUrl = attachment.get("0").getJSON("href"); attachmentUrl1 = attachment.get("1").getJSON("href"); attachmentUrl2 = attachment.get("2").getJSON("href"); attachmentUrl3 = attachment.get("3").getJSON("href"); downloadFile = invokeurl [ url :attachmentUrl type :GET connection:"deskoperation" ]; downloadFile1 = invokeurl [ url :attachmentUrl1 type :GET connection:"deskoperation" ]; downloadFile2 = invokeurl [ url :attachmentUrl2 type :GET connection:"deskoperation" ]; downloadFile3 = invokeurl [ url :attachmentUrl3 type :GET connection:"deskoperation" ]; sendmail [ from :zoho.adminuserid to :"naveen.gs@zohocorp.com,vijaytest2607@gmail.com" subject :"Test for SubTab attachments send on tikcet closure" message :emailcontent content type :HTML Attachments :file:downloadFile,file:downloadFile1,file:downloadFile2,file:downloadFile3 ] } ``` -------------------------------- ### Fetch Ticket Attachments and Send Email (3 Attachments) Source: https://github.com/zohodesk-developers/custom-function-samples/blob/master/Ticket/Send Mail/sendattachment.txt Retrieves three attachments from a ticket and sends them via email. Ensure the 'deskoperation' connection is properly configured. ```Zoho Flow ORGID = "644088596"; emailcontent = "This is test email from zoho. please ignore this email"; //replace email text body i = 0; getTicketAttachment = invokeurl [ url :"https://desk.zoho.com/api/v1/tickets/" + ticketID + "/attachments?limit=15" type :GET connection:"deskoperation" ]; //info getTicketAttachment.get("data"); countattachment = getTicketAttachment.get("data").size(); attachment = getTicketAttachment.get("data"); //info countattachment; currentTime = zoho.currenttime.toString("yyyy-MM-dd'T'HH:mm:ss'.00Z'","GMT"); hour = currentTime.subText(currentTime.indexOf("T") + 1,currentTime.indexOf(":")); hour = hour.toNumber(); info hour; for each attach in attachment { currentTime = zoho.currenttime.toString("yyyy-MM-dd'T'HH:mm:ss'.00Z'","GMT"); hour = currentTime.subText(currentTime.indexOf("T") + 1,currentTime.indexOf(":")); hour = hour.toNumber(); cTime = attach.get("createdTime").toString(); //info cTime; hour1 = cTime.subText(cTime.indexOf("T") + 1,cTime.indexOf(":")); hour1 = hour1.toNumber(); info hour1; if(hour1 == hour) { i = i + 1; } } info i; countattachment = i; if(countattachment == 3) { attachmentUrl = attachment.get("0").getJSON("href"); attachmentUrl1 = attachment.get("1").getJSON("href"); attachmentUrl2 = attachment.get("2").getJSON("href"); downloadFile = invokeurl [ url :attachmentUrl type :GET connection:"deskoperation" ]; downloadFile1 = invokeurl [ url :attachmentUrl1 type :GET connection:"deskoperation" ]; downloadFile2 = invokeurl [ url :attachmentUrl2 type :GET connection:"deskoperation" ]; sendmail [ from :zoho.adminuserid to :"naveen.gs@zohocorp.com,vijaytest2607@gmail.com" subject :"Test for SubTab attachments send on tikcet closure" message :emailcontent content type :HTML Attachments :file:downloadFile,file:downloadFile1,file:downloadFile2 ] } ``` -------------------------------- ### Send Email with Multiple Attachments Source: https://github.com/zohodesk-developers/custom-function-samples/blob/master/Ticket/Send Mail/sendattachment.txt This snippet demonstrates sending an HTML email with a list of attachments. The `Attachments` parameter accepts a comma-separated list of downloaded file variables. ```Zoho Functions sendmail [ from :zoho.adminuserid to :"naveen.gs@zohocorp.com,vijaytest2607@gmail.com" subject :"Test for SubTab attachments send on tikcet closure" message :emailcontent content type :HTML Attachments :file:downloadFile,file:downloadFile1,file:downloadFile2,file:downloadFile3,file:downloadFile4,file:downloadFile5,file:downloadFile6,file:downloadFile7,file:downloadFile8,file:downloadFile9,file:downloadFile10,file:downloadFile11,file:downloadFile12,file:downloadFile13,file:downloadFile14 ] ``` -------------------------------- ### Download Multiple Attachments and Send Email (12 Attachments) Source: https://github.com/zohodesk-developers/custom-function-samples/blob/master/Ticket/Send Mail/sendattachment.txt This snippet downloads up to 12 attachments and sends them with an email. Ensure the 'deskoperation' connection is configured. ```Zoho Deluge if(countattachment == 12) { attachmentUrl = attachment.get("0").getJSON("href"); attachmentUrl1 = attachment.get("1").getJSON("href"); attachmentUrl2 = attachment.get("2").getJSON("href"); attachmentUrl3 = attachment.get("3").getJSON("href"); attachmentUrl4 = attachment.get("4").getJSON("href"); attachmentUrl5 = attachment.get("5").getJSON("href"); attachmentUrl6 = attachment.get("6").getJSON("href"); attachmentUrl7 = attachment.get("7").getJSON("href"); attachmentUrl8 = attachment.get("8").getJSON("href"); attachmentUrl9 = attachment.get("9").getJSON("href"); attachmentUrl10 = attachment.get("10").getJSON("href"); downloadFile = invokeurl [ url :attachmentUrl type :GET connection:"deskoperation" ]; downloadFile1 = invokeurl [ url :attachmentUrl1 type :GET connection:"deskoperation" ]; downloadFile2 = invokeurl [ url :attachmentUrl2 type :GET connection:"deskoperation" ]; downloadFile3 = invokeurl [ url :attachmentUrl3 type :GET connection:"deskoperation" ]; downloadFile4 = invokeurl [ url :attachmentUrl4 type :GET connection:"deskoperation" ]; downloadFile5 = invokeurl [ url :attachmentUrl5 type :GET connection:"deskoperation" ]; downloadFile6 = invokeurl [ url :attachmentUrl6 type :GET connection:"deskoperation" ]; downloadFile7 = invokeurl [ url :attachmentUrl7 type :GET connection:"deskoperation" ]; downloadFile8 = invokeurl [ url :attachmentUrl8 type :GET connection:"deskoperation" ]; downloadFile9 = invokeurl [ url :attachmentUrl9 type :GET connection:"deskoperation" ]; downloadFile10 = invokeurl [ url :attachmentUrl10 type :GET connection:"deskoperation" ]; sendmail [ from :zoho.adminuserid to :"naveen.gs@zohocorp.com,vijaytest2607@gmail.com" subject :"Test for SubTab attachments send on tikcet closure" message :emailcontent content type :HTML Attachments :file:downloadFile,file:downloadFile1,file:downloadFile2,file:downloadFile3,file:downloadFile4,file:downloadFile5,file:downloadFile6,file:downloadFile7,file:downloadFile8,file:downloadFile9,file:downloadFile10 ] } ``` -------------------------------- ### Fetch Ticket Attachments and Send Email (2 Attachments) Source: https://github.com/zohodesk-developers/custom-function-samples/blob/master/Ticket/Send Mail/sendattachment.txt Retrieves two attachments from a ticket and sends them via email. Ensure the 'deskoperation' connection is properly configured. ```Zoho Flow ORGID = "644088596"; emailcontent = "This is test email from zoho. please ignore this email"; //replace email text body i = 0; getTicketAttachment = invokeurl [ url :"https://desk.zoho.com/api/v1/tickets/" + ticketID + "/attachments?limit=15" type :GET connection:"deskoperation" ]; //info getTicketAttachment.get("data"); countattachment = getTicketAttachment.get("data").size(); attachment = getTicketAttachment.get("data"); //info countattachment; currentTime = zoho.currenttime.toString("yyyy-MM-dd'T'HH:mm:ss'.00Z'","GMT"); hour = currentTime.subText(currentTime.indexOf("T") + 1,currentTime.indexOf(":")); hour = hour.toNumber(); info hour; for each attach in attachment { currentTime = zoho.currenttime.toString("yyyy-MM-dd'T'HH:mm:ss'.00Z'","GMT"); hour = currentTime.subText(currentTime.indexOf("T") + 1,currentTime.indexOf(":")); hour = hour.toNumber(); cTime = attach.get("createdTime").toString(); //info cTime; hour1 = cTime.subText(cTime.indexOf("T") + 1,cTime.indexOf(":")); hour1 = hour1.toNumber(); info hour1; if(hour1 == hour) { i = i + 1; } } info i; countattachment = i; if(countattachment == 2) { attachmentUrl = attachment.get("0").getJSON("href"); attachmentUrl1 = attachment.get("1").getJSON("href"); downloadFile = invokeurl [ url :attachmentUrl type :GET connection:"deskoperation" ]; downloadFile1 = invokeurl [ url :attachmentUrl1 type :GET connection:"deskoperation" ]; sendmail [ from :zoho.adminuserid to :email subject :"Test for SubTab attachments send on tikcet closure" message :emailcontent content type :HTML Attachments :file:downloadFile,file:downloadFile1 ] } ``` -------------------------------- ### Send Email with 5 Attachments Source: https://github.com/zohodesk-developers/custom-function-samples/blob/master/Ticket/Send Mail/sendattachment.txt This snippet sends an email with 5 attachments. It first downloads each attachment using 'invokeurl' and then includes them in the 'sendmail' task. ```Zoho Creator if(countattachment == 6) { attachmentUrl = attachment.get("0").getJSON("href"); attachmentUrl1 = attachment.get("1").getJSON("href"); attachmentUrl2 = attachment.get("2").getJSON("href"); attachmentUrl3 = attachment.get("3").getJSON("href"); attachmentUrl4 = attachment.get("4").getJSON("href"); downloadFile = invokeurl [ url :attachmentUrl type :GET connection:"deskoperation" ]; downloadFile1 = invokeurl [ url :attachmentUrl1 type :GET connection:"deskoperation" ]; downloadFile2 = invokeurl [ url :attachmentUrl2 type :GET connection:"deskoperation" ]; downloadFile3 = invokeurl [ url :attachmentUrl3 type :GET connection:"deskoperation" ]; downloadFile4 = invokeurl [ url :attachmentUrl4 type :GET connection:"deskoperation" ]; sendmail [ from :zoho.adminuserid to :"naveen.gs@zohocorp.com,vijaytest2607@gmail.com" subject :"Test for SubTab attachments send on tikcet closure" message :emailcontent content type :HTML Attachments :file:downloadFile,file:downloadFile1,file:downloadFile2,file:downloadFile3,file:downloadFile4,file:downloadFile5 ] } ``` -------------------------------- ### Send Email with 7 Attachments Source: https://github.com/zohodesk-developers/custom-function-samples/blob/master/Ticket/Send Mail/sendattachment.txt This snippet sends an email with 7 attachments. It downloads each attachment using 'invokeurl' and then includes them in the 'sendmail' task. ```Zoho Creator if(countattachment == 8) { attachmentUrl = attachment.get("0").getJSON("href"); attachmentUrl1 = attachment.get("1").getJSON("href"); attachmentUrl2 = attachment.get("2").getJSON("href"); attachmentUrl3 = attachment.get("3").getJSON("href"); attachmentUrl4 = attachment.get("4").getJSON("href"); attachmentUrl5 = attachment.get("5").getJSON("href"); attachmentUrl6 = attachment.get("6").getJSON("href"); downloadFile = invokeurl [ url :attachmentUrl type :GET connection:"deskoperation" ]; downloadFile1 = invokeurl [ url :attachmentUrl1 type :GET connection:"deskoperation" ]; downloadFile2 = invokeurl [ url :attachmentUrl2 type :GET connection:"deskoperation" ]; downloadFile3 = invokeurl [ url :attachmentUrl3 type :GET connection:"deskoperation" ]; downloadFile4 = invokeurl [ url :attachmentUrl4 type :GET connection:"deskoperation" ]; downloadFile5 = invokeurl [ url :attachmentUrl5 type :GET connection:"deskoperation" ]; downloadFile6 = invokeurl [ url :attachmentUrl6 type :GET connection:"deskoperation" ]; sendmail [ from :zoho.adminuserid to :"naveen.gs@zohocorp.com,vijaytest2607@gmail.com" subject :"Test for SubTab attachments send on tikcet closure" message :emailcontent content type :HTML Attachments :file:downloadFile,file:downloadFile1,file:downloadFile2,file:downloadFile3,file:downloadFile4,file:downloadFile5,file:downloadFile6,file:downloadFile7 ] } ``` -------------------------------- ### Search or Create Contact Source: https://github.com/zohodesk-developers/custom-function-samples/blob/master/Ticket/Email Parse/Update contact of ticket from content of email body.txt Searches for an existing contact by email. If not found, it creates a new contact using the extracted name and email. Requires 'Desk.contacts.READ', 'Desk.contacts.CREATE' scopes. ```Zoho Flow getcontactDetails = invokeurl [ url :"https://desk.zoho.com/api/v1/contacts/search?email=" + Email type :GET connection : "deskoperation" ]; size = getcontactDetails.get("data").size(); if(size > 0) { contactID = getcontactDetails.get("data").get(0).get("id"); } else { contactParam = Map(); contactParam.put("lastName",contact_name); contactParam.put("email",Email); createContact = invokeurl [ url :"https://desk.zoho.com/api/v1/contacts" type :POST parameters:contactParam.toString() connection : "deskoperation" ]; contactID = createContact.get("id"); } ``` -------------------------------- ### Fetch and Clone Ticket Details Source: https://github.com/zohodesk-developers/custom-function-samples/blob/master/Ticket/Create:Clone/Clone Ticket Sample code.txt This code fetches details from an existing ticket using its ID and prepares the data to create a clone. Ensure a Zoho OAuth connection is set up and replace 'deskoperation' with your connection's link name. ``` Zoho Flow ORGID = "644088596"; //replace orgid getTicketDetails = invokeurl [ url :"https://desk.zoho.com/api/v1/tickets/" + ticketID type :GET connection : "deskoperation" ]; //info getTicketDetails; ticketNumber = getTicketDetails.get("ticketNumber"); subCategory = getTicketDetails.get("subCategory"); subject = getTicketDetails.get("subject"); subject=subject+" [DOT]"; departmentId = getTicketDetails.get("departmentId"); channel = getTicketDetails.get("channel"); description = getTicketDetails.get("description"); resolution = getTicketDetails.get("resolution"); email = getTicketDetails.get("email"); productId = getTicketDetails.get("productId"); contactId = getTicketDetails.get("contactId"); priority = getTicketDetails.get("priority"); classification = getTicketDetails.get("classification"); assigneeId = getTicketDetails.get("assigneeId"); accountId = getTicketDetails.get("accountId"); phone = getTicketDetails.get("phone"); webUrl = getTicketDetails.get("webUrl"); teamId = getTicketDetails.get("teamId"); category = getTicketDetails.get("category"); status = getTicketDetails.get("status"); usertype = getTicketDetails.get("customFields").get("User Type"); usercount= getTicketDetails.get("customFields").get("No of User"); edition = getTicketDetails.get("customFields").get("Edition"); param = Map(); param.put("ticketNumber",ticketNumber); param.put("subCategory ",subCategory); param.put("departmentId",departmentId); param.put("channel ",channel); param.put("description",description); param.put("resolution ",resolution); param.put("email",email); param.put("productId ",productId); param.put("ticketId ",ticketID); param.put("contactId",contactId); param.put("priority ",priority); param.put("classification",classification); param.put("assigneeId ",assigneeId); param.put("accountId",accountId); param.put("phone ",phone); param.put("webUrl",webUrl); param.put("teamId ",teamId); param.put("category",category); param.put("status ",status); info param; customparam=Map(); customparam.put("User Type",usertype); customparam.put("No of User",usercount); customparam.put("Edition",edition); param.put("customFields ",customparam); createTicket = invokeurl [ url :"https://desk.zoho.com/api/v1/tickets" type :POST parameters:param.toString() connection : "deskoperation" ]; info createTicket; ``` -------------------------------- ### Send Email with 6 Attachments Source: https://github.com/zohodesk-developers/custom-function-samples/blob/master/Ticket/Send Mail/sendattachment.txt This snippet sends an email with 6 attachments. It downloads each attachment using 'invokeurl' and then includes them in the 'sendmail' task. ```Zoho Creator if(countattachment == 7) { attachmentUrl = attachment.get("0").getJSON("href"); attachmentUrl1 = attachment.get("1").getJSON("href"); attachmentUrl2 = attachment.get("2").getJSON("href"); attachmentUrl3 = attachment.get("3").getJSON("href"); attachmentUrl4 = attachment.get("4").getJSON("href"); attachmentUrl5 = attachment.get("5").getJSON("href"); downloadFile = invokeurl [ url :attachmentUrl type :GET connection:"deskoperation" ]; downloadFile1 = invokeurl [ url :attachmentUrl1 type :GET connection:"deskoperation" ]; downloadFile2 = invokeurl [ url :attachmentUrl2 type :GET connection:"deskoperation" ]; downloadFile3 = invokeurl [ url :attachmentUrl3 type :GET connection:"deskoperation" ]; downloadFile4 = invokeurl [ url :attachmentUrl4 type :GET connection:"deskoperation" ]; downloadFile5 = invokeurl [ url :attachmentUrl5 type :GET connection:"deskoperation" ]; sendmail [ from :zoho.adminuserid to :"naveen.gs@zohocorp.com,vijaytest2607@gmail.com" subject :"Test for SubTab attachments send on tikcet closure" message :emailcontent content type :HTML Attachments :file:downloadFile,file:downloadFile1,file:downloadFile2,file:downloadFile3,file:downloadFile4,file:downloadFile5,file:downloadFile6 ] } ``` -------------------------------- ### Fetch Ticket Attachments and Send Email (1 Attachment) Source: https://github.com/zohodesk-developers/custom-function-samples/blob/master/Ticket/Send Mail/sendattachment.txt Retrieves a single attachment from a ticket and sends it via email. Ensure the 'deskoperation' connection is properly configured. ```Zoho Flow ORGID = "644088596"; emailcontent = "This is test email from zoho. please ignore this email"; //replace email text body i = 0; getTicketAttachment = invokeurl [ url :"https://desk.zoho.com/api/v1/tickets/" + ticketID + "/attachments?limit=15" type :GET connection:"deskoperation" ]; //info getTicketAttachment.get("data"); countattachment = getTicketAttachment.get("data").size(); attachment = getTicketAttachment.get("data"); //info countattachment; currentTime = zoho.currenttime.toString("yyyy-MM-dd'T'HH:mm:ss'.00Z'","GMT"); hour = currentTime.subText(currentTime.indexOf("T") + 1,currentTime.indexOf(":")); hour = hour.toNumber(); info hour; for each attach in attachment { currentTime = zoho.currenttime.toString("yyyy-MM-dd'T'HH:mm:ss'.00Z'","GMT"); hour = currentTime.subText(currentTime.indexOf("T") + 1,currentTime.indexOf(":")); hour = hour.toNumber(); cTime = attach.get("createdTime").toString(); //info cTime; hour1 = cTime.subText(cTime.indexOf("T") + 1,cTime.indexOf(":")); hour1 = hour1.toNumber(); info hour1; if(hour1 == hour) { i = i + 1; } } info i; countattachment = i; if(countattachment == 1) { attachmentUrl = attachment.get("0").getJSON("href"); downloadFile = invokeurl [ url :attachmentUrl type :GET connection:"deskoperation" ]; sendmail [ from :zoho.adminuserid to :email subject :"Test for SubTab attachments send on tikcet closure" message :emailcontent content type :HTML Attachments :file:downloadFile ] } ``` -------------------------------- ### Create Call Activity Source: https://github.com/zohodesk-developers/custom-function-samples/blob/master/Activities/Calls/Create Call Activity.txt Use this Deluge script to create a call activity in Zoho Desk. It retrieves ticket information, sets call details, and invokes the Zoho Desk API. Ensure your OAuth connection is properly configured with the necessary scopes. ```deluge ORGID = 644088596; getTicketInfo = zoho.desk.getRecordById(ORGID,"tickets",ticketID); assigneeId = getTicketInfo.get("assigneeId"); currentDeptID = getTicketInfo.get("departmentId"); Subject = "Red Happiness Rating"; Direction = "outbound"; CallStatus = "Scheduled"; createdTime = zoho.currenttime.toString("yyyy-MM-dd HH:mm:ss","GMT").toTime().addHour(1).toString("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); info createdTime; callReminderTime = zoho.currenttime.toString("yyyy-MM-dd HH:mm:ss","GMT").toTime().addMinutes(45).toString("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); info createdTime; StartTime = createdTime; ContactName = contactName.trim(); CallOwner = assigneeId; Description = "This has been escalated to the management team via workflow in Zoho Desk. We have received a Red customer happiness rating for a Desk ticket. Please ensure a member of the management team calls the client to find out more details and see if further assistance is required."; taskdetails = Map(); taskdetails.put("subject","Red Happiness Rating"); taskdetails.put("departmentId",currentDeptID); taskdetails.put("priority","High"); taskdetails.put("startTime",createdTime); taskdetails.put("direction","outbound"); taskdetails.put("contactId",contactID); taskdetails.put("status","Scheduled"); taskdetails.put("ownerId",assigneeId); taskdetails.put("duration","60"); taskdetails.put("description",Description); taskdetails.put("ticketId",ticketID); remainderMap = Map(); remainderMap.put("alertType",{"EMAIL","POPUP"}); remainderMap.put("reminderType","ABSOLUTE"); remainderMap.put("reminderTime",callReminderTime); taskdetails.put("reminder",{remainderMap}); createCall = invokeurl [ url :"https://desk.zoho.com/api/v1/calls" type :POST parameters:taskdetails + "" connection:"deskoperation" ]; //info createCall; ```