Choose where you’d like to start

Merge and Invoke in Zoho Writer

Description

The zoho.writer.mergeAndInvoke task merges the document and invokes a custom function to perform further operations on it. This task is based on the Zoho Writer Merge and Invoke API.

Note: Applicable to all services except Zoho Creator.

Syntax

<response> = zoho.writer.mergeAndInvoke(<document_id>, <merge_detail>, <optional_settings>, <connection>)

where:

ParamsData typeDescription
<response>KEY-VALUEThe response returned by Zoho Writer. It represents the merged document's details, the output of the custom function invoked, and the merge status.
<document_id>TEXT

The ID of the document to be merged and on which the custom function should be invoked post-merge.

The document ID can be obtained from the URL of the document on which the custom function should be invoked post-merge.

The URL is formatted as follows:
https://writer.zoho.com/writer/open/<document_id>

<merge_detail>KEY-VALUE Specify how your input for the merge will be. It can be JSON, CSV file, or a URL.
<optional_settings>KEY-VALUEThe optional parameters you can send to merge and invoke custom functions according to your preference.
<connection>TEXT

The connection's link name.

Note:

  • To prevent new authtoken generation and ensure new integration tasks (created after the deadline specified in the post) work as expected, a Zoho OAuth connection with appropriate scopes is mandatory. Existing integration tasks will continue to work, with or without the connections parameter, until you manually delete the authtoken from Zoho Accounts.

  • Add relevant scopes from the Zoho Writer API when creating the connection.

  • Refer to this post for a list of Zoho services that support the Connections page.

  • Learn more about connections

You can provide the merge_detail parameter in any one of the below formats:

KeyValueDescription
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_urlURLProvide the required JSON URL in your API request body.

option_settings parameter values:

Parameter

Data Type

Description

output_settings

 

{

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

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

'merge_to': "<separatedoc/singledoc>,

'filename': "<new document name>"

}

Using this parameter, 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.

Note: If this key is not passed, the merged documents will be stored in Writer's format (ZDOC) 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 separatedoc and singledoc.

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 any one of the following ways;

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

For example, filename = NDA_Agreement

(OR)

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

For example, filename = NDA_Agreement <<ClientName>>

Maximum length allowed: 150

test_modeBoolean (true/false)

Using this parameter, 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 purposes.

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

Example

The following script merges a document and invokes a function.

document_id = "po5uobda049e029d44b13a9956f6d2cedc67b"; 

fields = Map(); 
fields.put("Name", "Ms.Amelia");
fields.put("Tamil", "S");
fields.put("English", "A");
fields.put("Maths", "A");
fields.put("Remark", "Good");
data_map = Map();
data_map.put("data", fields)
merge_details = Map();
merge_details.put("merge_data", data_map);

optional_settings= Map();
optional_settings.put("test_mode", "true");

response = zoho.writer.mergeAndInvoke(document_id, merge_details, optional_settings, "writer_oauth_connection");

info response;

Usecase

Scenario 1: Merge documents and add to records in CRM

Say you're generating a holiday greeting for your customers and would like to attach it to the CRM record in addition to sending it as an email. You merge the document and invoke a custom function that saves it as an attachment to the CRM record.

Trigger merge and invoke task from CRM using the code below:

document_id = "po5uobda049e029d44b13a9956f6d2cedc67b"; 

fields = Map(); 
fields.put("Name", "Ms.Zylker");
fields.put("Date", "20/12/2023");
fields.put("Place", "Chennai");
fields.put("id", "4356789132570"); // The id key is mandatory in your data source. Pass the CRM record's id to which the attachment needs to be added in this key. 

data_map = Map();
data_map.put("data", fields)
merge_details = Map();
merge_details.put("merge_data", data_map);

optional_settings= Map();
optional_settings.put("test_mode", "true");

response = zoho.writer.mergeAndInvoke(document_id, merge_details, optional_settings, "writer_oauth_connection");

info response;

 

In Writer, we have a gallery named AttachFile CRM in merge and invoke output actions to upload the merged document to the Attachments in the Zoho CRM record.

Configure the snippet and make sure that the changes mentioned in the comment are completed. Click Save & link a function.

Response format

{
    "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"
}

Related Links

Get Started Now

Execute