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

                                                                                                            • Look Up Field Type not available for events and tasks?

                                                                                                              Look Up Field Type not available for events and tasks?    
                                                                                                            • I cannot check out to Zoho People.

                                                                                                              When I tried to check out today, there's prompt that inhibits me to check out: To add entry in Attendance, log time for any of your jobs
                                                                                                            • Digest Juin - Un résumé de ce qui s'est passé le mois dernier sur Community

                                                                                                              Bonjour à toutes et à tous, Ce mois-ci encore, tout s’est enchaîné à toute vitesse ! On vous fait un petit récap de ce qui a marqué ces dernières semaines. Zoho RPA est une solution robuste d’automatisation des processus, conçue pour s’intégrer aux systèmes
                                                                                                            • Different Transaction Series for Different Types of Sales

                                                                                                              Is there any way I can create multiple transaction series for different type of Sales? Say B2B-001 and B2C -001 for respective type of Sales.?
                                                                                                            • Unable to charge GST on shipping/packing & Forwarding charges in INDIA

                                                                                                              Currently, tax rates only apply to items. It does not apply tax to any shipping or packing & forwarding charges that may be on the order as well. However, these charges are taxable under GST in India. Please add the ability to apply tax to these charges.
                                                                                                            • Customer Advance Zoho Book API

                                                                                                              All I could find was Customer Payment API, it does not have facility to add customer advances, where those are not linked to any invoice as such. How to do it?
                                                                                                            • Even though the received amount+tax is equal to or lesser than the invoice value, zoho doesnt allow to record

                                                                                                              Even though the received amount+tax is equal to or lesser than the invoice value, Zoho mentioned the error- you've recorded more payment than the actual invoice balance. please check again. screenshot also attached.  You've recorded more payment than
                                                                                                            • Multiple deductions in invoice

                                                                                                              I issue invoices to a customer that include multiple deductions that I would like to track in different expense accounts. But that is not possible in Zoho Books as there is only one Deduction field and even that I don't have control over to assign it
                                                                                                            • #BiginnersTips | How to bulk update closing dates for multiple deals in Bigin

                                                                                                              Hello Biginners! Keeping your CRM data accurate is crucial for any business- big or small. One key aspect is ensuring that closing dates for deals are always up to date. Why? Because if a deal is closed but not updated, your dashboards and reports would
                                                                                                            • 采购里出现付款通知 的错误

                                                                                                              采购里面出现付款通知错误,怎么调整,我找不到路径,好像是ZOHO 自动生成的,请问怎么调整
                                                                                                            • {"code":1002,"message":"Statement of Accounts does not exist."}

                                                                                                              Hello Zoho team, I faced an issue while trying to POST a sales order from sap to zoho books, using the below data packet: {   "customer_id": "4322967000027451968",   "line_items": [     {       "item_id": "2154170000010847685",       "rate": "752.00",
                                                                                                            • Add Custom Fields only in Customer module and not on supplier module!? Is not there a way to do that!?

                                                                                                              I am trying to create custom fields on clients module but it also gets created on suppliers module; which of course does not make sense at all as a lot of custom fields are client or supplier specific but never both. I am missing something? This seems
                                                                                                            • Logging website service fees

                                                                                                              Hello, I do a lot of freelance work on sites like Upwork and Wyzant and others and those companies take a small cut from what I pay or what I earn and I am wondering what is the correct way to log this in my books. For example if I charge $55 per hour
                                                                                                            • How do i clear a liability account without making a payment?

                                                                                                              I have a liability account with a provision for an expected bill from previous years. However the bill never arrived and the provision/liability account with Cr balance has been carried forward for many years now. How do i know clear the provision made
                                                                                                            • 2 Transactions for single Expense

                                                                                                              I have make 2 payments and have 1 Invoice containing both the items. My Bank Feeds show 2 Transactions, How can i associate them with Single Expense? I tried adding them to Advance Payment, but advance payment I can only apply to Bills It seems. Why cant
                                                                                                            • Everything AI in Zoho Recruit – Webinar Recording Available!

                                                                                                              AI is transforming the way recruiters find, engage, and hire top talent. In our latest webinar, we explored how Zoho Recruit’s AI-powered features can help streamline hiring, automate workflows, and improve decision-making. Missed the session? No worries
                                                                                                            • Introducing the FTP task in Deluge

                                                                                                              Hello everyone, We're excited to announce the launch of the FTP task, a powerful addition to Deluge that enables you to effortlessly transfer files between various Zoho apps and your own servers. Unlike the invokeUrl task, which supports various HTTP
                                                                                                            • The Social Wall: June 2025

                                                                                                              Hello everyone, We’re back with June Zoho Social highlights. This month brought some exciting feature updates—especially within the Social Toolkit—to enhance your social media presence. We engaged with several MSME companies through community meet-ups
                                                                                                            • Custom widgets on Zoho one dashboard

                                                                                                              Is it possible to create custom widgets on the Zoho One dashboard? I see there is a widget name My Open Tickets to display open tickets in my view, but I would also like to have a widget to display unassigned tickets. A widget to display unfinished projects
                                                                                                            • Data privacy concerns

                                                                                                              Does Zoho team have access to my data in the database e.g. Balance Sheet, Bank account transactions, Profit & Loss statement etc.
                                                                                                            • Ability to Remove/Change Zoho Creator Admins via Zoho One Interface

                                                                                                              Dear Zoho One Team, Greetings, We would like to request a feature enhancement in Zoho One. Currently, it is not possible to remove or downgrade a user with the Admin role in Zoho Creator from the Zoho One admin interface. Unlike other Zoho apps where
                                                                                                            • Zoho Sheets

                                                                                                              Are they ever going to set up the feature "where I left off" just as you can do in Microsoft Excel online ? For me that is the only feature missing from Zoho sheets other than that I think they are terrific and use them every day. I only occasionally
                                                                                                            • Canvas Detail View Related List Sorting

                                                                                                              Hello, I am having an issue finding a way to sort a related list within a canvas detail view. I have sorted the related list on the page layout associated with the canvas view, but that does not transfer to the canvas view. What am I missing?
                                                                                                            • Mass Update in Zoho CRM

                                                                                                              Hello, I want to update my past update records by using deluge on some conditions. anyone can please tell me how can I do it.
                                                                                                            • Admin asked me for Backend Details when I wanted to verify my ZeptoMail Account

                                                                                                              Please provide the backend details where you will be adding the SMTP/API information of ZeptoMail Who knows what this means?
                                                                                                            • Action requested: Retain your sales journey configuration in Path Finder

                                                                                                              Dear Customers, We hope you're well! As you might know, we're completely overhauling our journey management suite, CommandCenter, and are in the last leg of it. As a means of getting ready to go live, we will be announcing a series of requests and updates
                                                                                                            • search layout in new version

                                                                                                              Hello where is the menu for customizing search fields (module search layout) in the new zoho version (2016) ?? thanks nono
                                                                                                            • Zoho Marketplace Analytcis

                                                                                                              Hi Team, Our Zoho Marketplace Dashboard is not showing any data. What do you think we could do?
                                                                                                            • if i have zoho one can i upgrade some of my staff from crm to crm plus within my organisation?

                                                                                                              if i have zoho one can i upgrade some of my staff from crm to crm plus within my organisation? Or because I have many licenses of ZOHO ONE , IF I upgrade some staff to ZOGO CRUM PLUS. they will not be on the same organisat
                                                                                                            • The problem with Commerce ownership changing

                                                                                                              Hi, I am changing the ownership of the company and trying to delete the previous user-owner. I changed the owner of the company from user Tatiana to user Eugene. Eugene is the owner of the organization. It's OK. I am now trying to remove the user Tatiana.
                                                                                                            • Secondary Emails

                                                                                                              I am having issues deleting a secondary email address from a couple of our users and need help. When in Directory, manage email addresses, I click the trash icon by the email address and confirm I am trying to delete the email. I click continue and I
                                                                                                            • Kaizen #121 : Customize List Views using Client Script

                                                                                                              Hello everyone! Welcome back to another interesting Kaizen post. In this post, we can discuss how to customize List Views using Client Script. This post will answer the questions Ability to remove public views by the super admin in the Zoho CRM and Is
                                                                                                            • Page Layouts for Standard Modules like CRM

                                                                                                              For standard modules like quotes, invoices, purchase orders, etc, it would be a great feature to be able to create custom page layouts with custom fields in Zoho Books similar to how you can in Zoho CRM. For example, and my current use case, I have a
                                                                                                            • Zoho Books | Product updates | June 2025

                                                                                                              Hello Users, We’ve rolled out new features and enhancements in Zoho Books, from the option to record advances for purchase orders to dynamic lookup fields, all designed to help you stay on top of your finances with ease. Introducing Change Comparators
                                                                                                            • Widget Upload to CRM Fails with “Page Not Found” – Even with Correct Index Path

                                                                                                              I'm building a simple widget to export Contact data to CSV in Zoho CRM, triggered via a custom button. The widget uploads cleanly, appears in the widget list, and is successfully assigned to a Contact detail view via a custom button. But when clicked,
                                                                                                            • Account disabled

                                                                                                              I have an issue I need help with. Whilst trialing ZOHO CRM I created the following: Account1 (-------------) using m__ame@m__rg___s__i__.___.__ and 2 personal emails Account2 (-------------) using a personal email and 2 users _al__1@______________._o_.__
                                                                                                            • How can we manage the tags in ticket

                                                                                                              Allowing agents to use Tags indiscriminately can cause havoc. We could not find tag management where 1. The admin can create Tags beforehand for use by Agents 2. Permission can be allocated which roles/profiles can use existing tags or add new tags 3.
                                                                                                            • Feed Notifications filter?

                                                                                                              I'd like to have filter settings for Feed Notifications just like we have for Personal Email. If someone dumps a bunch of files into a project, we get a notification for every file!
                                                                                                            • Custom fields and filters for Timesheet

                                                                                                              HI Zoho Projects team. IT would be great and useful if we can add custom fields to the Timesheet design And is needed more options for filtering the timesheet dashboard, like "Milestones" and task list asociated to the record. Thank you
                                                                                                            • How do I rename the dropdown that contains a form and a report?

                                                                                                              I want to rename this, but I can't find how
                                                                                                            • Next Page