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

                                                                                                            • Create Project while winning potentials - Projects v3 api updated code

                                                                                                              Hi all, I've been using the built in function to create a project while a deal is closed won and noticed it had some missing fields when trying to reference the zoho projects v3 api documentation. Specifically the project group had some issues when adding
                                                                                                            • [Free Webinar] Zoho RPA - OCR, PDF Automation, & More

                                                                                                              Hello Everyone! Greetings from the Zoho RPA Training Team! We’re excited to invite you to our upcoming webinar on the latest release updates for Zoho RPA, where we’ll unveil powerful new capabilities designed to make your automation journey smarter, faster,
                                                                                                            • Merge feature parity with writer

                                                                                                              Hello Zoho team, I have run into a workflow limitation with Zoho Contracts and the lack of merge feature parity with what Writer can do. We have created a fairly complex merge process to create a statement of work based on several fields in our CRM which
                                                                                                            • Export option in Contacts is missing

                                                                                                              Hello - I've been clicking around Zoho all morning trying to find the export option. It formerly was in the right hand corner, above the search box, but now I don't see it. I've looked everywhere - Am I missing it somehow? I've attached a screenshot.
                                                                                                            • Formatting of cells changing by itself and formulas not always calculating automatically

                                                                                                              I'm new to Sheets and have been setting up a budgeting template that has many linked tabs. It's going fairly well except certain quirky things have been happening from time to time. 1- sometimes when I scroll up or down I lose formatting from a random
                                                                                                            • Unable to open iOS Zoho CRM app

                                                                                                              i am unable to open Zoho CRM iOS App in iPhone 14 Pro Max v18.5 and it is crashing immediately after i click to open
                                                                                                            • Whatsapp BOT with CRM

                                                                                                              Hello, how do you use Whatsapp integrations in zoho CRM?
                                                                                                            • sync two zoho crm

                                                                                                              Hello everyone. Is it possible to sync 2 zoho crm? what would be the easiest way? I am thinking of Flow. I have a Custom Module that I would like to share with my client. We both use zoho crm. Regards.
                                                                                                            • Side-by-Side view on Windows 11

                                                                                                              Is there a way to open two notes in a side-by-side view? I'm running Notebook on a Desktop running Windows 11. If this feature doesn't exist, do you have plans for it?
                                                                                                            • Value shows in balance sheet for Goods in Transit

                                                                                                              We have transferred goods from one warehouse to another warehouse and accepted the same at another warehouse. Although my balance sheet shows X amount as goods in transit value. I don't understand, how to clear that  Can anyone guide us please?
                                                                                                            • Resolution Time Report

                                                                                                              From data to decisions: A deep dive into ticketing system reports What are time-based reports? Time-based reports are valuable tools that help us understand how well things are going by breaking down key metrics over specific periods. By tracking, measuring,
                                                                                                            • Ask for a quote to multple vendors

                                                                                                              We are able to send a Purchase order, but How can we Send a quote request to our vendor, once the value changes every time? I didn't see any feature like this in Zoho Books/ Inventory. Send this request with the Items that we want to know the cost, to
                                                                                                            • Bigin merge field in email template for subject line to match lead name

                                                                                                              Hello We Are using email in to automatically create leads in our pipelines. When we want to reply from conversations, and apply an email template, it’s not matching the original subject line. It should be lead name to match. But it’s not working. Even
                                                                                                            • How to create auto-link between Invoice and Quote in CRM

                                                                                                              It's strange that when you 'convert' a quote into an invoice, it doesn't auto-link the two. How can we develop an auto sync so we don't need to manually link each invoice to their respective quote?
                                                                                                            • Why Are Columns Reset When Deleting Entry

                                                                                                              Hello, this is quite annoying. We use forms as a questionnaire for candidates, we filter entries by removing columns, when we delete an entry the columns reset. Every "delete" the columns reset, why!? Thank you
                                                                                                            • Pi or Pie? A slice of infinity in customer service

                                                                                                              Hey everyone! While Pi Day is on March 14 (3.14), July 22 marks another special occasion: Pi Approximation Day! On this day, we recognize the mathematical constant π (pi ≈ 22/7); a number that's infinite, irrational, and never-ending. Pi is essential
                                                                                                            • Configuración

                                                                                                              Hola acabo de instalar Zoho CRM y quiero configurarlo correctamente. Al respecto me surgen algunas dudas tales como la diferencia entre: Cuentas, posibles Clientes y Contactos. ¿Conceptualmente que son cada uno? ¿Como se se relacionan entre ellos? Si
                                                                                                            • Why Can't I add unicode emoji's to my signature?

                                                                                                              Why would Zoho Mail prevent me from adding unicode emojis to my email signature? Every time I try to save the signature, Zoho Mail erases the emoji and any nearby content. Every time I setup something with Zoho, I know I'm going to run into some incredibly
                                                                                                            • GL account associated to each supplier for new bill

                                                                                                              Hello I'm facing problem for all items of my bills that are not inventoried. The need is each time I enter new bill and after I select supplier the GL account section is autopopulated with default GL account (that I would like to add in supplier settings)
                                                                                                            • LinkedIn verification link and otp not receiving

                                                                                                              For the last 2 to 3 weeks I'm trying to verify my LinkedIn account to access my company's LinkedIn page, Linkedin is sending verification links and codes to this email address but I have not received any codes or links. Please help me here. Looking forward
                                                                                                            • Zoho reply to not working. just reply to my self

                                                                                                              Hello. i using on my wordpress website a contact form from Wsform. i can set the reply to email there. normally it works. but since i am using your wordpress plugin zoho mail it doesn`t work. its not using the reply to (email from customer). I just can
                                                                                                            • Mail Merge Stuck in Queue

                                                                                                              I am trying to send Mail Merge's and it never sends out to the full list. It always hits a portion and the rest remain in the "Queue" - the emails I am sending are time sensitive, so I need this to be resolved or have a way to push the emails through
                                                                                                            • SMTP Email Sending Not Working for My Domains and Apps

                                                                                                              Hello Zoho Support Team, I am experiencing a critical issue with sending emails via Zoho SMTP for my domain humanhup.com. Both of my applications, HumanHup and CheapUI, are unable to send emails using Zoho SMTP, even though the same setup was working
                                                                                                            • Receiving too many Spam Leads. Why?

                                                                                                              I am receiving so many junk leads from web forms created by zoho's platform. The junk queries are increasing day by day and are affecting our business. I am continuously following up with zoho team from the past one year but not getting any satisfactory
                                                                                                            • Why is Zoho supporting the Proud Boys?

                                                                                                              Hello. This is the only way I can find to contact your company. There is someone in Maine posing as a law enforcement officer, attempting to kidnap immigrants. They are also recruiting for a known hate group. They have an email address hosted by Zoho.com.
                                                                                                            • Composite Item - Associated/Component Items

                                                                                                              I am trying to find the Associated Item/Component Item field in the Composite Item Table in Analytics. Has anyone been able to find and utilize this field in Analytics?
                                                                                                            • What is a a valid JavaScript Domain URI when creating a client-based application using the Zoho API console?

                                                                                                              No idea what this is. Can't see what it is explained anywhere.
                                                                                                            • 🚀 WorkDrive 5.0: Evolving from a file sharing app to an intelligent content management platform: Phase 2

                                                                                                              Hello everyone, WorkDrive's primary focus has always been to provide an intelligent and secure content management platform, simplify collaboration, and be the central repository of files for all Zoho apps. In our previous announcement, we unveiled the
                                                                                                            • Use openUrl() to edit a specific record

                                                                                                              I am working on a queue app for my organization. I have a master queue that is a report of meetings with workflow buttons to manipulate the records. One of these buttons I would like to open the record and edit for the purpose of changing the queue lookup
                                                                                                            • why i cant access my web without the www

                                                                                                              please help me
                                                                                                            • Send Whatsapp with API including custom placeholders

                                                                                                              Is is possible to initiate a session on whatsapp IM channel with a template that includes params (placeholders) that are passed on the API call? This is very usefull to send a Utility message for a transactional notification including an order number
                                                                                                            • Help Centre Articles in Desk, Zia and iframe

                                                                                                              Hi, We embed SOP documents into articles from Scribe into using iframe. We are looking at zia indexing articles to present to agents to aid their work. Please advise if zia can view and learn from the content within the iframe?
                                                                                                            • Rich Text/WYSIWYG Input Area

                                                                                                              I'd like to have an option on ZoHo creator to create an input text area for HTML/rich text formatting. :)
                                                                                                            • How to create a directory report from one-to-many relationship

                                                                                                              Hi all, Newbie here. I'm converting an Access DB to Creator. I've learned Forms are tables and Reports are used to edit table rows, not Forms. I've got the data loaded and can maintain it with the Reports already done. I've done filtering and sorting,
                                                                                                            • Change Default Selection for Lookup field

                                                                                                              I have a Lookup field that I have locked, when I unlock it - the user can select the proper Zone but I need it locked, since this may change based on user selection of another field. Example. There are 3 potential zones. User A selects the Hospital Account
                                                                                                            • Restrict visibility and user permissions Creator 5

                                                                                                              I don't understand how restrict visibility for reports interacts with the already established role permissions. It seems that the default on restrict visibility has everything checked for all users, but I cannot set up different levels of permission for different individuals.  Right now I have three different ways to manage users and their access and it's confusing because everything has not migrated to Creator 5. Don't the role permissions extend to the reports as well? Are the selections under
                                                                                                            • LMS - Why do Trainers have to be Users?

                                                                                                              I'm not sure why the software is set up where trainers must be users (i.e., employees). This should really be changed, as there are many cases (the majority of cases for some companies) where classroom trainers are external or contractors. If this is
                                                                                                            • ZOho mail not stopped working with my domain.

                                                                                                              i have changed my name server settings in my domain sigmasquaretec.in . After that my emails are not working with ZOHO.
                                                                                                            • Request to Cancel Zoho Mail Subscription

                                                                                                              Hello Zoho Team, I have migrated to Google Workspace and would like to cancel my Zoho Mail subscription for my organization. Organization Name: AR Creators Media Admin Email: roman@arcreatorsmedia.com Subscription ID: RPUS2005901960812 Please cancel the
                                                                                                            • zoho smtp limit for free users

                                                                                                              What is Zoho SMTP limit for free users?
                                                                                                            • Next Page