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

                                                                                                            • Connecting Portals from different Zoho apps

                                                                                                              Hi, I note that Zoho has functionality for customer portals for several of the Zoho apps, like CRM, Projects, Desk etc. Is there any way to connect these portals?  It would be great if we could give our customers access to a portal in which they could
                                                                                                            • Not able to item an item to non taxable via api, despite sending is_taxable as false

                                                                                                              Hi everyone, I'm trying to update an item via books api and even when sending is_taxable as false, the item still shows Taxable in zoho, I get no errors as well when I update, any help appreciated in this!
                                                                                                            • Collection & Payment Mapping Automation

                                                                                                              We book Sales Invoices and Purchase Invoices against Same Projects. Both Sales Invoices & Purchase Invoices can have one or multiple Projects mentioning the Project ID. We prefer to Make vendor Payments Once we have received The Collections from Clients
                                                                                                            • Nested Sub-forms (Subform within subform)

                                                                                                              Hi Team, Whether there is any possibilities to add sub-form with in another sub-form like Main Form       -> Sub form A             ->Sub form B If we tried this, only one level of sub form only working.  Any one having any idea about this? Thanks Selvamuthukumar R
                                                                                                            • Restore Trashed Records Anytime Within 30 Days

                                                                                                              Access the recycle bin from the Data Administration tab under the settings page in Zoho Projects, which gives better control over the trashed data. When records like projects, phases, task lists, tasks, issues, or project templates are trashed, they are
                                                                                                            • Avoiding Inventory Duplication When Creating Bills for Previously Added Stock

                                                                                                              I had created several items in Zoho Books and manually added their initial stock at the time of item creation. However, I did not record the purchase cost against those items during that process. Now, I would like to create Purchase Orders and convert
                                                                                                            • Applying EUR Payments to USD Invoices in Zoho Books

                                                                                                              Hello, I have a customer to whom I issue invoices in USD. However, this customer makes payments in both EUR and USD. I have already enabled the multi-currency feature in Zoho Books Elite, but I am facing an issue: When the customer makes a payment in
                                                                                                            • How to prevent users from editing mail merge templates from Zoho crm

                                                                                                              We want users to use public mail merge templates. They should not be able to edit templates but only preview data merge and send emails. We did prohibit "manage mail merge template" in the user profile. But they can still edit the template in the zoho
                                                                                                            • Customer Addresses cannot be edited/deleted in invoices

                                                                                                              In the invoices we have an option to change the customer address and add a new address Now I dont know why for some reason if we add an address through this field, the address doesn't appear in the customer module We cannot delete the addresses added
                                                                                                            • Custom Fields connected to Invoices, Customers, Quotes, CRM

                                                                                                              I created the exact same custom fields in Books: Invoices, Customer, Quotes, and in CRM but they don't seem to have a relationship to one another. How do I connect these fields so that the data is mapped across transactions?
                                                                                                            • Accelerate Github code reviews with Zoho Cliq Platform's link handlers

                                                                                                              Code reviews are critical, and they can get buried in conversations or lost when using multiple tools. With the Cliq Platform's link handlers, let's transform shared Github pull request links into interactive, real-time code reviews on channels. Share
                                                                                                            • Heads up: We're going to update the VAT Summary table's visibility (UK and Germany Editions)

                                                                                                              Hello users, Note: This change only applies to organisations using the UK and Germany editions of Zoho Books. Currently, if you've enabled the VAT Summary table in a template, it will be displayed only in PDFs sent to your customers whose default currency
                                                                                                            • Partial payment invoicing

                                                                                                              Greetings I have questions related to payments and retainer invoices: 1. When I want to issue a partial payment invoice, I can't specify the portion to be paid or already paid, then balance to be shown as Due. 2. Retainer invoice is only available as
                                                                                                            • Inputting VAT Pre-Registration expenses for first VAT Return

                                                                                                              Hi Zoho, I've just registered for VAT and am setting up Zoho to handle calculations and VAT return submissions. I'm struggling to figure out how to input the last 4 years worth of expenses into Zoho so that they're calculated in the VAT module. When I
                                                                                                            • Anyone else experiencing very slow loading of pages in Zoho Projects?

                                                                                                              I reported this yesterday only to be told there are no issues but is anyone else experiencing stupidly slow loading of pages. On our loading screen, it is taking often as long as 60 seconds to load a page and just stays on this screen for ages! Other
                                                                                                            • Zoho Desk Lookup Field Reporting

                                                                                                              Thank you for adding the ability to add additional lookup fields for desk tickets. My question is how do you report against these fields? For example: Associating related accounts to the primary desk ticket account, I am not able to add the lookup fields
                                                                                                            • Integrating asana will cause notification messages to pop up continuously

                                                                                                              When I create or edit a task in Asana, the Asana bot keeps updating messages to group chat, which causes the cliq to keep popping up notifications.
                                                                                                            • Is there an API to "File a Ticket" in Desk

                                                                                                              Hi, Is there an API to "File a Ticket" in Desk to zoho projects?
                                                                                                            • Entire notebook that had notes has disappeared

                                                                                                              I don't know how tf this happened. All I did was uninstall and reinstall the mobile app after fixing a bug I had. After I reinstalled the app, everything was synced back except for one folder which had a bunch of notes in it. None of those notes are in
                                                                                                            • My site has disappeared from web builder

                                                                                                              www.mproperties.uk My site above is still working. However it has completely disappeared from my Zoho sites' web builder. I am therefore unable to edit my site whatsoever. Please help.
                                                                                                            • Kaizen #147 - Frequently Asked Questions on Zoho CRM Widgets

                                                                                                              Heya! It's Kaizen time again, folks! This week, we aim to address common queries about Zoho CRM Widgets through frequently asked questions from our developer forum. Take a quick glance at these FAQs and learn from your peers' inquiries. 1. Where can I
                                                                                                            • Trying to trigger email notification based on rollup summary field

                                                                                                              Hi there, I'm trying to trigger an email notification via Workflow Rules wherever the rollup summary field "Total Shipments" goes from empty to not empty. However this field is not available from the picklist of options in the Workflow rule. Can anyone
                                                                                                            • zia data enrichment - switch to webamigo Extension

                                                                                                              Hello, I have so far used data enrichment via Zia. Now I have installed the Webamigo extension to expand personal data. Unfortunately, nothing has changed after the installation; are there any additional steps needed to switch from the previous method
                                                                                                            • Rich-text fields in Zoho CRM

                                                                                                              Hello everyone, We're thrilled to announce an important enhancement that will significantly enhance the readability and formatting capabilities of your information: rich text options for multi-line fields. With this update, you can now enjoy a more versatile
                                                                                                            • Export Timeline

                                                                                                              With the new Timeline features, it would be really helpful to have the option to export a timeline. When handling customer complaints, having the full breakdown of everything that happens on a module is great but we usually have to send this to another
                                                                                                            • Interactions Tab in Zoho CRM: A 360° Omnichannel View of Every Customer Touchpoint

                                                                                                              Hello Everyone, Hope you are well! We are here today with yet another announcement in our series for the revamped Zoho CRM. Today, we introduce Interactions Tab a new way to view all customer interactions from one place inside your CRM account. Customers
                                                                                                            • How to resubscribe a contact marked as "Unsubscribed (Marked by Recipient)" without using a form?

                                                                                                              Hello, I have a question regarding Zoho Marketing Automation functionality. Is there a way for an administrator to change the subscription status of a contact marked as "Unsubscribed (Marked by Recipient)" back to "Subscribed" without using a form? Ideally,
                                                                                                            • Linkedin: when Zoho Social is going serious with it?

                                                                                                              Hi, it's been said in the past that Linkedin related features in Zoho Social were well behind those of other social networks because of limitations imposed by the platform. Now that we see around my tools (take taplio.com) frankly outpacing ZSocial on
                                                                                                            • 5名限定 課題解決型ワークショップイベント Zoho ワークアウト開催のお知らせ(7/24)

                                                                                                              ユーザーの皆さま、こんにちは。Zoho ユーザーコミュニティチームの藤澤です。 7月開催のZoho ワークアウトについてお知らせします。 2ヶ月ぶりに、渋谷にて「リアル開催」します! ▷▷詳細はこちら:https://www.zohomeetups.com/20250724Zoho ━━━━━━━━━━━━━━━━━━━━━━━━ Zoho ワークアウトとは? Zoho ユーザー同士で交流しながら、サービスに関する疑問や不明点の解消を目的とした「Zoho ワークアウト」を開催します。 Zoho サービスで完了させたい設定やカスタマイズ、環境の整備など……各自で決めた目標達成に向け、
                                                                                                            • How to get fields centered in a form?

                                                                                                              Is it possible to center fields in a form? Some of my forms do some don't and it is really not aestheticly pleasing?  Any help would be greatly appricated. Thanks, Michael McNeill 
                                                                                                            • Make Packages from multiple sales order of a single customer

                                                                                                              Our customers sends orders to us very frequently, some times what customer wants is to ship items from 5 to 6 sales orders in a single shipment. it will be very nice if, zoho can implement this function, in which we can select items from other sales orders of the customer.
                                                                                                            • Webhooks and Integration

                                                                                                              Hey, I was looking to create automation using webhooks or something equivalent of a trigger based mechanism, to connect it as an integration. But I don't find any relevant APIs to setup these webhooks/notifcations for the "Zoho Books". Can anyone please
                                                                                                            • Zoho Books X Zoho Expense

                                                                                                              Hello there, Please can you tell me if it is possible to sync from Books to Expense? I much prefer the Expense reports to that of Books and the Credit Card feeds work via expense and not Books for me. However I find books is much better to deal with the
                                                                                                            • ABILITY TO LOG INTO CUSTOMER PORTAL

                                                                                                              I think it would be very helpful to have a button in Zoho Books to be able to see the customer portal so we can see what they see to help them navigate through the portal. Many times, the customer will call about the portal, but without visibility into
                                                                                                            • Sort, filter & save views for BOOKS PROJECTS

                                                                                                              Thanks for all the updates. Our firm uses the module for simple internal project accountancy. This means we do everything from the Projects Section but this isn't user friendly at all. You can't do anything with customized your own fields which basically
                                                                                                            • edit input format in custom field - sales order

                                                                                                              hi, I want to integrate a custom field (multi line text box) in our sales order. It needs to show upper case and lower case letters, numbers, spaces, hyphens and "/". What do I need to put in the custom format to configure these signs? Thanks, Tina
                                                                                                            • This transaction type cannot be matched with a line on the statement.

                                                                                                              When using the books API https://www.zohoapis.com/books/v3/banktransactions/uncategorized/${transaction.transaction_id}/match I get this error "This transaction type cannot be matched with a line on the statement." What I'm doing is for the uncategorized
                                                                                                            • Full Text Customization & Translation in SalesIQ Chat Widget Settings

                                                                                                              Dear Zoho SalesIQ Team, Greetings, We would like to request an important enhancement to the chat widget customization options in Zoho SalesIQ. Current Limitation: At the moment, only some of the text shown in the chat widget is editable or translatable
                                                                                                            • Power of Automation :: Quick way to associate your Projects with Zoho CRM

                                                                                                              A custom function is a software code that can be used to automate a process and this allows you to automate a notification, call a webhook, or perform logic immediately after a workflow rule is triggered. This feature helps to automate complex tasks and
                                                                                                            • Timesheets

                                                                                                              I wanted to create the timesheets remainder for our team mates who miss out the weekly timesheet entries. While creating the email templates, I couldn't see anything related to timesheets. Since it shows projects Can you help me find and build a one
                                                                                                            • Next Page