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

                                                                                                            • Send again email with link for signup

                                                                                                              Hello, I have a lot of problem to send contract my email, also missing the features "share link". How can I send again email to client and me wit link for signup a contract? Everytime it's a disaster!
                                                                                                            • How do I synchronize a quote to an opportunity?

                                                                                                              Hi everyone, We don't quote anything via Zoho but we use it to track services/products so that I can see what was actually sold, vs an opportunity with just shows an amount.  We use the quotes for other purposes, mostly to request a quote from Salesforce but we don't invoice or do sales orders or anything. (Basically a user makes a quick quote in Zoho, adds items and pricing, and then exports to PDF which gets emailed to our Quote Desk who then enters the request into Salesforce). Just wondering
                                                                                                            • Zoho Sprints Android app update: Tags and Epic search

                                                                                                              Hello everyone! We are excited to introduce tags and an option to search items within Epic module on the latest Android version(v2.0.2) of the Zoho Sprints mobile app. Let's take a look at these features: Tags You can now create, edit, and delete tags,
                                                                                                            • Zoho CRM Webhooks - Dynamic URL

                                                                                                              Hi Zoho, We've noted a gap in the webhooks function that if improved would increase use cases significantly. The "URL to Notify" field in "Create a Webhook" only supports static information. We have a number of use cases where we could use webhooks more
                                                                                                            • Work Order Creation Issue

                                                                                                              Dear Team, I would like to inquire about the daily limit for Work Order creation in Zoho FSM. Yesterday (02/05/2025) at around 6:30 PM GST, I attempted to create a Work Order, but I have been unable to do so since then. Please find the attached image
                                                                                                            • Tracking on Zoho Booking

                                                                                                              Hi We want to use Zoho Booking for our appointment management. We're using Calendly as of now that lets us track sources of the appointments made including UTM parameters. Is there a way for us to do same with Zoho Bookings?
                                                                                                            • Pre-created Popular Zoho Flows returns with 404 Error

                                                                                                              Your popular Zoho Flows are returning with a 404 page error. This applies to all work flows in your Gallery Space. See video here for further clarification. When will this be fixed? https://drive.google.com/drive/folders/1kDl4ni5EQeLHWeaoIDdtRqoUbW8FNLfO?usp=sharing
                                                                                                            • CRM Feature Request

                                                                                                              When enabling Translation in Zoho CRM I would like to see the ability to remove the language "English (US)". I have encountered a user experience issue with a client recently. The client uses English (UK) but they are based in Spain, so they have activated
                                                                                                            • Import your Google Docs Spreadsheets into Zoho Sheet

                                                                                                              You can now import your Google spreadsheet into Zoho Sheet. This will be useful if you want to switch to Zoho Sheet or if you want to simply try out Zoho Sheet.  If you don't have an account with Zoho, you can still try this by signing in with your Google account. Here is a video on how to do this.  Note: Existing charts won't appear in spreadsheets you import from Google Docs as the Export functionality of Google Docs doesn't give out the charts. Check out the announcement in our blog: https://blogs.zoho.com/general/import-google-docs-into-zoho-productivity-suite
                                                                                                            • Support Mixed Visibility Settings in Knowledge Base Categories

                                                                                                              Hello Zoho Desk Team, We hope you're all doing well. We’d like to submit a feature request regarding visibility settings in the Knowledge Base module. 🎯 Current Limitation As of today, when a category is set to a specific visibility level (e.g., Public),
                                                                                                            • Will a campaign send duplicates is same email is on two separate lists

                                                                                                              Hi I have two lists to which I want to send campaign. One list is ALL leads and other is list of opportunities and current students. There is overlap between the two lists My question is if I send one campaign to all, will zoho automatically know only to send the email once to the duplicate email?
                                                                                                            • Time Based Report / Dashboard

                                                                                                              We measure our support agent's KPI based on their response time and resolution time from the time the ticket is assigned to them The time based dashboard should provide this information however there is a problem with us referring to this dashboard We
                                                                                                            • Zoho Learn API Access?

                                                                                                              We love using Zoho Learn to manage our internal trainings and knowledge base. What we'd really love is to be able to query Learn via API so that in Zoho Projects, Zoho Creator, or Zoho Desk, we can recommend relevant Learn articles and manuals to team
                                                                                                            • creating buttons in zoho site

                                                                                                              the connection between zoho site and zoho learn will be awesome and amazing feature so the user instead of registering himself twice just one time register on zoho site will be enough and creating accout on zoho learn instead of registering on zoho learn
                                                                                                            • Two Problems with the Description Field

                                                                                                              Our ticket workflow is often like this. Client calls or emails (to a personal email address) reporting a problem. We create a ticket and enter a description. Problems: 1. By my way of thinking when we enter a description, that is an internal comment (unless we mark it public). Yet it seems there is no way to mark it internal, and Desk just starts inserting it into communications. 2. Additionally, in the conversation view it makes it appear it was emailed by the customer and inserts their name on
                                                                                                            • Lookup Field limitations

                                                                                                              Good day all, Is anyone else frustrated with the lookup field limitation? I have an enterprise license, but I only get 10 lookups. Additionally, the custom module has been available for a while and is still in diapers. If you want good reporting, you
                                                                                                            • Automation#36: Auto-create time-entry after performing the Blueprint transition

                                                                                                              Hello Everyone, This week’s edition focuses on configuring a custom function within Zoho Desk to streamline time tracking within the Blueprint. In this case, we create a custom field, and request the agent to enter the spending time within the single
                                                                                                            • Dynamically Sync zoho.adminuserid with Current App Admin

                                                                                                              Hello Zoho Team, We hope you're doing well. We’d like to request an important enhancement to the Deluge sendmail task functionality. As per the current behavior, in most Zoho services (excluding Zoho Cliq, Zoho Connect, Zoho Mail, and Zoho Sheet), the
                                                                                                            • "Improper Statement" Error on Deluge Loops (while/for) when Processing a Date Range

                                                                                                              Hello, Zoho Community, I'm facing a very specific issue with a Deluge script and would appreciate any insights from the community. The Goal: I have a form (ausencia_visitadoras) where a user inputs a start date and an end date for a period of absence.
                                                                                                            • Zoho Meeting iOS app update: Hearing aid, bluetooth car audio and AirPlay audio support.

                                                                                                              Hello everyone! We are excited to announce the below new features in the latest iOS update(v1.7.4) of the Zoho Meeting app: 1. Hearing aid support: Hearing aid support has been integrated into the application. 2. Bluetooth car Audio, AirPlay audio support:
                                                                                                            • Automating Daily Lottery Result Publishing with Zoho Creator or Flow – Any Best Practices?

                                                                                                              Hello Zoho Community, I run a results-based informational website in Brazil called CaminhoDaSorte.com, where we publish daily Jogo do Bicho results. Right now, we're doing this process manually every day — but we’re looking to automate the backend using
                                                                                                            • issues with manually shipping sales orders - advise needed please

                                                                                                              we are new to zoho inventory. we are going to roll the program out to our company within a couple of weeks and during the implementation process we have come into a roadblock with manually packaging and shipping sales orders. its important to note important
                                                                                                            • I do not see the “Lead Forms” option under Integrations

                                                                                                              Hi, I’m using Zoho Social on a Premium plan. I’ve connected LinkedIn Company Page and have a valid LinkedIn Ad Account with Lead Gen Forms. However, I do not see the “Lead Forms” option under Integrations, so I can’t enable LinkedIn Lead Generation. Please
                                                                                                            • STOCK function showing #N/A! even thought the Stock symbol is valid

                                                                                                              Zoho Team, I use STOCK function on Zoho Sheet to fetch the recent Last Closing Price. Some stock symbols are valid but when the STOCK function is applied, it shows #N/A! Attaching an image for reference.
                                                                                                            • What’s the Correct Integration Flow Between Zoho Inventory, ShipStation, and Multi-Channel Sales Platforms?

                                                                                                              Hi Zoho Community, I’m currently implementing Zoho One to manage all of my business processes, and I’d appreciate some guidance on the correct integration flow for the tools I’m using. Here’s my current setup: Zoho Inventory is my central system for managing
                                                                                                            • Beyond Email: #4 Note taking done right with Notes

                                                                                                              With her favorite links now saved in Bookmarks, Sarah is feeling even more at home in Zoho Mail. As her day fills up with meetings and project discussions, she often finds herself scribbling quick ideas and reminders—only to lose track of them later.
                                                                                                            • When will Sales Order and Invoice Synchronisation with Zoho CRM be Available?

                                                                                                              When will Sales Orders and Invoices, created in Zoho Books or Inventory be made available in Zoho CRM? John Legg Owner: The Debug Store
                                                                                                            • Generate Unique Customer ID for Each for All Contacts

                                                                                                              Generate Unique Customer ID for Each for All Contacts
                                                                                                            • Bookings to Books automation using Flow

                                                                                                              I'm using Zoho Flow to automate a process between Bookings and Books. When someone uses Bookings to schedule time with me I use Flow to automatically add the person as a customer in books, then create a Quote in Books for the type of consultation they
                                                                                                            • Different Canvas for Different account type

                                                                                                              I would like to have a separate canvas for Customers and Resellers that auto-applies when I enter an ACCOUNT. Is this do-able?
                                                                                                            • IMAP sync issues in Zoho CRM

                                                                                                              We are using the Zoho CRM for a while, and we sync (via IMAP) our Google Apps email system. The sync works properly when looking at emails per account, contact or deal, etc. However, it does not function well in the "Messages" and "SalesSigns" features.
                                                                                                            • Reporting tags for custom modules

                                                                                                              Hi, it could be very useful. At field level and at sub table level. Thanks, Eduardo
                                                                                                            • Can't pass Dates and use date filtered Charts in Pages?

                                                                                                              I don't mess with pages very much, but I'm trying to build a dashboard. I have a search element and several charts that need to be filtered. I also have a stateless form for a start/end date picker I am trying to use to filter data for the charts. Here
                                                                                                            • ZOHO FSM Trial - Assets

                                                                                                              Hi I am currently using Zoho CRM and looking at adding FSM. I am trialing FSM at the moment, to potentially move away from my current programme (SimPro) but have a query on the Asset system within FSM It looks like you can only create 1 asset "type";
                                                                                                            • Customize User Invites with Invitation Templates

                                                                                                              Invitation Templates help streamline the invitation process by allowing users to create customized email formats instead of sending a one-size-fits-all email. Different invitation templates can be created for portal users and client users to align with
                                                                                                            • Sending Email with Attachment (PDF, Excel file)

                                                                                                              Hi, I'm new to Zoho CRM and I'm setting up a flow to send an Email with Attachment when user reaching a certain stage of a Deal. In detail, I've created a Blueprint which requires user to attach a PDF file when reaching a certain point of the stage and
                                                                                                            • A letter to the unsung heroes of the internet

                                                                                                              Dear social media marketers, this one’s for you! From the outside, it may look like you're just scrolling through feeds or switching between tabs. But we know better. Team Zoho Social sees the real story. We understand the challenges you face—and we’ve
                                                                                                            • Based on the Assign To time task want to trigger also reminder for the task still move form fresh lead

                                                                                                              If the leads is assigned To 1 am to 10.55 am task want to create 11am Then reminder want to go the person at 4pm If lead status not moved from fresh lead. From next on wards Reminder want to go 11 Am and 4pm Every day still the person moved to fresh lead
                                                                                                            • Emails Not Sending

                                                                                                              This has happened before. I contacted Zoho and it seemed to work, but now my emails are not sending or taking a long time to send and half the time attachments don't attach. It just keeps saying Sending... and I have to keep clicking it to make it send.
                                                                                                            • [Free Webinar] Learning Table Series - AI-Enhanced Logistics Management in Zoho Creator

                                                                                                              Hello Everyone! We’re excited to invite you to another edition of Learning Table Series, where we showcase how Zoho Creator empowers industries with innovative and automated solutions. About Learning Table Series Learning Table Series is a free, 45-60
                                                                                                            • Next Page