Attachment

Purpose

To send the merge document as attachment with a message in the body of the email.

HTTP Request URL

https://{zohoapis_domain}/writer/api/v1/documents/{{document_id}}/merge/email

Path Parameters

ParameterData TypeDescription
Mandatory Parameters
document_idStringSpecify a unique id for the writer document.

Body Parameters

ParameterData TypeDescription
Mandatory Parameters
output_formatStringSupported formats are pdf, pdfform and docx. Specify the format in which the merged document needs to attached and sent.
subjectStringSpecify a subject to the email.
messageStringSpecify a message related to the attachment in the email.
recipient_emailStringSpecify the receiver's email id.
You can provide the data in any one of the below formats
merge_dataJSONObjectPass a String value through 'data' key as JSON Array.
merge_data_csv_contentFileProvide the required csv content in your API request body.
merge_data_json_contentFileProvide the required json content in your API request body.
merge_data_csv_urlurlProvide the required csv url in your API request body.
merge_data_json_url urlProvide the required json url in your API request body.
Optional Parameters
cc_emailStringSpecify the Cc email id's (maximum upto 10) separated by comma.
bcc_emailStringSpecify the BCC email id's (maximum upto 10) separated by comma.
passwordStringSpecify a password if you would like to protect the merged document.
attachment_nameString

Specify a name (without extension) for the merged document (pdf or docx) that is attached in the mail.

For example: "attachment_name = test" (extension will be automatically added according to the attached file format)

from_emailString

Specify the from address using which the merge document needs to be sent.

If the 'from_email' parameter is not passed (OR) the 'from address' is not configured in the  Template's Mail Merge Settings, we will go ahead and use the Email ID of the current user who is sending the mail (by default).

common_attachmentsFile

Specify the attachments that needs to be sent to all the recipients in common.

Maximum files allowed: 3

Maximum file size allowed: 3MB

Supported file formats: docx / doc / rtf / pdf / zip / html / txt / png / jpeg / gif / jpg

unique_attachments

{
  "type": "field",
  "field_id": <field_id>
}

(OR)

{
   "type": "file",
   "folder_id":123456789,
   "filename_filter":
        {
           "type":"startswith/contains/is/endswith",
           "value": <field_id>
        },
}

Using this param, you can send a different or unique attachment to each recipient.

It can be sent in either one of the following ways;

1. Field Containing Attachment URLs - If you want to map the attachment file paths to a spreadsheet/CSV file.

(OR)

2. Folder Containing Attachments - If you want to map the attachment file paths to a particular folder.

from_nameStringSpecify the display name for your 'from address'. If this param is not passed, by default, we will take the display name of your Zoho email account.
replyto_emailStringSpecify the 'Reply to' email address to which you want the receipients response email to be sent.
sign_service_nameString

Specify the third party sign service name with respect to which the merged document needs to be generated.

Possible values are adobesign and docusign. By default, it will be zohosign.

test_modeBoolean (true/false)

Using this param, you can test the Merge APIs without consuming any credit points. The output file will contain a watermark as it is used only for testing purpose.

Test mode limit: 50 merges/day for an org.

Note:

  • We have also provided an option to configure the values for all the above parameters while creating the document itself.
  • If you have saved the merge settings earlier by configuring the parameter values, then we will get those values (by default) if you miss to pass the parameters while sending the API request.
  • Optional parameters are not supported in mergeAndSend deluge task. To make use of them, you need to use the invokeURL task with this API.

Sample Request

Copiedcurl --location --request POST "https://zohoapis.com/writer/api/v1/documents/ponazfea04477109f4681a831e7177d96bc40/merge/email" \
  --header "Authorization: Zoho-oauthtoken xxx.yyy.zzz" \
  --form "output_format=pdf" \
  --form "message=Email Message" \
  --form "subject=Email Subject" \
  --form "recipient_email=amelia@zylker.com" \
  --form "merge_data={\"data\":[{\"name\":\"Amelia\",\"email\":\"amelia@zylker.com\"}]}"
Copieddata = Map(); 
data.put("InvoiceNo","12345"); 
data.put("InvoiceDate","27 May 2022"); 
data.put("InvoiceAmount","$100");
param = Map(); 
param.put("message", "Reg Invoice \n Please find your invoice attached."); 
param.put("subject", "Invoice Data"); 
param.put("merge_data", {"data":data}); 
param.put("output_format", "pdf"); 
param.put("recipient_email","amelia@zylker.com"); 
param.put("cc_email", "john@zylker.com");    //optional
param.put("bcc_email", "kim@zylker.com");   //optional
param.put("from_email", "jackson@zylker.com");    //optional
param.put("password","*****");   //optional
param.put("attachment_name", "Invoice");    //optional
param.put("from_name", "Jack");    //optional
param.put("replyto_email", "jerry@zylker.com");    //optional
invokeurl 
[ 
url: "https://zohoapis.com/writer/api/v1/documents/fbsa6360a78f53f564dfa9b4a1e79febed569/merge/email" 
type: post 
parameters: param 
connection: "<connection_name>" 
];

Sample Response

