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

                                                                                                            • A Question about Email Handling (Sending and Receiving)

                                                                                                              Hello! I was looking into setting up Email Aliases for my domain that I purchased a while ago through Zoho Mail. I set up a singular alias already and have it linked with Gmail, and it seems to be working out well. However, I set up another alias today,
                                                                                                            • Kaizen #201 - Answering Your Questions | Webhooks, Functions, and Schedules

                                                                                                              Hello everyone! Welcome back to another post in the Kaizen series! We are incredibly grateful for all the feedback we received, and as promised, we will answer all the queries in this Kaizen series. Last week, in our 200th post, we addressed one of the
                                                                                                            • Zoho Projects Strict Dates for Tasks

                                                                                                              Hi Zoho Projects team, I would love to see a feature to allow Strict Dates for Tasks. Sometimes in projects you have dates which must not move, even if predecessor Task dates change. For example, perhaps you need to book access to a facility to perform
                                                                                                            • No Mark as filed buton in GSTR -3b

                                                                                                              We are filing our GST in GST portal -and want to mark GST in Zoho books as filed. It is possible to mark GSTR 1 as filed through Mark as filed button. But there is no such button in GSTR-3B.  How to mark corrosponding GSTR-3B as filed?
                                                                                                            • ranking by drag the choices instead of rank by number

                                                                                                              is the option of draging the choice is available instead of selecting the ranking number for each choice?
                                                                                                            • TASKS - Dashboard to show ALL Tasks from ALL apps.

                                                                                                              The Unified Tasks View is useless without the other main zoho apps (Desk, Books & even FSM now) We need to see all our tasks under on pane of glass. The Zoho developers are out of touch with real business workflows. So how it was designed they want us
                                                                                                            • Function #13: Transaction level profitability

                                                                                                              In Zoho Books, the Profit & Loss report provides valuable insights into the overall profitability of your business, indicating whether you have made a profit or incurred a loss. However, there may be occasions when you wish to assess whether a specific
                                                                                                            • Zoho CRM with Sap Business One

                                                                                                              I need information about integration CRM with Sap BO, thank.
                                                                                                            • Allow bill to nest multiple projects

                                                                                                              A bill (purchase) is more often than not used across multiple projects and this functionality is missing and very urgently needed for accurate reporting of purchases across projects
                                                                                                            • Amazon invoice in Zoho Books

                                                                                                              I have just made my first few sales on Amazon India. Amazon Seller account generates invoices for the sales made on Amazon. These invoices are sent to customers also. Now when I was only making offline sales, I used to create Invoices in Zoho Book. Now
                                                                                                            • How can I change iOS display setting at night?

                                                                                                              It seems like at night the two light daytime settings themes (white with blue on top or just white) are not available and I am forced to choose among a few other colours that I really don’t want, I.e., black, blue or orange. Is there a way for me to always
                                                                                                            • Celebrate WWW day with Zoho Desk

                                                                                                              Let's recall the times when we learned 'WWW' stands for World Wide Web. Whether you like to call it wuh-wuh-wuh or double-u double-u double-u, or World Wide Web, we all owe a lot to this groundbreaking invention that reshaped how we connect, communicate,
                                                                                                            • The power of camaraderie

                                                                                                              In the days before the internet boom, conversations happened face-to-face or over the phone. Phone calls were precious; every minute counted, and every word mattered. We looked forward to those moments of real connection. Even today, nothing quite matches
                                                                                                            • Message Content is missing/invalid fault

                                                                                                              We cannot create a complete template over zoho. Some features - like button adding - is missing. The templates are created on Zoho and edited on Meta to solve the problem. But still then, some features cannot be used and the message returns this failure
                                                                                                            • Können bereits gesendete Kampagnen im Nachhinein einer Mailing-Liste zugeordnet werden, ohne dass die Kampagne erneut versendet wird?

                                                                                                              Wir haben unsere älteren Kampagnen in Campaigns über Kontaktkategorien versendet. Dann haben wir umgestellt auf Mailing-Listen, damit alte Kampagnen auch in einem Archiv aufgerufen werden können. Jetzt ist die Frage, ob die Kampagnen, die über die Kategorieauswahl
                                                                                                            • Newsletter Templates Are Not Mobile Responsive

                                                                                                              Hi, I've already submitted this request to ZOHO once this morning, but for some reason your system logged me out, wouldn't accept my username/password login, and isn't showing any evidence that I've submitted this issue. So here we go again... I am under the impression that your newsletter templates are supposed to be mobile optimised: https://www.zoho.com/campaigns/blog/responsive-email-marketing.html This is clearly not the case, as the last 2 newsletters I've created in Campaigns look perfect
                                                                                                            • Digest Juillet - Un résumé de ce qui s'est passé le mois dernier sur Community

                                                                                                              Bonjour à toutes et à tous, Zoom sur les nouveautés de juillet dernier au sein de Zoho Community France. Zoho Commerce vous propose une expérience améliorée grâce à sa nouvelle interface ergonomique et à ses fonctionnalités avancées, conçues pour faciliter
                                                                                                            • 100 Rows in a Subform is too limited

                                                                                                              We have a custom Module in CRM called Price Sheets, when we get a PO from a client we add the items from the PO to it and then check with our vendors for pricing and add our margin etc And after it is complete we have setup custom scripts to create a
                                                                                                            • Uninstall unattended agent

                                                                                                              Hello, I'm testing many use case before we purchase assist for our remote support. While we are testing what is the proper way to uninstall agent?  I did uninstall from systray, from windows control panel but still ZohoURservice is running. How can I uninstall client side?
                                                                                                            • Zoho Commerce Down?

                                                                                                              Is anyone else's storefront down at the moment? Ours has been down for at lease an hour.
                                                                                                            • Zoho Projects iOS app update: Dashboard widget on the home screen

                                                                                                              Hello everyone! We are excited to introduce the 'Dashboard' widget in the latest version(v3.10.8) of the Zoho Projects iOS app. Dashboard widgets allow you to view the project progress visually without having to open the app. The widget enables you to
                                                                                                            • Idea: Workflow Rule Trigger Only When Subform Row Is Updated (Thanks to New Inline Row Feature)

                                                                                                              Hi Zoho team and community, With the recent update to Zoho CRM, we can now add or delete rows inside subforms without entering edit mode, using the inline Add row button. This is a fantastic improvement for user experience — seamless, fast, and efficient.
                                                                                                            • Auto add new section based on document choices

                                                                                                              Hi team, I'm wondering if the below is a possilibity within Zoho sign. We have an application process to become a customer of ours, we currently use Zoho Sign to manage this application and this works quite well. However, if the customer indicates 'YES'
                                                                                                            • Change rate after xxxx kilometers

                                                                                                              Is there a way to change the miileage rate after a certain mileage. After 5000 kilometers, we want the rate to automaticly change. Thank !
                                                                                                            • Subform Entry Limit from a Subform Field (A different Subform on the same Form)

                                                                                                              Hi, I would like to be able to use a Subform 1 Field as the Dynamic Entry Limit for Subform 2. Even better would be able to use some code with the values, so for example using the Subform 1 Qty Field as the Max Entry limit for Subform 2, BUT only the
                                                                                                            • Slow Zobot response time

                                                                                                              Hi, We launched the Zobot on our site to sit along with the regular Live Chat but had to take the Zobot down as the response time was very slow. The bot was slow to begin then once the chat had been initiated the response was very slow. The bot typing
                                                                                                            • how to show data of 3 table in pivot

                                                                                                              Based on engineer name i want to get the data from 3 different tables like Service , amc, installation , but Every table contain Engineer name As Common , based that from the service table i want to take service amount , and count of service based on
                                                                                                            • Custom Status for Purchase Orders

                                                                                                              Currently Zoho books has functionality to create custom statuses for Sales Orders. Can this be extended to include custom status for purchase orders as well? It was a great decision to add this functionality to sales orders. Our use case is for tracking
                                                                                                            • Ask the Experts 22: Scale up your customer support with integrations & extensibility

                                                                                                              Hello everyone! The foundation is set. Build the beams. Raise the pillars. Set the walls. The Zoho Desk architecture stands tall. Let's discuss integration within Zoho Desk, extensions from the Marketplace, creating connections between Zoho Desk and other
                                                                                                            • Is there no way to duplicate an entire workflow or even custom function across multiple departments?

                                                                                                              Is there no way to duplicate an entire workflow or even a custom function from one department to other departments, like it is done for field duplication from one department layout to other department layouts?
                                                                                                            • Automated reply on any new ticket raised by customer

                                                                                                              Hi ZohoDesk team, Can we set up an automation so that whenever a new ticket is created against our support email; ZohoDesk immediately sends our standard acknowledgement, including the expected TAT for resolution? If that’s possible, could you share the
                                                                                                            • Zoho equipment rental - just like Booqable

                                                                                                              Hi Zoho Team, is it possible to create a module or a system like booqable? our business starts renting our IT equipment assets that have been recently used for Events and Projects, we are having ZOHO books so its easy to integrate if you create one. Booqable
                                                                                                            • Profit Margin Scheme

                                                                                                              I'm a tourism company operating in the aviation and outbound tourism sectors. Typically, taxes are 0% as our operations are outside the country. However, the state has now imposed a tax on the profit margin. This means if the selling price of an airline
                                                                                                            • Visibility and Enforcement for Outdated Plug Parameters in Zobot Canvas

                                                                                                              Dear Zoho SalesIQ Team, Greetings, We’d like to suggest an important usability and quality improvement for working with Plugs inside Zobot. Current Behavior: When we update the code of an existing Plug, any Zobot card using that Plug requires manual resaving.
                                                                                                            • Announcement: Zoho DataPrep to Deprecate Password-Only Authentication for Snowflake Connections on July 31, 2025

                                                                                                              As part of our ongoing commitment to security and in alignment with Snowflake's pledge to the Cybersecurity and Infrastructure Security Agency (CISA) Secure by Design initiative, Zoho DataPrep will no longer support single-factor password authentication.
                                                                                                            • The same Contact associated to multiple Companies - Deals

                                                                                                              Hi, I would like to know if there is an option to associate the same contact with multiple companies (two or more) deals, using the same contact details for all. This is because we have contacts who are linked to different companies or branches of the
                                                                                                            • Text on Zoho Sign confirmation dialouge is very small compared to text used everywhere else on Zoho Sign.

                                                                                                              I've reported multiple times through Zoho's support email that the text on this notification is very small in contrast to all the other text on the Zoho Sign app. I think it's a bug and it just needs the font size to be increased. It's very minor but
                                                                                                            • Wise integration in Zoho Books

                                                                                                              Hi, it is now time for zoho books to support Wise.com integration for payment links. Wise has launched credit card payments, now about 0.5% cheaper than Stripe. Also their bank payments are much much cheaper than credit cards. Its time for books team
                                                                                                            • Error Message: None of the rows can be imported

                                                                                                              I have been using zoho sheets to download my CSV file for about 2 years now, this month, October 2021, for some reason when I download it to upload to zoho books I get a message saying "None of the rows can be imported". I have been using the same process,
                                                                                                            • Invalid Element place_of_contact, Invalid Element gst_no, Invalid Element gst_treatment

                                                                                                              so this is the body contact_name: orderData.customerName, company_name: orderData.customerName, email: orderData.email, contact_type: 'customer', currency_code: 'INR', gst_treatment: 'business_gst', gst_no: 'i using proper gst no i just removed it from
                                                                                                            • Next Page