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

                                                                                                            • two columns layout

                                                                                                              it's actually frustrating to not have this feature, I actually had to convince my employer to subscribe to zoho forms and integrate it with zoho crm, but because of this feature not beeing provided, our forms looks unnecessarly long and hideous. 
                                                                                                            • Sync Zoho Desk Help Center Category Icons to SalesIQ Articles

                                                                                                              Dear Zoho SalesIQ Team, Greetings, We are using the integration between Zoho SalesIQ and Zoho Desk to sync articles from our Zoho Desk Knowledge Base into SalesIQ. While this integration works well for syncing article content, we’ve noticed a visual inconsistency:
                                                                                                            • Company Name not pre-populating when using Quick Create: Contact

                                                                                                              Hi Devs, This has bugged me for a long time, and it's a simple UX design change to solve it. Problem: Users creating Contacts not linked to Companies/Accounts Cause: When a user creates an Opportunity where after browsing the Contacts they realise they
                                                                                                            • Spell Checker in Zoho desk

                                                                                                              Is there a way to set always check spelling before sending? Outlook does this and it is a handy tool to avoid typos
                                                                                                            • Enable Sync of SalesIQ Article Interactions to Zoho Analytics for Unified Knowledge Base Reporting

                                                                                                              Dear Zoho SalesIQ and Zoho Analytics Teams, Greetings, We’d like to formally request an enhancement to enable SalesIQ article interaction data to be synced with Zoho Analytics, so that we can obtain a unified view of our knowledge base performance metrics
                                                                                                            • How to enter membership share, sold or reimburse

                                                                                                              Hello, First, I am just begining taking care of the accounting of my organisation, and new also to Books. In Books, our accounting plan has an account #3900 - Share capital, that cumulates the share our member pay. How do I write a sale or a reimbursement
                                                                                                            • Ability for me to take the issued PDF certification on successful completion of a course then push to zoho sign in order that it is digitally certified

                                                                                                              How can I take the issued PDF certification on successful completion of a Zoho Learn course then trigger a workflow to push to Zoho Sign in order that it is digitally certified, hosted on the blockchain and then push to Zoho Workdrive to be hosted off
                                                                                                            • Candidates rejection process

                                                                                                              Is there a way to get ZOHORecruit to automatically send out an email to candidates that are rejected?
                                                                                                            • Multi file upload

                                                                                                              Hi, I just wonder if one could upload multiple files in one shot, say between one and three files, without adding multiple File Upload fields? Thanks, Alalbany
                                                                                                            • Passing the image/file uploaded in form to openai api

                                                                                                              I'm trying to use the OpenAI's new vision feature where we can send image through Api. What I want is the user to upload an image in the form and send this image to OpenAI. But I can't access this image properly in deluge script. There are also some constraints
                                                                                                            • Calendar Year View?

                                                                                                              Is there a way I can view the calendar in year view? Maybe create a page with a view like this?
                                                                                                            • ABN Amro

                                                                                                              Hi, We are trying to add Abn AMRO as a bank in Zoho Books. However we get the following error: Type of Error: User Action Required Description: The request cannot be completed because the site is no longer supported for data updates. Possible workaround: Please deactivate or remove the account. Suggested Action: The site will no longer be supported by Zoho Books and should be removed. Does that mean it's no longer supported? Thanks!
                                                                                                            • Add bank transfers via a webhook or API

                                                                                                              Hello ZOHO Books Community, is there anyway to add single transactions to bank accounts via an API or webhook? I found in docs to upload a bank statement. But i want to add a transaction from an external (unsupported bank) in the moment there is a transaction
                                                                                                            • Books does not allow 19% tax rate for invoice - Please help!

                                                                                                              Hi there, I need to do an import of invoices into Zoho Books. The process worked smoothly before we migrated to the Books Germany Edition in December 2024. It does import 13 out of 14 invoices from my csv-file. For the one it does not import I get the
                                                                                                            • When will Zoho Books offer native NFS-e issuing, now with Brazil's National Standard?

                                                                                                              Hello Zoho Team and Community, I'd like to follow up on my previous suggestion regarding the critical need for Zoho Books to natively issue Brazilian Service Invoices (NFS-e). My original idea was that this could be achieved by extending the same integration
                                                                                                            • API 500 Error

                                                                                                              Hello amazing ZOHO Projects Community, I get this message. How can we solve this? { "error": { "status_code": "500", "method": "GET", "instance": "/api/v3/portal/2010147XXXX/projects/2679160000003XXXX/timesheet", "title": "INTERNAL_SERVER_ERROR", "error_type":
                                                                                                            • Admin Access to Subscriber Information for System/Default Bots in Zoho Cliq

                                                                                                              Dear Zoho Cliq Team, Greetings, We would like to request an enhancement to Zoho Cliq's bot management capabilities. Specifically, we are asking for the ability for organization administrators to view the list of subscribers for system/default bots, such
                                                                                                            • zoho webmail keeps opening an empty tab when on log in/vist webmail

                                                                                                              as the the title says, whenever i log in or visit the page in a new tab, zoho webmail with open a new tab, but it errors out (see attachment). how do you stop it from doing this?
                                                                                                            • FSM work order creation on books quote approval

                                                                                                              I have followed https://help.zoho.com/portal/en/kb/fsm/custom-integrations/zoho-books/articles/perform-actions-in-zoho-fsm-on-estimate-approval-in-zoho-books#Step_1_Create_a_connection_for_Zoho_FSM_in_Zoho_Books in order to create a work order in FSM
                                                                                                            • How to View Part Inventory and Warehouse Location When Creating a Work Order in Zoho FSM

                                                                                                              Hi everyone, We’re currently setting up Zoho FSM and would like to improve how our team selects parts when creating a Work Order. Right now, when we add a part or item to a Work Order, we can select it from our Zoho Inventory list but we don’t see any
                                                                                                            • Tip of the week #46 - Stay more organized by moving threads between inboxes

                                                                                                              Have you ever come across a thread in your inbox that should have been handled by a different team or inbox? Or maybe you've wrapped up your part of the conversation, but another team needs to step in to finish the task or assist further? Keeping such
                                                                                                            • Desktop app doesn't support notecards created on Android

                                                                                                              Hi, Does anybody have same problem? Some of last notecards created on Android app (v. 6.6) doesn't show in desktop app (v. 3.5.5). I see these note cards but whith they appear with exclamation mark in yellow triangle (see screenshot) and when I try to
                                                                                                            • Text summarization and field detection with Zia, Zoho's AI assistant

                                                                                                              Have lengthy documents that take forever to read and sign? Tired of placing fields into hundreds of pages? Here's a single solution to solve both challenges: Zia, Zoho's AI assistant. With Zia's integration with OpenAI, you can summarize long documents
                                                                                                            • Sending Links to Functions in CRM

                                                                                                              Maybe I'm crazy, but currently there's no way to send someone a link to a custom function. The only link you can get is to the myfunctions page, which is very frustrating. This should work like workflow rules where when you click on one, it should have
                                                                                                            • zohoからの自動メールについて

                                                                                                              zohoからの自動メールにおいてちょっと困ったことが起こっており、サポートにも相談中なのですが ほかの方にも同現象が発生していないか相談したい。 ▼事象 zohoからの自動メールにおいて時折「このメールが送信者からのものであると確認できないため、このメールに安全に返信できない可能性があります」とメーラーから警告が出る。 ▼状況 発信元:設定した独自ドメイン SPF/DKIM設定:済 利用メーラー:outlook 発生頻度:稀(連続するときもあるが、パタッとでなくなる時もある) サポートへの連絡:ただいま継続相談中
                                                                                                            • Using Deluge scripting to create/update data in TabularSections

                                                                                                              I am having following Form structure with some other usual fields, and a tabular section which allows putting question, self rating and lead rating. (pic below) I am trying to create a record of this form via Deluge, but can't figure out way to populate
                                                                                                            • Zoho Recruit: How to link lookup fields using record ID instead of name during import?

                                                                                                              Hi, I'm having an issue with lookup fields in Zoho Recruit during data import. When I import records into a module that includes a lookup field (e.g., to an Interview record), Zoho Recruit matches the lookup by the display name (string) instead of the
                                                                                                            • Add a "Success" Route to the "Forward to Operator" Card in Zobot

                                                                                                              Hello Zoho SalesIQ Team, We hope you're doing well. We would like to request an enhancement to the "Forward to Operator" card in Zobot. Current Limitation: At present, the "Forward to Operator" card provides the following routes: Operator Not Available
                                                                                                            • Power of Automation :: Auto-update Project status based on Tasklist completion

                                                                                                              Hello Everyone, A Custom function is a user-written set of code to achieve a specific requirement. Set the required conditions needed as when to trigger using the Workflow rules (be it Tasks / Project) and associate the custom function to it. Requirement:
                                                                                                            • Multi Module Lookup Fields

                                                                                                              🎯 Use Case: In many custom implementations, especially those involving financial tracking, service operations, or project-based work, a single record (e.g. an invoice or bill) often relates to one of several different modules — but only one at a time.
                                                                                                            • How to Download a File from Zoho WorkDrive Using a Public Link

                                                                                                              How to Download a File from Zoho WorkDrive Using a Public Link If you're working with Zoho WorkDrive and want to download a file using a public link, here's a simple method to do so using API or a basic script. This approach helps developers or teams
                                                                                                            • Facturation électronique 2026 - obligation dès le 1er septembre 2026

                                                                                                              Bonjour, Je me permets de réagir à divers posts publiés ici et là concernant le projet de E-Invoicing, dans le cadre de la facturation électronique prévue très prochainement. Dans le cadre du passage à la facturation électronique pour les entreprises,
                                                                                                            • Introducing AI Modeler—a no-code approach to adding AI to your business applications

                                                                                                              Forward-thinking businesses today are embracing AI to make life easier for themselves, their employees, and their customers. But if you haven't started yet, you might be concerned that your business will be left behind. Or maybe you're worried because
                                                                                                            • Tip #20 - Three things you probably didn't know you can do with picklists

                                                                                                              Hello Zoho Sheet users! We’re back with another quick tip to help you make your spreadsheets smarter. Picklists are a great tool to maintain consistency in your spreadsheet. Manually entering data is time-consuming and often leaves typos and irregular
                                                                                                            • Zoho People how do i view the history of leave taken

                                                                                                              Hi All What is the report that i am unable to view the history of the leave taken for an individual and team?
                                                                                                            • UK Registration for VAT with existing stock/inventory

                                                                                                              We have an existing inventory of stock and are investigating how to handle the conversion from a UK VAT unregistered company to a UK VAT registered company. Enabling VAT registered status looks extremely easy, but we cannot find any way within Books to
                                                                                                            • Trigger action after workflow

                                                                                                              I would like to trigger a deluge function after the approval workflow is complete. Is this possible? The objective is to take the approved document and move it over to Zoho Contracts to send out to our customer for review and signature. The reason we
                                                                                                            • Is it possible to create a meeting in Zoho Crm which automatically creates a Google Meet link?

                                                                                                              We are using Google's own "Zoho CRM for Google" integration and also Zoho's "Google Apps Sync" tools, but none of them provide us with the ability to create a meeting in Zoho CRM that then adds a Google Meet link into the meeting. Is this something that
                                                                                                            • Unable To Enable Google Calendar Sync

                                                                                                              Hi Folks, I am unable to enable google calendar sync. I get Internal Error, Problem Occurred Internally. Screenshot attached. How do I solve this?
                                                                                                            • Export to Zoho CRM Not Triggering Workflow Rules

                                                                                                              Hello, I have set up an automated export from DataPrep to Leads in CRM but none of my Workflow Rules are triggering once the leads are created. The Timeline history is completely empty in every lead. How can I fix this issue? Do I need to set up a Schedule
                                                                                                            • Next Page