Automatic Mail-Merge Document Creation Using Zoho CRM APIs

Automatic Mail-Merge Document Creation Using Zoho CRM APIs

Efficient communication and personalized document generation are crucial for maintaining strong customer relationships in your business. Manual document generation can be time-consuming, repetitive and error-prone, decreasing productivity and customer satisfaction. You can solve this with automatic document generation by creating merged documents from predefined mail merge templates.
With Zoho CRM's mail merge templates you can create personalized documents, including forms, envelopes, and letters, by utilizing variables also known as merge fields. These templates enable you to merge data from variables, ensuring accurate information is incorporated into the documents without the need for manual data entry for each record. For additional information, please consult the guidelines on Managing Mail Merge Templates. 

In Zoho CRM, you can automate document generation using its mail merge template APIs. You can send, sign, and download customized documents automatically. 
Send Mail Merge API : To send emails to users using mail merge template. You can also attach files either as inline images or separate attachments with the email through the API.
Sign Mail Merge API : To sign and approve a merged document.
Download Mail Merge API: To download a mail merged document.

Let us discuss two use cases where these APIs are used. Assume you manage your business for a technological company, Zylker Technologies, using Zoho CRM. 

Prerequisites
  • Create a connector with required scopes. For the below use cases a connector with the below scopes was created -ZohoSign.documents.ALL, ZohoCRM.modules.ALL, ZohoWriter.documentEditor.ALL, ZohoWriter.Merge.ALL, ZohoCRM.settings.mailmerge.CREATE

Use Case 1: Using Mail Merge APIs for sending Letter of Intent for customers
 Let us consider a scenario where you want to send a LOI (Letter of Intent) to be signed by your customer. A Letter of Intent is a formal document that contains a preliminary agreement and commitment to move forward with the deal, outlining key terms and conditions. You can create a mail merge template for your LOI with merge fields from your Customer module. You can find mail merge templates in Zoho CRM UI under Setup > Customization > Templates > Mail Merge. Refer the below image for a sample LOI mail merge template. 

Sample Mail Merge Template for Letter of Intent

Note that the merge fields given in the mail merge template are fields from Accounts module (renamed as Customers) with additional custom fields.
You can automate sending the LOI to your customer using a custom button with an associated function for the Customers module. In this case, a custom button "send LOI" is added as shown in the screenshot below.
Screenshot of Customer module showing sendLOI button

The below function calls sign mail merge API which sends the merged letter of intent document to your customer for signing.  The customer will receive an email notification containing the document which can be signed using Zoho Sign. Sign mail merge API's response includes a Zoho Writer document link that can be used to track the signing status. In the below function, the system will send mail to the customer along with the mail-merged document for them to sign, and it will store the link to track the sign status in a custom URL field named Document Sign Details.  This field allows you to access and review the document from your record conveniently.

customerMap = zoho.crm.getRecordById("Accounts",customerId.toLong());
name = customerMap.get("Account_Name");
to_email = customerMap.get("customer_Email");
merge_template_name = "LOI";
//Replace with your mail merge template name
info name;
info to_email;
input_json = "{'sign_mail_merge':[{'mail_merge_template':{'name':'" + merge_template_name + "'},'file_name':'letterofintent','sign_in_order':false,'signers':[{'recipient_name':'" + name + "','action_type':'sign','recipient':{'type':'email','value':'" + to_email + "'}}]}]}";
header_data = Map();
header_data.put("Content-Type","application/json");
response = invokeurl
[
url :"https://www.zohoapis.com/crm/v5/Accounts/" + customerId.toLong() + "/actions/sign_mail_merge"
type :POST
parameters:input_json
connection:"zylkercrm"
];
//Replace above connection name with your connection name
info response;
details = response.getJSON("sign_mail_merge").toJSONList();
link = "";
for each  detail in details
{
link = detail.get("details").get("report_link");
info link;
}
mp = Map();
mp.put("Document_Sign_Details",link);
update = zoho.crm.updateRecord("Accounts",customerId.toLong(),mp);
return "";

The system sends a merged document, as shown in the screenshot below, to the customer.
Final Merged Document sent to Customer

Use case 2: Using mail merge API for sending different types of SLA 
Assume that in Zylker Technologies, when you sell a product, your customer can opt for different types of after sales support . A check list field - Support Type - indicates type of support - Standard or Premium.  SLA document(Service Level Agreement) is a contract between you and your customer that defines level of service and the metrics used to measure the service.The service level provided to different customers will be different based on the kind of support they opted for and you need to send different SLA document based on this.  This can be achieved by maintaining two SLA mail merge templates. 
Similar to use case 1, a custom button can invoke the below function and in the function, a mail merge template is selected based on the type of service provided. The support_Type fields gets the value of the "Support Type" check list. Merge mail template is decided based on this field and send mail merge API is called to send the merged document. After sending the mail with appropriate mail merge template document, the function downloads the merged document and uploads it to the Attachments related list. 
Using download mail merge API, the merged document is obtained and then attached to the Contacts module with the attachFile function.


