How send a ticket attachment using the Sendreply API in Zoho Desk
API document references :
you make use of the
Upload file API and gather the attachment ID. This ID is be
passed
with the
Send email Reply API to deliver responses with the attachment intact.
Code template is as below:
- // ORGID
- ORGID = "XXXXXXX"; // Masked Org ID
- ApiUrl = "https://desk.zoho.com/api/v1";
- // Get Contact data
- getData = zoho.desk.getRecordById(ORGID, "tickets", TicketID);
- ContactID = getData.get("contactId");
- getContact = zoho.desk.getRecordById(ORGID, "contacts", ContactID);
- // update ticket with contact's phone number
- updateTicket = zoho.desk.update(ORGID, "tickets", TicketID, {"phone": getContact.getJSON("phone")});
- // Get thread attachments
- getthreadattachment = zoho.desk.getRelatedRecordById(ORGID, "threads", "XXXXXXX", "tickets", TicketID).getJSON("attachments");
- attachss = List();
- if(getthreadattachment != null && getthreadattachment.size() > 0)
- {
- for each attach in getthreadattachment
- {
- attachid = attach.get("id");
- fileName = attach.get("name");
- if(isText(attach))
- {
- attach = attach.toFile(fileName);
- }
- attach = attach.toFile(fileName);
- attach.setParamName("file");
-
- param = Map();
- param.put(fileName, attach);
-
- uploadattachments = invokeurl
- [
- url : ApiUrl + "/uploads"
- type : POST
- parameters: param
- headers: { "Content-Type": "multipart/form-data" }
- connection: "XXXX" // Masked connection type
- ];
-
- newattachid = uploadattachments.get("id");
- attachss.add(newattachid);
- info attachss;
- }
- }
- // Prepare to render email template
- templateId = "XXXXXXX"; // Masked template ID
- Render = invokeurl
- [
- url : ApiUrl + "/templates/" + templateId + "/render?entityId=" + TicketID
- type : POST
- connection: "XXXX" // Masked connection type
- ];
- contentEmail = Render.getJSON("body");
- Mappy = Map();
- Mappy.put("to", "masked_email@example.com"); // Masked recipient email
- Mappy.put("content", contentEmail);
- Mappy.put("contentType", "html");
- Mappy.put("fromEmailAddress", "masked_sender@example.com"); // Masked sender email
- Mappy.put("channel", "EMAIL");
- Mappy.put("isForward", "false");
- Mappy.put("attachmentIds", attachss);// input the attachmentid
- sendResponsess = invokeurl
- [
- url : ApiUrl + "/tickets/" + TicketID + "/sendReply"
- type : POST
- parameters: Mappy + ""
- connection: "XXXX" // Masked connection type
- ];
- info sendResponsess;
Explanation:
- Fetching Ticket Details: The script retrieves ticket and contact information to update the ticket’s phone number.
- Uploading Attachments: It gathers any attachments from the ticket's threads and uploads them to the Zoho Desk system.
- Sending Emails: Finally, it prepares an email using a specified template and includes any uploaded attachments before sending.
Feel free to adapt this code for your own ticket handling processes in Zoho Desk! Just remember to replace the masked values with your actual data when implementing.
Happy coding!