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

                                                                                                            • Collect in-app feedback with richer context and granular insights

                                                                                                              Hello, Apptics community! From GenAI chatbots to one-tap checkouts, user experience standards keep rising—yet 96% of unhappy users never explain what went wrong; they simply leave. Introducing in-app feedback 2.0 banner In-app feedback 2.0 is here to
                                                                                                            • Temporary restiction

                                                                                                              My account says You have been temporarily restricted from publishing jobs from Zoho Recruit.Click here to request a one-time approval to publish your jobs and when I go to click it shows error. Kindly assist.
                                                                                                            • Help with Quote template for peer review

                                                                                                              We are wanting to do peer review of quotes/proposals, however the quote templates dont have product cost, profit margins, etc. It is difficult for a manager to approve a quote without ensuring nothing is going out at improper margins, etc. I have not
                                                                                                            • India Tech Support

                                                                                                              Is there no phone tech support number for India? And no chat facility either?
                                                                                                            • How many AR fields We can add in a form?

                                                                                                              I want to add at least 10-15 AR fields in a form. I just want to know is there any limit on the AR fields or do I need to pay extra money for using 10-15 AR fields. Thanks in advance.
                                                                                                            • Agent working hours

                                                                                                              Hi, I know it is possible to set company business hours but is it possible so that agents can have different ones? I.e. some agents cover later hours on specific weeks - can these be set so those agents that are "working" get notified about tickets etc. 
                                                                                                            • Disallow CLOSE if tags field is empty

                                                                                                              I want to introduce a mandatory condition that NEW tickets (not prior closed tickets) cannot enter the CLOSED state without first having an entry in the tags field. Is there a way I can do this?
                                                                                                            • Central de Ajuda - Restringir visualização de tickets

                                                                                                              Estou tentando configurar o Zoho Desk para que determinados usuários dentro de uma mesma conta consigam visualizar apenas os tickets criados por usuários específicos dessa conta — e não todos os tickets ou apenas os seus próprios. Até onde sei, existe
                                                                                                            • Business Hours with lunch break

                                                                                                              Our business hours are: mon - fri 08:30 - 13:00, 15:00 - 18:30. How can I handle the lunch break? If I use 8:30 - 18:30 it obviously breaks SLA. Thanks
                                                                                                            • Default/Private Departments in Zoho Desk

                                                                                                              1) How does one configure a department to be private? 2) Also, how does one change the default department? 1) On the list of my company's Zoho Departments, I see that we have a default department, but I am unable to choose which department should be default. 2) From the Zoho documentation I see that in order to create a private department, one should uncheck "Display in customer portal" on the Add Department screen. However, is there a way to change this setting after the department has been created?
                                                                                                            • Ask the Experts 21: Power up your support game with Zoho Desk Automation

                                                                                                              " In every business, there are tasks to automate, Zoho Desk helps with features that integrate Assignments to manage tickets and teams to align,Macros for quick actions and workflows to streamline Contracts and schedules to hold things tight, Plans run
                                                                                                            • If leads are assigned to a person before 4:00 PM and the stage is "Fresh Lead", then an email should be triggered at 4:00 PM to all assigned users. If leads are assigned after 4:00 PM and the stage is

                                                                                                              If leads are assigned to a person before 4:00 PM and the stage is "Fresh Lead", then an email should be triggered at 4:00 PM to all assigned users. If leads are assigned after 4:00 PM and the stage is "Fresh Lead", then the email should be triggered the
                                                                                                            • Multiselect lookup in subform

                                                                                                              It would be SO SO useful if subforms could support a multiselect look up field! Is this in the works??
                                                                                                            • Tasks as calendar events? What about a way to verify a meeting actually happened?

                                                                                                              I'm not sure how to best ask this, but i'm looking to add some guard-rails into zoho for the end-user. However for guardrails to be effective they can't really add extra steps for the end-user. i.e. every step that's added for the user, is another place
                                                                                                            • Attachments should sync between Zoho Finance in CRM and Zoho Books

                                                                                                              It would EXTREMELY helpful and practical if the attachments added to an invoice via Zoho Finance in CRM synced with the invoice updates in Zoho Books. Currently, attachments to an invoice updated in CRM DO NOT appear as attachments when viewing the same
                                                                                                            • Introducing a new home page view and UI enhancements for Dashboards

                                                                                                              Hello everyone,  In CRM, the home pages provide a quick view of the various happenings in a business with the help of dashboards. The home pages also help to organize one's and the team's day's work. There are three views in the home tab: Classic User's
                                                                                                            • Translation support expanded for Modules, Subforms and Related Lists

                                                                                                              Hello Everyone!   The translation feature enables organizations to translate certain values in their CRM interface into different languages. Previously, the only values that could be translated were picklist values and field names. However, we have extended
                                                                                                            • Call result pop up on call when call ends

                                                                                                              I’d like to be able to create a pop up that appears after a call has finished that allows me to select the Call Result. I'm using RingCentral. I have seen from a previous, now locked, thread on Zoho Cares that this capability has been implemented, but
                                                                                                            • Data Template Amending

                                                                                                              Hi, is it possible to remove data templates once you have applied them in Workdrive? Also, once I have added a new field to a data template can I mass update multiple files who have already been allocated that template and amend just that one added
                                                                                                            • Zoho Flow y subformularios de Zoho CRM

                                                                                                              Buenas tardes, En mi empresa vamos a empezar a usar los subformularios de zoho crm pero estos los voy a tener que rellenar con zoho flow ya que va a ser el encargado de rellenar dichos campos del subformulario. El problema es que a la hora de intentar
                                                                                                            • Recurring Invoices

                                                                                                              We are looking at moving our invoices to ZOHO Billing, I have started the trial period and like that I can et up for four different companies. The one feature we need which is mentioned in the documentation is Recurring Invoices so we can send our Rent
                                                                                                            • Implement Meeting Polls in Zoho Bookings

                                                                                                              Dear Zoho Bookings Support Team, We'd like to propose a feature enhancement related to appointment scheduling within Zoho Bookings. Current Functionality: Zoho Bookings excels at streamlining individual appointment scheduling. Users can set availability
                                                                                                            • Zoho Projects App update: Arabic and Hebrew language support

                                                                                                              Hello everyone! In the latest version(v3.10) of the Zoho Projects iOS app update, we have brought in support to access the app in RTL(Right to Left) languages (Arabic and Hebrew). Note: RTL is yet to be supported on the Calendar and Gantt charts modules
                                                                                                            • I want to cancel @mention group in the notes in Zoho CRM

                                                                                                              Hi Everybody, I want to prevent people from mentioning a specific group in notes in Zoho CRM. We have one group called Team Sales, and although we've asked users not to mention groups, they still mention the group name. My workaround is to change the
                                                                                                            • 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.
                                                                                                            • How to install node packages in Zoho Creator cloud functions

                                                                                                              I wanted to create some functions which requires node packages like axios, fetch, multer etc., How and where can i install the node packages in Zoho creator to use it in Zoho creator Nodejs function.
                                                                                                            • Session "Ask Me Anything" Zoho France - Le 26 Juin 2025 14h à 17h (en Français

                                                                                                              Chers Utilisateurs, Vous cherchez à mieux comprendre Zoho CRM ou Zoho Desk ? Nos experts seront disponibles pour répondre à toutes vos questions lors de notre session Ask Me Anything. Rejoignez-nous ici pour en discuter en ligne. Pendant trois heures,
                                                                                                            • Option to Crop Existing Agent Image in Zoho One Directory

                                                                                                              Hello Zoho Team, We hope you're all doing well. We would like to request a small but useful enhancement to the Zoho One Directory. 🎯 Current Limitation At present, the system allows cropping an agent image only during the initial upload of an agent's
                                                                                                            • Introducing Sub-Accounts in Zoho Books!

                                                                                                              Hello Everyone, Sub-Accounts is LIVE! Yes, you read it right. The much needed and most requested feature is now live in Zoho Books. The sub-accounts feature in Zoho Books will help you to classify your accounts further which will give you a more detailed view of your accounts while running reports. You can create sub-accounts for the below Accounts: Asset Cost of Goods Sold Expense Liability Fixed Asset Other Asset Other Current Asset Long Term Liability Other Current Liability Other Liability Other
                                                                                                            • Sesión "Ask me anything" Zoho en Español - 26 de junio de 2025, de 14:00 a 17:00 (en español)

                                                                                                              ¡Hola Comunidad! ¿Quieres entender mejor Zoho CRM o Zoho Desk? Nuestros expertos estarán disponibles para responder a todas tus preguntas durante nuestra sesión "Ask me anything". Puedes comentar este artículo y durante tres horas, nuestro equipo estará
                                                                                                            • UI Update: We've Reorganized Invoice Settings

                                                                                                              Dear users, We’ve reorganized invoice settings to offer you a streamlined and intuitive experience when managing your subscriptions. Starting from 2 July 2025, subscription-related invoice settings will be accessible from a new page called Billing Preferences
                                                                                                            • Marketer’s Space – Automate Subscription Management for CRM Contacts Using Workflows in Zoho Campaigns

                                                                                                              Hello, marketers! Welcome back to Marketer’s Space. In this week’s post, we’ll look at how to simplify subscription management using Workflows for contacts synced from Zoho CRM in Zoho Campaigns. There are multiple ways to assign topics to your contacts:
                                                                                                            • CRM and Finance Tab - Add Invoice "Subject " Column

                                                                                                              When On a contact in CRM, and you click the Zoho Finace tab, how can I put in the invoice subject line? Or even a custom field for this.  We need to see what that invoice is for, without opening it.   If we have tons of invoices we need a way to quick
                                                                                                            • WhatsApp to shift to per-message billing from July 1, 2025

                                                                                                              Greetings Recruiters, If you’re using WhatsApp to connect with candidates through Zoho Recruit, there’s an important pricing change coming up that you’ll want to plan for. What’s changing? Starting July 1, 2025, WhatsApp is moving away from conversation-based
                                                                                                            • Implement full RTL support in Zoho Cliq, including text alignment and character positioning, regardless of the interface language.

                                                                                                              Dear Zoho Cliq Support Team, We are writing to request a significant enhancement to the current RTL language support within Zoho Cliq. Currently, while Zoho Cliq allows users to input text in RTL languages, the text alignment remains LTR, resulting in
                                                                                                            • Email Alerts with Affected Flow Details When Deprecating Modules in Zoho Flow

                                                                                                              Dear Zoho Flow Team, We would like to request an enhancement to the module deprecation process in Zoho Flow. 🧩 Current Limitation: Currently, when a module is deprecated by the Flow team: No email notifications are sent. There is no automated way to
                                                                                                            • are there Url parameters to group records in the report/view?

                                                                                                              There are URL parameters to filter records in target report.  Is there any way to group records in report by certain field, using URL parameters or embed report parameters? Or any other workaround, apart from creating second report for dofferent grouping?  Aim: I want to provide user a quick link to re-group embed report by different fields.
                                                                                                            • Setvalue() client script not working

                                                                                                              I have created a client script on the load the record(detail view page). I wanted to populate some default information in the single line field. for that I created the client script. below is the script: var field_obj = ZDK.Page.getField( 'Designation'
                                                                                                            • Power of Automation :: Automate Deal Status Update in Zoho CRM upon Project Completion.

                                                                                                              Hello Everyone, A Custom function is a user-written set of code to achieve a specific requirement. Set the required conditions needed as when to trigger using the Workflow rules (be it Tasks / Project) and associate the custom function to it. Requirement:
                                                                                                            • Leverage the power of Zia (AI) to create Marketing Projects in Zoho Marketing Plus

                                                                                                              Hey everyone, Zoho's advanced AI assistant, Zia, now works with OpenAI to offer personalized marketing activity suggestions for your marketing projects in Brand Studio. With information such as your campaign's objective, duration, marketing channel types,
                                                                                                            • Next Page