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

                                                                                                            • Set Conditional and Dependent Rules for Issues in Zoho Projects

                                                                                                              An Issue Layout is a customizable form to add and update information about a specific issue. The fields in the issue layout can be changed dynamically based on user requirement using the issue layout rules. Consider a scenario where an electrical fluctuation
                                                                                                            • Accounting on the Go Series-56: e-Way Bill Module in the Mobile App – A Handy Solution for Indian Businesses

                                                                                                              Hello everyone, Managing e-Way bills just got more convenient with the Zoho Books mobile app! For businesses operating under the GST regime, e-Way bills are essential for tracking the movement of goods. Previously, you had to log in to the web app to
                                                                                                            • Copying records from a Custom Module into Deals

                                                                                                              Hello, I recently created a custom module to handle a particular type of order/transaction in our business. Having got this up and running I've realised that it would be much better to use the Deals module with a different layout instead. We've entered
                                                                                                            • Creator App on Mobile - Workflow "On Create / Edit - On Load" not triggered ?

                                                                                                              Hi Everyone, I built an application to track assets, which is used both at the office (desktop) an in the field by technicians (mobile app). In the field, technicians open an existing form and add rows to a subform at some point. One field they have to
                                                                                                            • HOW TO VIEW INDIVIDUAL COST OF NEWLY PURCHASED GOODS AFTER ALLOCATING LANDED COSTS

                                                                                                              Hello, I have been able to allocate landed costs to the purchase cost of the new products. however, what i need to see now is the actual cost price (original cost plus landed cost), of only my newly purchased products to enable me set a selling price
                                                                                                            • Custom Function to get custom field of lookup type in Books

                                                                                                              Hi, Here's the situation. In Purchase Order, there is a custom field (lookup) to SO. The requirement is to update to the related SO if PO get updated Right now facing challenge to get the id of custom field (lookup) in PO. Please find below the sample
                                                                                                            • Custom From Address is now Organizational Email

                                                                                                              We're introducing a small yet meaningful change in Zoho Recruit, one that sets the foundation for bigger improvements coming your way. What’s changed? We’ve renamed the Custom From Address to Organizational Email. The new name was chosen to better reflect
                                                                                                            • What's New in Zoho Billing Q2 2025

                                                                                                              Hello everyone, We are excited to share the latest set of updates and enhancements made to Zoho Billing in Q2 2025, ranging from image custom fields to support for new languages. Keep reading to learn more. Upload Images From Your Desktop to Email Notifications
                                                                                                            • Map dependency on Multiselect picklist

                                                                                                              I need help in Zoho CRM. I have 2 multi-select picklists. For example, Picklist A has country names. Picklist B has state names. Now I want to show states on the basis of the selected country from Picklist A. Both are multi-select fields, so the standard
                                                                                                            • Tip of the Week #63 – Keep personal emails out of team view.

                                                                                                              Shared inboxes are great for teamwork—they let everyone stay on the same page, respond faster, and avoid duplicate replies. But not every message needs to be shared with the entire team. Think about those one-on-one chats with a manager, a quick internal
                                                                                                            • Episode III : Powering Automation: Custom Functions in Action

                                                                                                              Hello Everyone, In our previous episodes, we explored custom functions and the Deluge programming language. If you’ve been wondering why the Episode series have been quiet, here’s the reveal! On our community, we've been showcasing custom functions integrated
                                                                                                            • Narrative 2 - Understanding Organizational Departments

                                                                                                              Behind the scenes of a successful ticketing system - BTS Series Narrative 2 - Understanding Organizational Departments A ticketing system's departments are essential because they provide an organized and practical framework for handling and addressing
                                                                                                            • Zoho Projects Plus for the healthcare industry

                                                                                                              The global healthcare industry is complex and diverse; from patient record maintenance, healthcare supply chain, to manufacturing complex medical equipment, the industry functions on many layers. Managing all these layers requires tested out techniques
                                                                                                            • Missing Outlook calendar option in Calendar

                                                                                                              Hi all I don't have an Outlook Calendar option in the Settings > Synchronise settings of Calendar. Any ideas why not?
                                                                                                            • Zoho Meeting Android app update: Breakout rooms, noise cancellation

                                                                                                              Hello everyone! In the latest version(v2.6.1) of the Zoho Meeting app update, we have brought in support for the following features: 1. Join Breakout rooms. 2. Noise cancellation Join Breakout rooms. Breakout Rooms are virtual rooms created within a meeting
                                                                                                            • Whats App Automation

                                                                                                              It would be nice to be able to send out an automated whats app message template on moving stages or creation of a ticket (same as you can do for automated emails). Currently only automated emails can be sent. Also, if whats app could be used more effectively
                                                                                                            • Zoho Projects Android app update: Enhanced Documents module within the projects.

                                                                                                              Hello everyone! In the latest Android version(v3.9.35) of the Zoho Projects app update, we have enhanced the documents module within the projects. Now, you can view all the attachments that you have added across the project in tasks, bugs, comments, etc,
                                                                                                            • Lead Source Disappears

                                                                                                              When adding a new lead and saving the page, the page refreshes itself and the lead source field becomes blank. We set the "Lead source" as a required field to see if it would help, but the problem persists and we always have to re-enter the lead sou
                                                                                                            • Inquiry Regarding Monitoring ZOHO CRM API Credit Usage

                                                                                                              Hello ZOHO Community, I hope this message finds you well. I have a question regarding monitoring the usage and remaining credits of the ZOHO CRM API. I recently discovered that within ZOHO CRM, by navigating to Settings ⇒ Developer Hub ⇒ APIs & SDKs,
                                                                                                            • Payment Gateways - A unified hub to manage all your payment integrations in Zoho Creator

                                                                                                              Hello everyone, We're thrilled to announce that we've completely reimagined the way payment gateways are handled in Creator. The result is a centralized Payment Gateways section that provides a clean, user-friendly interface to configure and manage all
                                                                                                            • Community Digest Julio 2025 - Todas las novedades en Español Zoho Community

                                                                                                              ¡Hola, Español Zoho Community! Ha pasado un tiempo desde el último Digest pero, ¡ya estamos de vuelta con las novedades más relevantes en las aplicaciones de Zoho y su universo! Si no te quieres perder ninguna de las novedades que vamos publicando, te
                                                                                                            • Tip #35- How to use Notifications in Zoho Assist to stay on top of session activities- 'Insider Insights'

                                                                                                              Hello Zoho Assist Community! This week, we’re exploring Zoho Assist’s built-in notification system for improved visibility and accountability. Keeping track of session activity is crucial, especially when you're managing multiple remote devices and technicians.
                                                                                                            • Assistance with Exporting Specific Data from Zoho CRM

                                                                                                              Hi, Could you please guide me on how to export specific information, such as the model number and serial number, from the Accounts module in Zoho CRM? Thank you in advance for your assistance.
                                                                                                            • Coming Soon in Zoho Invoice: Send Invoices Instantly via WhatsApp

                                                                                                              We're working on bringing a new level of convenience to your invoicing experience. Introducing a much-requested feature in Zoho Invoice: You can now share invoices directly to your customers via WhatsApp! With this new option, you can: Share invoices
                                                                                                            • field update from the value of another field

                                                                                                              Hello, I need to do a field update from the value of another field, but i don´t know how can i do it. In the mass update option it is not possible... I need to put the last name value form the leads module to other custom field that i have created. thanks for your help
                                                                                                            • What is a realistic turnaround time for account review for ZeptoMail?

                                                                                                              On signing up it said 2-3 business days. I am on business-day 6 and have had zero contact of any kind. No follow-up questions, no approval or decline. Attempts to "leave a message" or use the "Contact Us" form have just vanished without a trace. It still
                                                                                                            • Playback and Management Enhancements for Zoho Quartz Recordings

                                                                                                              Hello Zoho Team, We hope you're all doing well. We would like to submit a feature request related to Zoho Quartz, the tool used to record and share browser sessions with Zoho Support. 🎯 Current Functionality As of now, Zoho Quartz allows users to record
                                                                                                            • Is there any way to prevent the row cloning feature(on edit page)

                                                                                                              My initial requirement is to prevent some users from adding new rows in the subform. For that, I have implemented the client script, and the script is working fine. But users are able to clone the row and make changes. For that, I was unable to find any
                                                                                                            • Using Another Field Value for Workflow Field Update

                                                                                                              I'm trying to setup a Workflow with a "Field Update" action on the Lead module, but I would like the new value to actually be taken from a DIFFERENT Field's on the Lead record (vs just defining some static value..) Is this possible? Could I simply use
                                                                                                            • How Do I Change Business Location

                                                                                                              Ive just shifted my business to a new country and would like to update my address and Business location in the "Organisation Profile" page but it is locked in the previous country. How do I unlock it / change it? Thanks
                                                                                                            • Verify details pop-up windows

                                                                                                              Hi, Is it possible to turn-off the anoying "Verify details" window that ask for closing date, "Reason for Lost" or other concepts. If I would like the user to enter such data, I will implement a rule .... How can I turn-off such pop-up? it's not necessary
                                                                                                            • Monthly overtime wrong after adding/changing attendance time for past month

                                                                                                              Hi there, as I understand it, the montly overtime overview under attendance is calculated at the end of each month. If someone was not able to enter his attendance in time but entered it in the new month, this time will not be considered in the overview.
                                                                                                            • As a security measure, you need to link your phone number with this account and verify it to proceed further.

                                                                                                              I want to disable this feature as my one staff travels with different phone numbers so it is hard to verify by phone. How do I do that?
                                                                                                            • Asset Tracking

                                                                                                              I am looking to create custom modules to track customer assets. We install serialized and non-serialized equipment into customers vehicles. So we will have vehicles belonging to the customer then equipment that will belong to a vehicle (if installed)
                                                                                                            • Will zoho thrive be integrated with Zoho Books?

                                                                                                              title
                                                                                                            • 【参加無料】8月8日(金) 福岡 ユーザ交流会 参加登録 受付開始!

                                                                                                              ユーザーの皆さま、こんにちは。コミュニティチームの藤澤です。 8月8日(金)に1年ぶりに、福岡でZoho ユーザー交流会を開催します! ユーザー事例セッションでは、CreativeStudio樂合同会社の前田 美知太郎さまが、労働時間を削減したZoho活用のリアルな工夫を語ります。 Zoho社員セッションでは、データ収集から自動処理まで一気に効率化できるZoho Formsの最新活用アイディアをお届けします。 ▷▷詳細はこちら:https://www.zohomeetups.com/Fukuoka2025#/?affl=fuk2508forumpost
                                                                                                            • Unusable due to "server" issues but there's nothing on Zoho or Down Detector saying there's an outage

                                                                                                              I just started the Zoho trial and I cannot do anything because no apps or even the "contact support" will actually load. I tried to create a project but it keeps giving me the error "server is unable to process your request at this time". I tried to load
                                                                                                            • Issue After Updating to Zoho Desk Android SDK v4.5.0 – Authentication Fails (Status Code 204)

                                                                                                              Hi Zoho Support Team, I was previously using the Zoho Desk Android SDK with the following dependency: implementation 'com.zoho.desk:asapsdk:3.0_BETA_17' Everything was working as expected — including user authentication, the tickets section, and the
                                                                                                            • add another department to helpcenter

                                                                                                              After activating multi-brand, how to add another department to help center? For example department A has associated with help center 1. We have another department B and would like user to be able to submit ticket to department B via help center 1, how
                                                                                                            • Task and Milestones - Dependency feature needed

                                                                                                              I'm sure we're not the first to bring this up. We've been using zoho project for a while. Every project manager knows that to manage a successful project you need option to stack tasks and milestones and be able to create dependencies between tasks and milestones. I think you get the idea... Can you let us know if this feature is in the making or not? any chance we'll see this in future releases? If you need customer feedback about this feature or other enhancements, we'll be happy to test new products
                                                                                                            • Next Page