How to merge subform fields and image field via Zoho Writer's Merge APIs?

How to merge subform fields and image field via Zoho Writer's Merge APIs?

Overview

Zoho Writer's Merge API enables the dynamic population of documents using data from Zoho CRM. This includes merging not only standard fields but also related list (subform) fields and image fields. This guide outlines the steps required to merge subform and image fields into Writer templates using both Deluge scripts and API calls.

Steps

  1. Open Zoho Writer and create a new merge template.
  2. Insert merge fields for both main module and related list (subform) fields using the field insert option.
Example Template Content:

Hello <<Contacts.First Name>>
Send a mail to <<Contacts.Email>>

Invoice Owner
Invoice Number
Created By
Due Date
<<Invoices.Invoice Owner>>
<<Invoices.Invoice Number>>
<< Invoices. Created By>>
<<Invoices.Due Date>>

Product_Code

Product_Description

Item_Quantity

Item_Price

 

«Products.Product_Code»

 

«Products.Product_Description»

 

«Products.Item_Quantity»

 

«Products.Item_Price»

Step 2: Retrieve RL Field Information via API  

Use the following Deluge code to retrieve all merge fields from your template:
fields = invokeurl
[
type: GET
connection:"<CONNECTION_NAME>"
];
info fields;
Notes
  • Replace <DOCUMENT_ID> with your actual Writer document ID.

  • Reference Zoho Connections for setting up the connection.

Step 3: Map RL Fields via Deluge Script  

invoicesRecords = zoho.crm.getRecordById("Invoices", invoiceId);

 

CustomerInvoice = Map();

CustomerInvoice.put("First_Name", invoicesRecords.get("Account_Name").get("name"));

CustomerInvoice.put("Email", invoicesRecords.get("Account_Name").get("id"));

 

invoicesList = list();

invoiceDetails = Map();

 

invoiceDetails.put("Invoices.Owner", invoicesRecords.get("Owner").get("name"));

invoiceDetails.put("Invoices.Invoice_Number", invoicesRecords.get("Invoice_Number"));

invoiceDetails.put("Invoices.Created_By", invoicesRecords.get("Created_By").get("name"));

invoiceDetails.put("Invoices.Due_Date", invoicesRecords.get("Due_Date"));

invoicesList.add(invoiceDetails);

 

productList = list();

productDetails = Map();

productDetails.put("Products.Product_Code", invoicesRecords.get("Product_Code"));

productDetails.put("Products.Product_Description", invoicesRecords.get("Product_Description"));

productDetails.put("Products.Item_Quantity", invoicesRecords.get("Item_Quantity"));

productDetails.put("Products.Item_Price", invoicesRecords.get("Item_Price"));

productList.add(productDetails);

 

 

CustomerInvoice.put("Invoices", invoicesList);

CustomerInvoice.put("Products", productList)

 

 

mergedata = Map();

mergedata.put("merge_data", {"data": CustomerInvoice});

mergedata.put("subject", "Invoice Details");

 

//optional

mergedata.put("message", "Please find your invoice attached.");

info mergedata;

 

zoho.writer.mergeAndSend("eb4kob4cf65bb6d074af7a7de21e561119eb9", "pdf", invoicesRecords.get("email"), mergedata, "<CONNECTION_NAME>");

Step 4: Sample JSON data with RL fields (via APIs)

