Auto-Sync Zoho Desk Ticket Attachments to Zoho CRM Contacts
Overview:
When Zoho CRM is integrated with Zoho Desk, contacts from CRM are automatically synced into Desk. These contacts can raise tickets in Zoho Desk, which often include important attachments like images, documents, or logs. In many cases, businesses want to ensure these attachments are also available in the CRM for easy access and future reference.
This article explains how to automate the process of fetching attachments from the latest thread of a Zoho Desk ticket and uploading them to the corresponding contact's record in Zoho CRM using a custom function and a workflow rule.
Business case:
In customer-facing organisations using Zoho CRM and Zoho Desk, it’s common for support tickets submitted via Desk to include important attachments such as invoices, screenshots, legal documents, contracts, and more. However, these attachments remain separated within Desk and are not automatically synced to the associated Contact or Account in Zoho CRM.
For teams that rely on CRM as the single source of truth for customer profiles and documents, this leads to:
By automating the syncing of ticket attachments from the latest customer reply in Desk to the Attachments related list of the corresponding CRM contact, you:
Ensure CRM always has the latest files
Improve visibility for sales/account teams
Avoid manual downloading and reuploading
Streamline customer data consolidation
This automation especially benefits teams managing high ticket volumes, where manual syncing is not scalable.
Navigate to Zoho Desk > Settings > Automation > Workflows.
Click Create Workflow Rule.
Name the rule and choose Trigger: Customer Reply.
Define conditions as required.
Under Action, choose Custom Function.
Map the argument ticketid with the ticket ID.
Paste the custom function code provided below.
Code:
ticketInfo = invokeurl
[
url :"https://desk.zoho.com/api/v1/tickets/" + ticketid + ""
type :GET
connection:"desk"
];
contactId = ticketInfo.getJSON("contactId");
contactInfo = invokeurl
[
url :"https://desk.zoho.com/api/v1/contacts/" + contactId + ""
type :GET
connection:"desk"
];
info contactInfo;
crmContactID = contactInfo.getJSON("zohoCRMContact").get("id");
latestThreadInfo = invokeurl
[
url :"https://desk.zoho.com/api/v1/tickets/" + ticketid + "/latestThread"
type :GET
connection:"desk"
];
attachmentsInfo = latestThreadInfo.get("attachments");
for each attachment in attachmentsInfo
{
attachmentURL = attachment.get("href");
fileName = attachment.get("name");
getAttachment = invokeurl
[
url :attachmentURL
type :GET
connection:"testa"
];
if(getAttachment != null)
{
if(isText(getAttachment))
{
getAttachment = getAttachment.toFile(filename);
}
param = Map();
param.put(fileName,getAttachment);
getAttachment.setParamName("file");
info "getAttachment:" + getAttachment;
uploadAttachment = zoho.crm.attachFile("Contacts",crmContactID,getAttachment,"crm");
info uploadAttachment;
}
}
Screenshots for reference:


API References:Note: This method works only if your contacts in Desk are synced via Zoho CRM. The zohoCRMContact ID is essential for locating the corresponding record in CRM.

Note: This related Zoho CRM contact ID will be available in the case of contact synced via Zoho CRM - Zoho Desk Integration.
Output:
Every time a customer responds to a ticket in Zoho Desk with an attachment, the file will automatically be uploaded to the related contact in Zoho CRM.
Screenshot of attachments in Zoho Desk:

Screenshots of attachments in related contacts in Zoho CRM:

Conclusion:
By configuring this automation, you can streamline the way your organisation manages customer-related files. It eliminates the need for manual file uploads between Zoho Desk and Zoho CRM and ensures all customer-related documents are accessible directly from CRM.
Custom Solution Created by Santhiya| Zoho Partner Support