customerMap = zoho.crm.getRecordById("Accounts",customerId.toLong());
to_email = customerMap.get("customer_Email");
from_email = customerMap.get("Owner").get("email");
support_Type = customerMap.get("Support_Type");
if (support_Type == "Premium" )
{
merge_template_name = "SLA_Premium";
}
else 
{
merge_template_name = "SLA_Std";
}
//Replace above merge template names with your merge template names
input_json = "{'send_mail_merge':[{'mail_merge_template':{'name':'" + merge_template_name + "'},'from_address':{'type':'email','value':'" + from_email + "'},'to_address':[{'type':'email','value':'" + to_email + "'}],'subject':'Hi there','type':'attachment','attachment_name':'testdocument','message':'Big Deal'}]}";
header_data = Map();
header_data.put("Content-Type","application/json");
response = invokeurl
[
url :"https://www.zohoapis.com/crm/v5/Accounts/" + customerId + "/actions/send_mail_merge"
type :POST
parameters:input_json
connection:"zylkercrm"
];
//Replace above connection name with your connection name
input_json = "{'download_mail_merge':[{'mail_merge_template':{'name':'" + merge_template_name + "'},'output_format':'pdf'}]}";
header_data = Map();
header_data.put("Content-Type","application/json");
//The merged document is stored to file_object
file_object = invokeurl
[
url :"https://www.zohoapis.com/crm/v5/Accounts/" + customerId.toLong() + "/actions/download_mail_merge"
type :POST
parameters:input_json
connection:"zylkercrm"
];
//Replace above connection name with your connection name
response = zoho.crm.attachFile("Accounts",customerId,file_object);
return "";

