Automatic Mail-Merge Document Creation Using Zoho CRM APIs

Automatic Mail-Merge Document Creation Using Zoho CRM APIs

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

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

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

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

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

Sample Mail Merge Template for Letter of Intent

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

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

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

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

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


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

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

    Access your files securely from anywhere







                            Zoho Developer Community





                                                  Use cases

                                                  Make the most of Zoho Desk with the use cases.

                                                   
                                                    

                                                  eBooks

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

                                                   
                                                    

                                                  Videos

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

                                                   
                                                    

                                                  Webinar

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

                                                   
                                                    
                                                  • Desk Community Learning Series


                                                  • Meetups


                                                  • Ask the Experts


                                                  • Kbase


                                                  • Resources


                                                  • Glossary


                                                  • Desk Marketplace


                                                  • MVP Corner




                                                            • Sticky Posts

                                                            • Kaizen #197: Frequently Asked Questions on GraphQL APIs

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

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

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

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

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


                                                            Manage your brands on social media



                                                                  Zoho TeamInbox Resources



                                                                      Zoho CRM Plus Resources

                                                                        Zoho Books Resources


                                                                          Zoho Subscriptions Resources

                                                                            Zoho Projects Resources


                                                                              Zoho Sprints Resources


                                                                                Qntrl Resources


                                                                                  Zoho Creator Resources



                                                                                      Zoho CRM Resources

                                                                                      • CRM Community Learning Series

                                                                                        CRM Community Learning Series


                                                                                      • Kaizen

                                                                                        Kaizen

                                                                                      • Functions

                                                                                        Functions

                                                                                      • Meetups

                                                                                        Meetups

                                                                                      • Kbase

                                                                                        Kbase

                                                                                      • Resources

                                                                                        Resources

                                                                                      • Digest

                                                                                        Digest

                                                                                      • CRM Marketplace

                                                                                        CRM Marketplace

                                                                                      • MVP Corner

                                                                                        MVP Corner







                                                                                          Design. Discuss. Deliver.

                                                                                          Create visually engaging stories with Zoho Show.

                                                                                          Get Started Now


                                                                                            Zoho Show Resources


                                                                                              Zoho Writer Writer

                                                                                              Get Started. Write Away!

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

                                                                                                Zoho CRM コンテンツ








                                                                                                  Nederlandse Hulpbronnen


                                                                                                      ご検討中の方




                                                                                                            • Recent Topics

                                                                                                            • How to display results from zoho.crm.searchRecords in message window

                                                                                                              Hello, I've created a custom function which is linked to a custom button which pulls a date from our contacts module and searches a date field in our quotes module and returns all records matching the date. My issue is, how to I get this to display the
                                                                                                            • Domain Transfer

                                                                                                              Hello there! I wanted to know if I can transfer my domain from Zoho to other hosting providers or use a different hosting provider instead of zoho's services.
                                                                                                            • Select CRM Custom Module in Zoho Creator

                                                                                                              I have a custom module added in Zoho CRM that I would like to link in Zoho creator.  When I add the Zoho CRM field it does not show the new module.  Is this possible?  Do i need to change something in CRM to make it accesible in Creator?
                                                                                                            • New User - Opening Stock Aging Report

                                                                                                              I am setting up new client and am entering Opening Stock - created items and entered quantity/price details. Now the aging report is showing all the opening stock as new. How do I enter the Purchase Dates of these items so that I get accurate Inventory
                                                                                                            • Bulk Receive Multiple Purchase Orders

                                                                                                              Is there a feature or function that will allow you to bulk receive issued purchase orders? I have about 100 that need to be received from 5 years ago.
                                                                                                            • Manual Invoice

                                                                                                              How to create a Manual invoice, I need to enter Amount directly instead of (qty*Rate). our company is a service sector
                                                                                                            • Effective Inbox Organization: Folders vs Tags in Zoho Mail?

                                                                                                              I'm exploring the best ways to organize a busy inbox, especially when managing multiple clients or project using Zoho Mail. I’d love to know what works best for others: 1. Do you prefer **folders** (possibly with sub-folders) for each client or project?
                                                                                                            • Merging contacts and or accounts

                                                                                                              Hello, In a prior CRM we were able to merge contacts and or accounts.  We have turned on the function to stop multiple contacts with the same email, so we can prevent multiple contacts from happening, however, we now have multiple contacts that have the
                                                                                                            • Capture Reason for absence next to Campaign Member Status. Is there a reasonable workaround?

                                                                                                              I've reviewed the topics I could find to do with this but still couldn't find anything that satisfies our requirements: We would like to track a *reason* (picklist or text, doesn't matter which) why a Campaign Member (Lead or Contact associated with a
                                                                                                            • Zoho Learning Management System - Certificate Upload by Employees

                                                                                                              We are planning to enroll employees in courses which are hosted by coursera or similar sites. I want to share the links of those courses and also want employees to upload their completion certificate once they are done. Is this function possible in
                                                                                                            • Add RTL and Hebrew Support for Candidate Portal (and Other Zoho Recruit Portals)

                                                                                                              Dear Zoho Recruit Team, I hope you're doing well. We would like to request the ability to set the Candidate Portal to be Right-to-Left (RTL) and in Hebrew, similar to the existing functionality for the Career Site. Currently, when we set the Career Site
                                                                                                            • Button or Links order

                                                                                                              Is there a way to re-order the buttons or links that are created?
                                                                                                            • Adding Multiple Products (Package) to a Quote

                                                                                                              I've searched the forums and found several people asking this question, but never found an answer. Is ti possible to add multiple products to a quote at once, like a package deal? This seems like a very basic function of a CRM that does quotes but I can't
                                                                                                            • 'Pin' notes, so that specific ones are always visible at the top of the 'notes' tab.

                                                                                                              It doesn't appear Bigin has the functionality to 'pin' a note to then have it always show at the top of the notes tab section of a record. Often times we have a large number of records, but key information we may want to have easily visible to all at
                                                                                                            • Request for Subform Support in Zoho CRM Webforms

                                                                                                              Hi Team, I hope you're doing well. I would like to bring to your attention that currently, Zoho CRM Webforms do not support Subforms, which limits our ability to send forms that mirror the actual structure used within Zoho CRM. This feature is extremely
                                                                                                            • Formatting Mailing Labels

                                                                                                              I want to use the "Print Mailing Labels" function on the drop down list, but I am not seeing a way to change the formatting on the mailing labels. At the moment, the information that appears on the mailing labels ARE NOT mailing addresses, but random
                                                                                                            • Maxima Address on FSM Customer

                                                                                                              Im trying to add probably 50 customers from one company but couldn't make it since it has limit..how do i add the limit?
                                                                                                            • How to Track Inventory Usage from Zoho FSM to Zoho Inventory?

                                                                                                              Hi everyone, We’re currently working on integrating Zoho FSM with Zoho Inventory, and we’ve encountered a challenge we’re hoping the community can help us understand better. Here’s the context: When we create a Work Order in Zoho FSM that involves parts
                                                                                                            • View subform entries without viewing a record in Zoho CRM | Kiosk Studio Session #8

                                                                                                              In a nutshell Have you ever wanted to take a quick peek at a record's subform? Examples might be invoiced items in an invoice, ordered items in a sales order, or purchased items in a purchase order. Let's say you're viewing your list of invoices in Zoho
                                                                                                            • How to Create a YTD vs Last YTD Comparison Report in Zoho Analytics?

                                                                                                              Hi everyone, I'm trying to build a report that compares Year-to-Date (YTD) metrics from this year to last year. I’m struggling to get accurate results using custom formulas or aggregate functions. Has anyone successfully created a YTD vs LYTD comparison
                                                                                                            • Transforma tu Inventario: Control Inteligente y Funciones Clave en Zoho Inventory (Spanish Webinar)

                                                                                                              ¿Tu empresa necesita mayor trazabilidad y control en almacenes? Conoce cómo gestionar tu inventario con eficiencia y automatización... ¡y descubre las sorpresas que trae Zoho Analytics! Participa en nuestro webinar gratuito en español, este 19 de agosto
                                                                                                            • Dashlane discontinued its free plan: Here's why Zoho Vault's free plan is worth the switch

                                                                                                              Hey everyone, Dashlane password manager has officially announced that its free plan will be discontinued starting September 16, 2025. This change means that current free users will need to either upgrade to a paid subscription or export their data and
                                                                                                            • Mails are not being sent from custom Deluge function

                                                                                                              We are having troubles to implement sending Invoices / Sales_Orders etc. automatically using following deluge script: attachment_template_id = "aaaa"; record_id = "bbbb"; mail_template_id = "cccc"; //NEW aproach fileUrl = "https://www.zohoapis.com/crm/v8/settings/inventory_templates/"
                                                                                                            • Currency transition

                                                                                                              We are using Zoho CRM in Curacao, Dutch Caribbean. Our currency is currently the ANG. Curacao will be transition ing from using the ANG (Antillean Guilder) to using the XCG currency (Caribbean Guilder) on March 31st 2025, see: https://www.mcb-bank.com/caribbean-guilder.
                                                                                                            • Notes and Attachments visibility can now be restricted based on profiles

                                                                                                              Dear All, We hope you're well! We are here with a quick update about Notes and Attachments profile permissions. In the past, a record's Notes and Attachments were visible by default to all users with record access. However, as notes and attachments can
                                                                                                            • Zoho webinar--hard for agencies

                                                                                                              So, this is just a dive into our use case, and why we've been disappointed in Zoho webinar. We are a small marketing agency, and we wanted to add webinars to the services we provide, as many of our clients want to learn to use them as part of their content
                                                                                                            • Celebrating Raksha Bandhan with Zoho Desk: A Bond of Trust, Protection, and Service

                                                                                                              Raksha Bandhan, celebrated across India, symbolizes the sacred bond of protection and affection between siblings. “Raksha” means protection, “Bandhan” means bond or knot: together, it represents a knot of care and security. On this occasion, we'd like
                                                                                                            • Banking > Import statements with a csv file

                                                                                                              Good morning, I am regularly using the "import statement" option to match my transactions. I've been using csv files produced by my bank online and was able to import my transactions. Until now. Thank you for your help for fixing this ! Alex.
                                                                                                            • ZOHO BOOKS - RECEIVING MORE ITEMS THAN ORDERED

                                                                                                              Hello, When trying to enter a vendor's bill that contains items with bigger quantity than ordered in the PO (it happens quite often) - The system would not let us save the bill and show this error: "Quantity recorded cannot be more than quantity ordered." 
                                                                                                            • Has anyone successfully added Microsoft Graph API Oauth2 as a connection?

                                                                                                              I'm having trouble getting Microsoft Graph API created as a connection in zoho crm. Has anyone successfully added Microsoft Graph API Oauth2 as a connection? My issue is not necessarily on the Zoho side, but understanding how to set up the Microsoft side
                                                                                                            • Syncing Timesheets between Projects and Desk

                                                                                                              All users able to see their own timelog entries from all apps in one place, synced immediately. All managers able to view total/all time entries from one place. This is something that has come up for us and multiple clients. Example: we have a client
                                                                                                            • Spell Check default language

                                                                                                              Hello All, Is it possible to set the Spell Check default language? I can't find it in the settings. Thanks a lot! Levente
                                                                                                            • Zoho Backstage 3.0 - Boostez vos événements avec des outils malins

                                                                                                              Zoho Backstage vous accompagne dans l’organisation d’événements réussis, avec des outils qui simplifient la planification, optimisent l’exécution et renforcent la connexion avec votre public. La version 2.0 a apporté une nouvelle interface, plus de flexibilité
                                                                                                            • Portal user activity reporting

                                                                                                              Aside from the metrics section in the admin dashboard, is there a way to view/create reports for portal user activity? Im looking for a more granular option to see exactly what users are utilizing the portal. Thanks!
                                                                                                            • Automation #11 - Auto Update Custom Fields with Values from Emails

                                                                                                              This is a monthly series designed to help you get the best out of Desk. We take our cue from what's being discussed or asked about the most in our community. Then we find the right use cases that specifically highlight solutions, ideas and tips to optimize
                                                                                                            • Admins to set Agents Picture

                                                                                                              Admins should not have to rely on agents to set a nice profile picture for them. Admins get the headshot pictures from HR and should be able to upload and set their picture, not rely on them to: 1) upload a picture at all 2) upload a good picture 3) upload
                                                                                                            • Time Tracking Reporting and Billing

                                                                                                              I wish for the time tracking module to be enhanced further. Currently it is independent of Support Plans and Contracts. Support Plans and Contracts are also mostly separate. We need a better dashboard of this with the ability to natively mark billed or
                                                                                                            • Enhanced Email Signature Folding

                                                                                                              We have departmental signatures setup which are great, however, when viewing ticket details, it gets very overwhelming when scrolling though threads and conversations where you scroll past ten different signatures of your own team, then ten signatures
                                                                                                            • How to add formatting in zoho.cliq.postToUser(...) message?

                                                                                                              In a CRM Deluge function, I'm trying to use the message formatting guidelines given here: https://www.zoho.com/deluge/help/cliq/posting-to-zoho-cliq.html#message-formats My message is: message: #Title text. The result in Cliq is: #Title text. (no large
                                                                                                            • How to add line breaks in zoho.cliq.postToUser(...) message?

                                                                                                              In a CRM function using Deluge I'm sending this message and attempting to add some line breaks but they are ignored. Is there another way to add these breaks? My message: message: New urgent task\nDescription \nThis is a fake description.\n A new line?
                                                                                                            • Next Page