Copied{
    "merge_report_data_url": "http://writer.zoho.com/writer/api/v1/merge/job/0tq5n465132106580437abe99b6f56f2b0c85/data",
    "merge_report_url": "http://writer.zoho.com/writer/v1/mailmerge/job/0tq5n465132106580437abe99b6f56f2b0c85",
    "records": [
        {
	    "name": "Amelia",
            "email": "amelia@zylker.com",
            "download_link": "{url}",
            "status": "inprogress"
        }
    ],
}
Copied{
    "merge_report_data_url": "http://writer.zoho.com/writer/api/v1/merge/job/fbsa6360a78f53f564dfa9b4a1e79febed569/data",
    "merge_report_url": "http://writer.zoho.com/writer/v1/mailmerge/job/fbsa6360a78f53f564dfa9b4a1e79febed569",
    "records": [
        {
            "InvoiceNo": "12345",
            "InvoiceDate": "27 May 2022",
            "InvoiceAmount": "$100",
            "download_link": "{url}",
            "status": "inprogress"
        }
    ],
}

Snippet 2 - Merge and Email with common attachments

Copiedmessage = "Hello \n Team"; 
fields = invokeurl 
[ 
url :"https://zohoapis.com/writer/api/v1/documents/eb4kob4cf6***61119eb9/fields" 
type :GET 
connection:"<connection_name>" 
]; 
data = Map(); 
data.put("InvoiceNo","12345"); 
data.put("InvoiceDate","27 May 2022"); 
data.put("InvoiceAmount","$100");
dataMap = map(); 
dataMap = {"data": data}; 
downloadFile = invokeurl 
[ 
url:"http://homepages.inf.ed.ac.uk/neilb/TestWordDoc.doc" 
type :GET 
]; 
commonAttachmentFile1 = invokeurl 
[ 
url :"<https://example.com/download/publicdocument>" 
type :GET 
]; 
commonAttachmentFile2 = invokeurl 
[ 
url :"<https://example.com/download/publicdocument>" 
type :GET 
]; 
downloadFile1.setParamName("common_attachments"); 
paramList = list(); 
paramMap1 = {"paramName":"common_attachments","content":commonAttachmentFile1}; 
paramMap8 = {"paramName":"common_attachments1","content":commonAttachmentFile2};
paramMap2 = {"paramName":"merge_data","content":dataMap.toString(),"stringPart":"true"};
paramMap3 = {"paramName":"subject","content":"Invoice data","stringPart":"true"}; 
paramMap4 = {"paramName":"message","content":"Reg Invoice \n Please find your invoice attached.","stringPart":"true"}; 
paramMap5 = {"paramName":"attachment_name","content":"attachment_name","stringPart":"true"};
paramMap6 = {"paramName":"output_format","content":"pdf","stringPart":"true"};
paramMap7 = {"paramName":"recipient_email","content":"amelia@gmail.com","stringPart":"true"};
 
paramList.add(paramMap1); 
paramList.add(paramMap2); 
paramList.add(paramMap3); 
paramList.add(paramMap4); 
paramList.add(paramMap5); 
paramList.add(paramMap6); 
paramList.add(paramMap7); 
paramList.add(paramMap8); 

merge = invokeurl 
[ 
url :"https://zohoapis.com/writer/api/v1/documents/eb4kob4cf6***61119eb9/merge/email" 
type :POST 
files:paramList 
connection:"<connection_name>" 
]; 
info merge;

Sample Response

Copied{
    "merge_report_data_url": "http://writer.zoho.com/writer/api/v1/merge/job/fbsa6360a78f53f564dfa9b4a1e79febed569/data",
    "merge_report_url": "http://writer.zoho.com/writer/v1/mailmerge/job/fbsa6360a78f53f564dfa9b4a1e79febed569",
    "records": [
        {
            "InvoiceNo": "12345",
            "InvoiceDate": "27 May 2022",
            "InvoiceAmount": "$100",
            "download_link": "{url}",
            "status": "inprogress"
        }
    ],
}

Snippet 3 - Merge and Email Task (Attachment Type)

Copieddata = {"data":{"InvoiceNo":"12345","InvoiceDate":"27 May 2022","InvoiceAmt":"$100"}};
mergedata = Map();
mergedata.put("merge_data", data);
mergedata.put("subject", "Invoice data");     
mergedata.put("message", "Please find your invoice in the attachment");    
zoho.writer.mergeAndSend("fbsa6360a78f53f564dfa9b4a1e79febed569", "docx", "amelia@zylker.com", mergedata, "<connection_name>");    //outputformat -> pdf/docx

Sample Response

Copied{
    "merge_report_data_url": "http://writer.zoho.com/writer/api/v1/merge/job/fbsa6360a78f53f564dfa9b4a1e79febed569/data",
    "merge_report_url": "http://writer.zoho.com/writer/v1/mailmerge/job/fbsa6360a78f53f564dfa9b4a1e79febed569",
    "records": [
        {
	    "InvoiceNo": "12345",
            "InvoiceDate": "27 May 2022",
            "InvoiceAmount": "$100",
            "download_link": "{url}",
            "status": "inprogress"
        }
    ],
}