How to use Zoho WorkDrive files into Writer merge fields?

How to use Zoho WorkDrive images in Zoho Writer's merge fields

Overview

When performing a mail merge in Zoho Writer, image fields must be provided with a public URL to properly display the image. If your images are stored in Zoho WorkDrive, you can generate a public download URL and use it for your image fields.

This article explains multiple ways to achieve this using the WorkDrive UI, WorkDrive API, or via a Deluge script.

Method 1: Using the WorkDrive User Interface (UI)

1. Navigate to the desired image in your WorkDrive folder.


2. Click on the More option (three dots) and select New Download Link.
3. In the pop-up window, create the download link and copy it.
4. Append ?directDownload=True to the copied link.

Example:

Original: https://workdrive.zohoexternal.com/external/abc123/download
Final: https://workdrive.zohoexternal.com/external/abc123/download?directDownload=True

Use the final link as the input value for your image field in Zoho Writer.

Method 2: Using WorkDrive API

You can programmatically create a download link using the following API:

Endpoint: POST <workdrive domain>/api/v1/links
Required Scope: WorkDrive.files.CREATE

Sample Payload:
{
"data": {
"attributes": {
"resource_id": "g576y886ac79ac5************",
"link_name": "sample_link",
"link_type": "download",
"request_user_data": false,
"allow_download": true,
"expiration_date": "2021-12-12",
"download_link": {
"download_limit": "5"
}
},
"type": "links"
}
}

Sample Response:

Look for the 'download_url' key in the response.
Info
Append ?directDownload=True to the download_url before using it in Writer.

Method 3: Using Deluge Script

Step 1: Upload Image to WorkDrive

Use the below script and upload the image to WorkDrive.
workdrive_folder_id = "g576*****";
responseData = zoho.workdrive.uploadFile(image1,workdrive_folder_id,image1.getFileName(),true,"<connection_name>");
workdrive_resourceid = "";
if(responseData != null){
responseList = responseData.get("data");
responseData = responseList.get(0);
workdrive_resourceid = responseData.get("attributes").get("resource_id");
}

Step 2: Create Download Link

Use the below script to create an external download link for the image from WorkDrive.
attribute = Map();
attribute.put("resource_id", workdrive_resourceid);
attribute.put("allow_download", true);
attribute.put("request_user_data", false);
attribute.put("link_name", "sample_link");
attribute.put("expiration_date", "2021-12-12");

attributeMap = Map();
attributeMap.put("attributes", attribute);
attributeMap.put("type", "links");
param = Map();
param.put("data", attributeMap);
paramString = param.toString();

mp = Map();
mp.put("Accept", "application/vnd.api+json");
makeExternalLink = invokeurl
[
url :"
https://workdrive.zoho.com/api/v1/links"
type :POST
parameters:paramString
headers:mp
connection:"<connection_name>"
];

linkobj = makeExternalLink.get("data");
downloadlink = "";
if(linkobj != null)
{
constructURl = linkobj.get("attributes").get("download_url");
downloadlink = constructURl + "?directDownload=True";
}

Sample Download Link:
https://workdrive.zohoexternal.com/external/b24042070f8fb42dc9a54132bcc610ab/download?directDownload=True

Use this final download link as the value for the image field in your Writer template.

Summary

Regardless of the method used—UI, API, or Deluge—the key requirement is:
  1. You must obtain a public download URL from Zoho WorkDrive.
  2. Append ?directDownload=True to the end of the URL.
This ensures that the link works correctly as the image field value during your Zoho Writer merge process.

1. Error / Symptom: Some images from subforms or image merge fields do not appear in the merged PDF, especially when merging documents with many images stored in Zoho WorkDrive using external share links.

Possible cause: Zoho WorkDrive external share links have a throttle limit of 40 requests per second. During PDF merge, Writer sends multiple parallel requests to download images. If the limit is exceeded, some image download requests fail, causing images to be missing in the output PDF.

Recommended solution:
  1. Avoid using WorkDrive external share links for image merge fields when merging large numbers of images.
  2. Instead, use the direct download link of the image file instead of the external share link or ensure the image source can handle multiple simultaneous download requests without throttling.
  3. Retry the merge after updating the image URLs.