The benefits of using the mail merge template APIs from Zoho CRM, which enable automated document generation, are highlighted in this article. These APIs enable the easy customization of the documents like Letters of Intent (LOIs), Service Level Agreements (SLAs), Request for Proposal (RFPs), etc. Businesses can increase efficiency, accuracy, and customer happiness by automating this procedure.
We hope you found this article useful. We will be back next week with another interesting topic. If you have any questions, write to us at support@zohocrm.com or let us know in the comment section. 

    Access your files securely from anywhere







                            Zoho Developer Community





                                                  Use cases

                                                  Make the most of Zoho Desk with the use cases.

                                                   
                                                    

                                                  eBooks

                                                  Download free eBooks and access a range of topics to get deeper insight on successfully using Zoho Desk.

                                                   
                                                    

                                                  Videos

                                                  Watch comprehensive videos on features and other important topics that will help you master Zoho Desk.

                                                   
                                                    

                                                  Webinar

                                                  Sign up for our webinars and learn the Zoho Desk basics, from customization to automation and more

                                                   
                                                    
                                                  • Desk Community Learning Series


                                                  • Meetups


                                                  • Ask the Experts


                                                  • Kbase


                                                  • Resources


                                                  • Glossary


                                                  • Desk Marketplace


                                                  • MVP Corner




                                                            • Sticky Posts

                                                            • Kaizen #197: Frequently Asked Questions on GraphQL APIs

                                                              🎊 Nearing 200th Kaizen Post – We want to hear from you! Do you have any questions, suggestions, or topics you would like us to cover in future posts? Your insights and suggestions help us shape future content and make this series better for everyone.
                                                            • Kaizen #198: Using Client Script for Custom Validation in Blueprint

                                                              Nearing 200th Kaizen Post – 1 More to the Big Two-Oh-Oh! Do you have any questions, suggestions, or topics you would like us to cover in future posts? Your insights and suggestions help us shape future content and make this series better for everyone.
                                                            • Celebrating 200 posts of Kaizen! Share your ideas for the milestone post

                                                              Hello Developers, We launched the Kaizen series in 2019 to share helpful content to support your Zoho CRM development journey. Staying true to its spirit—Kaizen Series: Continuous Improvement for Developer Experience—we've shared everything from FAQs
                                                            • Kaizen #193: Creating different fields in Zoho CRM through API

                                                              🎊 Nearing 200th Kaizen Post – We want to hear from you! Do you have any questions, suggestions, or topics you would like us to cover in future posts? Your insights and suggestions help us shape future content and make this series better for everyone.
                                                            • Client Script | Update - Introducing Commands in Client Script!

                                                              Have you ever wished you could trigger Client Script from contexts other than just the supported pages and events? Have you ever wanted to leverage the advantage of Client Script at your finger tip? Discover the power of Client Script - Commands! Commands


                                                            Manage your brands on social media



                                                                  Zoho TeamInbox Resources



                                                                      Zoho CRM Plus Resources

                                                                        Zoho Books Resources


                                                                          Zoho Subscriptions Resources

                                                                            Zoho Projects Resources


                                                                              Zoho Sprints Resources


                                                                                Qntrl Resources


                                                                                  Zoho Creator Resources



                                                                                      Zoho CRM Resources

                                                                                      • CRM Community Learning Series

                                                                                        CRM Community Learning Series


                                                                                      • Kaizen

                                                                                        Kaizen

                                                                                      • Functions

                                                                                        Functions

                                                                                      • Meetups

                                                                                        Meetups

                                                                                      • Kbase

                                                                                        Kbase

                                                                                      • Resources

                                                                                        Resources

                                                                                      • Digest

                                                                                        Digest

                                                                                      • CRM Marketplace

                                                                                        CRM Marketplace

                                                                                      • MVP Corner

                                                                                        MVP Corner







                                                                                          Design. Discuss. Deliver.

                                                                                          Create visually engaging stories with Zoho Show.

                                                                                          Get Started Now


                                                                                            Zoho Show Resources


                                                                                              Zoho Writer Writer

                                                                                              Get Started. Write Away!

                                                                                              Writer is a powerful online word processor, designed for collaborative work.

                                                                                                Zoho CRM コンテンツ








                                                                                                  Nederlandse Hulpbronnen


                                                                                                      ご検討中の方




                                                                                                            • Recent Topics

                                                                                                            • How to see history on Bulk send of Customer Statements

                                                                                                              Hi, We bulk send statements to customers every month via Books - every month we have customers emailing requesting a statement. Currently I have no visibility on if a customer was sent the statement or not and if our process is being followed or overlooked
                                                                                                            • Guided Conversations - Ticket Creation

                                                                                                              Hi there, Using Guided Conversations to Take Customer Data and apply it into a Support Ticket for internal use, Is there a way to take multiple Textual Variables Inputs (A series of questions), and have the answers all appear in the Description of the
                                                                                                            • How to add buttons elements in the Header

                                                                                                              I am trying to add CTA (Call to Action) buttons in the right side of the main navigation menu. This is a common practice for sites but I can't seem to figure this out for Zoho Sites. Is there a custom workflow that could be shared with me? 
                                                                                                            • Automatic back up - Zoho Recruit, books, people,crm, analytics

                                                                                                              Hello, Has anyone found a good way of automatically backing up Zoho (CRM, expense, recruit, people, books, analytics).? I have found with tool that does, but it doesn't include recruit or analytics It's a bit annoying and time consuming having to go to
                                                                                                            • delete departments on zoho desk

                                                                                                              I created test departments on zoho desk. how can i delete them now?
                                                                                                            • Validation, checking if a file has been attached to the ticket

                                                                                                              A very useful option would be to allow checking, under specific conditions, whether the user has attached a file to the application, e.g., a bug report. Some applications require files to be attached, and the system could enforce this after the system
                                                                                                            • AI & Zoho Recruit

                                                                                                              Hello, I guess we all are using AI in our personal and professional lives. Now, let's imagine. Recruitment is just a succession of stages and steps. For which step would you like to see AI implemented into Zoho Recruit ? I'll start : - Automatic translation
                                                                                                            • Zoho Flow not handling Boolean properly

                                                                                                              Hi, I have a checkbox in one system that I'm trying to sync with a checkbox in Zoho CRM. The value from the source system comes in as blank (unticked) or 1 (ticked). I've written the following custom function to convert the output to either boolean false
                                                                                                            • Quotes Module - import data

                                                                                                              Hello Zoho, is it possible to import Quotes records? I was trying and i have no results. Raport shows no data imported. Could you help me please how to do it?
                                                                                                            • Balance Sheet - Zoho Analytics

                                                                                                              Hi Team, I’m looking to implement a feature that captures the conversion rate based on the filters applied. By default, it should fetch the most recent conversion rate, and when a filter (such as a timeline filter) is applied, it should return the conversion
                                                                                                            • files sent will not open for recipient

                                                                                                              work files (done in writer) which previously opened will not open for the recipient
                                                                                                            • How to Print the Data Model Zoho CRM

                                                                                                              I have created the data model in Zoho CRM and I want the ability to Print this. How do we do this please? I want the diagram exported to a PDF. There doesnt appear to be an option to do this. Thanks Andrew
                                                                                                            • Cisco Webex Calling Intergration

                                                                                                              Hi Guys, Our organisation is looking at a move from Salesforce to Zoho. We have found there is no support for Cisco Webex Calling however? Is there a way to enable this or are there any apps which can provide this? Thanks!
                                                                                                            • Migration of Mails from Pipedrive

                                                                                                              Hi, so far the migration from Pipedrive to ZOHO works pretty good. For full completeness of the migration we miss all the mails linked to Deals, Contacts, Customers, ... What possibilities do we have to have Pipedrive fully migrated to ZOHO? Best Regards,
                                                                                                            • Published sheets don't work anymore

                                                                                                              Hi, Published sheets don't work anymore. The display of values is very very slow and calculations are not displayed at all. Thanks!
                                                                                                            • WorkDrive TrueSync for macOS 26 (Tahoe) Beta

                                                                                                              Hello everyone, With Apple unveiling the macOS 26 (Tahoe) Beta, we know many of you are eager to explore the latest features and enhancements. We’re excited to support your enthusiasm! As part of our commitment to delivering seamless cross-platform experiences,
                                                                                                            • Limited layout rules in a module

                                                                                                              There is a limit of 10 layout rules per module. Is there a way to get that functionality through different customization or workflow + custom function (easily accessible), etc. Having just 10 is limiting especially if module contains a lot of data. Are
                                                                                                            • #1 Zoho Billing vs. Zoho Books: Which one should I choose?

                                                                                                              Managing your business finances isn't just about sending invoices. It's about keeping everything organized, accurate, and moving towards your organization's goals. At Zoho, we understand the complexity, which is why we offer two powerful yet distinct
                                                                                                            • Is Zoho tables still being developed?

                                                                                                              Has this product been abandoned? I haven't seen any useful new features or stability improvements over the past six months or more. I think Tables is a great concept, filling a niche between spreadsheets and full database tools, but the current implementation
                                                                                                            • How to connect oracle ADW with Analytics

                                                                                                              I want to add Oracle ADW as a data source in Zoho Analytics, but I couldn't find any relevant documentation. Can anyone suggest how to do it, or let me know if it's even possible? Thanks!!
                                                                                                            • RAG (Retrieval Augmented Generation) Type Q+A Environment with Zoho Learn

                                                                                                              Hi All, Given the ability of Zoho Learn to function as a knowledge base / document repository type solution and given the rapid advancements that Zoho is making with Zia LLM, agentic capabilities etc. (not to mention the rapid progress in the broader
                                                                                                            • add attachments to automated emails?

                                                                                                              Hi, I'm looking for a way to have documents saved under an account, be grabbed and sent to an email address once a specific status has been updated.  For example we have a tab we've labeled as sales orders, when the status is changed to shipped, it emails the customer the tracking number and estimated delivery date.  I'd like it to also grab pdf docs (COA, BOL, etc) from that order and send in that email.   Currently we have to go into zoho change the status to shipped, then email all the docs to
                                                                                                            • [Action Required] Zendesk - Zoho Analytics integration requires re-authentication

                                                                                                              Dear Zendesk integration users, Zendesk is transitioning to a new OAuth model that uses refresh tokens for improved security and stability (read more). As a result, all Zendesk users in Zoho Analytics must re-authenticate their Zendesk connections on
                                                                                                            • Rerun Migration?

                                                                                                              I migrated a mailbox a few days ago, but didn't do the cutover on the MX records until today.  How can I rerun the migration to sync the mailboxes?  The old account has had a fair amount of activity since the first migration. I am used to other systems
                                                                                                            • طلب حذف الدومين والمؤسسة من حساب zoho

                                                                                                              السلام عليكم، أود طلب حذف الدومين التالي من حسابي في Zoho، حيث لا يظهر لي خيار الحذف في لوحة التحكم: اسم الدومين: hudajstore.com البريد المرتبط: [contact@hudajstore.com] علمًا بأنني المسؤول عن المؤسسة، ولا أستخدم الدومين حاليًا، وأرغب في إلغاء ربطه وحذف
                                                                                                            • Microsoft Outlook Add-in Update: Enhancing Efficiency for Recruiters

                                                                                                              We've released an update to the Zoho Recruit Microsoft Outlook Add-in, which brings a host of features designed to streamline your recruiting process and boost productivity. Let's delve into the details: Associate Emails with records in Zoho Recruit You
                                                                                                            • New integration: Zoho Books + Zoho Forms

                                                                                                              Hello Zoho Forms community! We are thrilled to announce the addition of another integration that brings speed and efficiency to your financial workflows. Zoho Forms can now be integrated with Zoho Books! Here’s a quick rundown on Zoho Books! For anyone
                                                                                                            • Witness Sign - Automation with Zoho Creator

                                                                                                              Hi there, I used to be able do automatically send a Zoho Sign document from Zoho Creator where each signer had one witness. The action code was as follows for each signer and witness:       // CLIENT eachActionMap1 = Map(); eachActionMap1.put("signing_order","1");
                                                                                                            • Announcing: custom color palette + free workshop

                                                                                                              Hello everyone, We're excited to share new feature in Zoho Bookings—a color palette within booking page themes. You'll find this option under Manage Bookings > Workspaces > Booking Page Themes. You can customize the color of every element in your booking page and even alter the transparency of your background image. Please note that this is a paid feature included in the Basic and Premium plans. At the moment, it's available only under the Modern Web theme. This means you can create billions (7,
                                                                                                            • Removing To or CC Addresses from Desk Ticket

                                                                                                              I was hoping i could find a way to remove unnecessary email addresses from tickets submitted via email. For example, a customer may email the support address AND others who are in the helpdesk notification group, in either the TO or CC address. This results
                                                                                                            • Ability to Export Field Dependency Structure in Zoho Desk

                                                                                                              Hi Zoho Team, We’d like to request a feature enhancement in Zoho Desk that would greatly improve configuration management for organizations like ours: Requested Feature: The ability to export the full structure of Field Dependencies, especially for multi-level
                                                                                                            • [URGENT] Allow reorder (drag&drop) of subform record

                                                                                                              Very simple user case: a wedding planning app where you want to send your client a form to fill with information about their wedding. Form includes some field for general purpose information and a subform for event pacing/schedule. Clients are invited to create a new row (When? - What? - Where? - Who?) for each thing happening during their wedding chronologically. Ex: When                  What 10h                      Something TBD                    Speech After speech      Yet another thing happening
                                                                                                            • Departments in Zoho

                                                                                                              I'm trying to set up a department. It looks like Departments have been removed from Zoho One. Is there another option? We have our main account setup, but want to set up a separate small department that can't see our tabs.
                                                                                                            • Add Timer for Agent Status Duration in Zoho Desk Dashboard

                                                                                                              Hello Zoho Desk Team, We hope you're doing well. We would like to submit a feature request to further enhance the agent status tracking functionality within the Zoho Desk Dashboard. 🎯 Current Functionality As it stands, Zoho Desk allows us to view the
                                                                                                            • [Beta Feature] Parent-Child Ticketing

                                                                                                              Hello there, a beta parent-child ticketing feature has recently been made available for some, read more here: https://help.zoho.com/portal/en/kb/desk/ticket-management/articles/understanding-parent-child-ticketing-system#Business_scenarios I would like
                                                                                                            • Enable Sorting by Ticket Count in Category Reports

                                                                                                              Hi Zoho Desk Product Team, I hope you're doing well. We would like to submit a feature request to improve the reporting capabilities in Zoho Desk. 🎯 Feature Request: Sorting by Ticket Count in Category Reports Currently, category-based reports in Zoho
                                                                                                            • Reactivating a CRM user...

                                                                                                              I'm a 1-man business primarily using CRM under my Zoho1 subscription (I have NO other employees or users). I wish to re-activate a prior user (my son, once more working with me) but when changing his status from inactive to active I receive this message:
                                                                                                            • Zohoサポートにスコープ開放を依頼する

                                                                                                              お世話になっております。 現在、弊社にてZoho DeskのナレッジベースをAPI経由で取得し、AIツール(NotebookLM等)に連携する仕組みの構築を検討しています。 つきましては、ZohoDesk.articles.READ スコープを使用したOAuth認証の許可をいただけますでしょうか。 API Console から Server-based アプリを作成済みですが、認可URLにアクセスすると「スコープが登録されていません」と表示されます。 お手数をおかけしますが、スコープの開放をご
                                                                                                            • Where can I configure the notifications for everything KB-related?

                                                                                                              Hi all, I'm receiving notifications for some actions happening in our Knowledge Base (e.g. someone leaving a feedback) and I would like to customise the template or have the choice to enable/disable such notifications like it is possible for ticket notification
                                                                                                            • Increase Round Robin Scheduler Frequency in Zoho Desk

                                                                                                              Dear Zoho Desk Team, We hope this message finds you well. We would like to request an enhancement to the Round Robin Scheduler in Zoho Desk to better address ticket assignment efficiency. Current Behavior At present, the Round Robin Scheduler operates
                                                                                                            • Next Page