{

    "data": [

        {

            "First_Name": "Amelia",

            "Email": "amelia@zylker.com",

            "Invoices": [

                {

                    "Invoices.Owner": "John",

                    "Invoices.Invoice_Number": 1279,

                    "Invoices.Created_By": "Amelia",

                    "Invoices.Due_Date": "07/10/2020"

                }

            ]

            "Products": [

              {

                "Products.Product_Code": "A123",

                "Products.Product_Description": "Mobile Cases",

                "Products.Item_Quantity": 2,

                "Products.Item_Price": 1000

              }

            ]

        }

    ]


Step 5: Pass Image Field Values in Merge API  

To include image fields in the merge:
  • Invoke Get Record API (version 5 and above) and use the Preview Image ID [Preview_Id__s] from the CRM response.
  • Construct the image URL manually using the below pattern:
Sample values to replace the variables in the snippet shared below:
Info
Module = "Leads";   //Provide your respective module name
RecordId = "456789";   //CRM record id
RLModuleName = "Products";   //Related List Name
zohoapi_domain (for US DC) = "https://www.zohoapis.com";   //For other DCs, refer the API domains here.

For Standard Image Fields  

// get Records
recordInfo = invokeurl
[
url :zohoapi_domain+"/crm/v5/"+Module+"/"+RecordId;
type :GET
connection:"<CONNECTION_NAME>"
];
recordInfoData = recordInfo.get("data").get(0);
dataMap = Map();
dataMap.put("Email",recordInfoData.get("Email"));
dataMap.put("Last_Name",recordInfoData.get("Last_Name"));
// Image field
if(recordInfoData.get("Image_Upload") != null)
{
imageId = recordInfoData.get("Image_Upload").get(0).get("Preview_Id__s");
imageUrl = zohoapi_domain+"/crm/v2.1/__attachment_preview/" + imageId;    //constructed image url 
dataMap.put("Image_Upload",imageUrl);
}
info dataMap;

For Image Fields in Related Lists  

If image field is a RL record, then invoke this Related Records Data API (version 5 and above) to get the RL Record ID. Then, invoke the Get Records API with this RL Record ID to get the Preview Image ID.
dataMap = Map();
 //Get Related List IDs
relatedListsIds = invokeurl
[
url:zohoapi_domain+"/crm/v5/"+Module+"/"+RecordId+"/"+RLModuleName+"?fields=Parent_Id"
type :GET
connection:"<CONNECTION_NAME>"
];
rlListData = relatedListsIds.get("data");
rlProductsList = List();
//Get Related List Data
for each  record in rlListData
{
rlId = record.getJSON("id");
rlInfo = invokeurl
[
url :zohoapi_domain+"/crm/v5/+"RLModuleName+"/" + rlId
type :GET
connection:"crm"
];
rlInfoData = rlInfo.get("data").get(0);
rlMap = Map();
rlMap.put("Product_Name",rlInfoData.getJSON("Product_Name"));
rlMap.put("Product_Code",rlInfoData.getJSON("Product_Code"));
//RL Image Field
if(rlInfoData.get("Image_Upload") != null)
{
rlImageId = rlInfoData.get("Image_Upload").get(0).get("Preview_Id__s");
imageUrl = zohoapi_domain+"/crm/v2.1/__attachment_preview/" + rlImageId;  //constructed image url
rlMap.put("Image_Upload",imageUrl);
}
rlProductsList.add(rlMap);
}
//Add Related List to dataMap
dataMap.put("Products",rlProductsList);
info dataMap;

Additional Notes

  • Always use the /fields API to dynamically retrieve field names for accurate mapping.
  • Ensure that merge field names in the Writer template exactly match the JSON keys used in your API or Deluge script.
  • For all image fields, construct the image URL using the __attachment_preview endpoint:
    https://{zohoapi_domain}/crm/v2.1/__attachment_preview/{Preview_Id__s}
  • The CRM API only provides image Preview IDs, not full URLs — construction is mandatory.
  • Use the correct API versions (v5 for CRM, v2.1 for attachment preview).
  • If using Deluge:
    • Ensure connection is set up.
    • JSON mapping must match the Writer template structure.
  • The Writer Document ID can be found in the URL in this format:
    /writer/open/<document_id>

      Create. Review. Publish.

      Write, edit, collaborate on, and publish documents to different content management platforms.

      Get Started Now


        Access your files securely from anywhere

          Zoho CRM Training Programs

          Learn how to use the best tools for sales force automation and better customer engagement from Zoho's implementation specialists.

          Zoho CRM Training
            Redefine the way you work
            with Zoho Workplace

              Zoho DataPrep Personalized Demo

              If you'd like a personalized walk-through of our data preparation tool, please request a demo and we'll be happy to show you how to get the best out of Zoho DataPrep.

              Zoho CRM Training

                Create, share, and deliver

                beautiful slides from anywhere.

                Get Started Now


                  Zoho Sign now offers specialized one-on-one training for both administrators and developers.

                  BOOK A SESSION







                              Quick LinksWorkflow AutomationData Collection
                              Web FormsRetailOnline Data Collection Tool
                              Embeddable FormsBankingBegin Data Collection
                              Interactive FormsWorkplaceData Collection App
                              CRM FormsCustomer ServiceForms for Solopreneurs
                              Digital FormsMarketingForms for Small Business
                              HTML FormsEducationForms for Enterprise
                              Contact FormsE-commerceForms for any business
                              Lead Generation FormsHealthcareForms for Startups
                              Wordpress FormsCustomer onboardingForms for Small Business
                              No Code FormsConstructionRSVP tool for holidays
                              Free FormsTravelFeatures for Order Forms
                              Prefill FormsNon-Profit
                              Forms for Government
                              Intake FormsLegal
                              Mobile App
                              Form DesignerHR
                              Mobile Forms
                              Card FormsFoodOffline Forms
                              Assign FormsPhotographyMobile Forms Features
                              Translate FormsReal EstateKiosk in Mobile Forms
                              Electronic FormsInsurance
                              Drag & drop form builder

                              Notification Emails for FormsAlternativesSecurity & Compliance
                              Holiday FormsGoogle Forms alternative GDPR
                              Form to PDFJotform alternativeHIPAA Forms
                              Email FormsWufoo alternativeEncrypted Forms
                              Accessible FormsTypeform alternativeSecure Forms

                              WCAG

                                          Create. Review. Publish.

                                          Write, edit, collaborate on, and publish documents to different content management platforms.

                                          Get Started Now






                                                            You are currently viewing the help pages of Qntrl’s earlier version. Click here to view our latest version—Qntrl 3.0's help articles.




                                                                Manage your brands on social media

                                                                  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



                                                                    Zoho Sheet Resources

                                                                     

                                                                        Zoho Forms Resources


                                                                          Secure your business
                                                                          communication with Zoho Mail


                                                                          Mail on the move with
                                                                          Zoho Mail mobile application

                                                                            Stay on top of your schedule
                                                                            at all times


                                                                            Carry your calendar with you
                                                                            Anytime, anywhere




                                                                                  Zoho Sign Resources

                                                                                    Sign, Paperless!

                                                                                    Sign and send business documents on the go!

                                                                                    Get Started Now




                                                                                            Zoho TeamInbox Resources





                                                                                                      Zoho DataPrep Demo

                                                                                                      Get a personalized demo or POC

                                                                                                      REGISTER NOW


                                                                                                        Design. Discuss. Deliver.

                                                                                                        Create visually engaging stories with Zoho Show.

                                                                                                        Get Started Now









                                                                                                                            • Related Articles

                                                                                                                            • How to setup image type merge field in Zoho Writer

                                                                                                                              Overview The Image Field Merge feature in Zoho Writer lets you dynamically insert images (like profile photos, product images, logos, or scanned documents) into templates during a mail merge. You can map image fields from your data source—such as ...
                                                                                                                            • How to setup fields in fillable templates in Zoho Writer

                                                                                                                              Overview A fillable template in Zoho Writer is a document designed with interactive form fields that allow users to enter, edit, or submit data directly within the document, just like filling out a digital form. There are 20 field types that are ...
                                                                                                                            • How to merge and send document via email in Zoho Writer

                                                                                                                              Overview The Merge and Send via Email option in Zoho Writer lets you generate personalized documents for each record in your data source and automatically send them via email. Each recipient gets a customized document as an attachment or inline ...
                                                                                                                            • Zoho Writer merge templates: understanding supported merge data sources and its limits

                                                                                                                              Overview This table provides a consolidated comparison of data source limits in Zoho Writer, organized by app, and includes details on image support, record limits, and subform (table) constraints for the supported data sources Supported Data Sources ...
                                                                                                                            • How to track merge status and handle errors in Zoho Writer

                                                                                                                              Overview You can track the status of the merge jobs using email notifications and the merge logs. While email notifications help you track the merge initiation and completion status, the merge logs help you track the status of jobs in progress, along ...
                                                                                                                              Wherever you are is as good as
                                                                                                                              your workplace

                                                                                                                                Resources

                                                                                                                                Videos

                                                                                                                                Watch comprehensive videos on features and other important topics that will help you master Zoho CRM.



                                                                                                                                eBooks

                                                                                                                                Download free eBooks and access a range of topics to get deeper insight on successfully using Zoho CRM.



                                                                                                                                Webinars

                                                                                                                                Sign up for our webinars and learn the Zoho CRM basics, from customization to sales force automation and more.



                                                                                                                                CRM Tips

                                                                                                                                Make the most of Zoho CRM with these useful tips.



                                                                                                                                  Zoho Show Resources