Merge and Invoke

Purpose

Using this API, you will be able to execute/invoke the custom function configured in the template and merge it.

HTTP Request URL

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

Path Parameters

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

Body Parameters

ParameterData TypeDescription
Mandatory Parameters
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
output_settings

'format':"<pdf/docx/pdfform>",

'password': "<*****>",    

'merge_to': "<separatedoc/singledoc>,

'filename': "<new document name>"

}

 

Using this param, you will be able to specify the following;

format -> Specify a format in which you would like to store the merged document. Supported formats are pdf, pdfform and docx.

If this key is not passed, the merged documents will get stored in Writer format (pdf) by default.

password -> Specify a password if you would like to protect the merged document.

Supported formats are pdf, pdfform and docx.

merge_to -> Supported merge types are separatedocand singledoc.Specify in which type you would like to merge the document.

separatedoc - If you would like to merge each record as a separate document.

singledoc- If you would like to merge all the records as a single document.

filename -> Specify a unique name for the merged document. This can be achieved using anyone of the following ways;

1. You can pass it has a normal string value.

For example: filename=NDA_Agreement

(OR)

2. You can also customise the filename by passing the merge field id.

For example: filename=NDA_Agreement <<ClientName>>

Maximum length allowed: 150

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:

  • To use this API, an OAuth token should be generated with the following scopes ZohoWriter.documentEditor.ALL and ZohoWriter.merge.ALL 
  • 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.

Sample Request


				curl --location --request POST "https://zohoapis.com/writer/api/v1/documents/ca6nf5c638e0e9cd242e2b2c46bb8cacc965a/merge/execute" \
--header "Authorization: Zoho-oauthtoken xxx.yyy.zzz" \
--form "output_settings={\"format\":\"pdfform\", \"password\":\"*****\", \"merge_to\":\"singledoc\", \"filename\":\"New document\"}" \
--form "merge_data={\"data\":[{\"name\":\"Amelia\",\"email\":\"amelia@zylker.com\"}]}"			

Sample Response


				{
    "merge_report_data_url": "https://writer.zoho.com/writer/api/v1/merge/job/ba9cb8b6d826e05e26fd03c391dc4baa674281f9895988caf8420630887b5902/data",
    "merge_report_url": "https://writer.zoho.com/writer/v1/mailmerge/job/ba9cb8b6d826e05e26fd03c391dc4baa674281f9895988caf8420630887b5902",
    "records": [
        {
            "download_link": "{url}",
            "status": "inprogress"
        }
   ],
    "status": "inprogress"
}			

Sample Snippet


				document_id = "fbsa6360a78f53f564dfa9b4a1e79febed567";
fieldInfo =  invokeurl
[
url: "https://zohoapis.com/writer/api/v1/documents/fbsa6360a78f53f564dfa9b4a1e79febed567/fields"
type: GET
connection:"<connection_name>"
];
fieldsList =  fieldInfo.get("fields");
datamap = map();
for each field in fieldsList
{
 info field;
}	
datamap.put("Name", "Ms.Amelia");
datamap.put("Tamil", "S");
datamap.put("English", "A");
datamap.put("Maths", "A");
datamap.put("Remark", "Good");
output_settings = Map();
outputsettings.put("filename","Student Grade");
outputsettings.put("format","pdf");     //<docx/pdfform/pdf>  //optional
outputsettings.put("password","*****");    	//optional
outputsettings.put("merge_to","separatedoc");     //<separatedoc/singledoc>  //optional
param = map();
param.put("merge_data",{"data":datamap});
param.put("output_settings",outputsettings);
response = invokeurl
[
url: "https://zohoapis.com/writer/api/v1/documents/fbsa6360a78f53f564dfa9b4a1e79febed567/merge/execute"
type: POST
parameters: param
connection:"<connection_name>"
];			

Sample Response


				{
    "merge_report_data_url": "https://writer.zoho.com/writer/api/v1/merge/job/ba9cb8b6d826e05e26fd03c391dc4baa674281f9895988caf8420630887b5902/data",
    "merge_report_url": "https://writer.zoho.com/writer/v1/mailmerge/job/ba9cb8b6d826e05e26fd03c391dc4baa674281f9895988caf8420630887b5902",
    "records": [
        {
            "download_link": "{url}",
            "status": "inprogress"
        }
   ],
    "status": "inprogress"
}