Execute Mail Merge online Executes Mail Merge operation.
Execute Mail Merge online REST API
Server
Method
Endpoint
https://api.aspose.cloud/v4.0
PUT
/words/MailMerge
You can use the following parameters in a REST request:
Parameter Name
Data Type
Required/Optional
Description
withRegions
boolean
Optional
The flag indicating whether to execute Mail Merge operation with regions.
cleanup
string
Optional
The cleanup options.
documentFileName
string
Optional
The filename of the output document, that will be used when the resulting document has a dynamic field {filename}. If it is not set, the “template” will be used instead.
Use $multipart/form-data
request to combine one or more properties into a single body:
Property Name
Data Type
Required/Optional
Description
Template
string(binary)
Required
File with template
Data
string(binary)
Required
File with mailmerge data
Options
FieldOptions
Optional
Field options
Note : to access this REST API, you need to register and get personal credentials. Use the ‘
Quick Start ’ guide to go through the procedure in a couple of minutes.
Execute Mail Merge online usage examples
Let’s look at practical examples of using the web service. You can do this both with cURL and Postman utilities, and from your code in various programming languages: Python, Java, JavaScript, C#, PHP, C++, Go, Ruby, Swift, Dart.
How to execute Mail Merge online with cURL or Postman
One of the easiest and fastest ways to call a REST API is to use cURL or Postman:
cURL Request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -v "https://api.aspose.cloud/v4.0/words/MailMerge" \
-X PUT \
-H "Content-Type: multipart/form-data" \
-H "Authorization: Bearer ####################" \
-F Template="@Sample.docx" \
-F Data="@@TestMailMergeData.xml" \
-F Options="{\"CurrentUser\":{\"Name\":\"SdkTestUser\"}}"
To get a JWT token use these instructions
Postman Request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{
"info": {
"name": "ExecuteMailMergeOnline",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"auth": {
"type": "oauth2",
"oauth2": [
{
"key": "clientSecret",
"value": "{{CLIENT_SECRET}}",
"type": "string"
},
{
"key": "clientId",
"value": "{{CLIENT_ID}}",
"type": "string"
},
{
"key": "addTokenTo",
"value": "header",
"type": "string"
},
{
"key": "client_authentication",
"value": "body",
"type": "string"
},
{
"key": "accessTokenUrl",
"value": "https://api.aspose.cloud/connect/token",
"type": "string"
},
{
"key": "grant_type",
"value": "client_credentials",
"type": "string"
},
{
"key": "tokenName",
"value": "Access Token",
"type": "string"
}
]
},
"item": [
{
"name": "mailMergeRequest",
"protocolProfileBehavior": {
"disableBodyPruning": true
},
"request": {
"method": "PUT",
"header": [
],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "Template",
"type": "file",
"src": "Sample.docx"
},
{
"key": "Data",
"type": "file",
"src": "TestMailMergeData.xml"
},
{
"key": "Options",
"type": "text",
"value": "{\"CurrentUser\":{\"Name\":\"SdkTestUser\"}}"
}
]
},
"url": {
"raw": "https://api.aspose.cloud/v4.0/words/MailMerge",
"protocol": "https",
"host": [
"api",
"aspose",
"cloud"
],
"path": [
"v4.0",
"words",
"MailMerge"
],
"query": [
]
}
},
"response": []
}
],
"variable": [
]
}
To get a JWT token use these instructions
How to execute Mail Merge online in Python, Java, C#, C++, JavaScript and other programming languages
Using SDK is the quickest way to speed up the development. Please take a look at the provided code examples to quickly call this web service from your favourite programming language:
Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os
import asposewordscloud
import asposewordscloud.models.requests
from asposewordscloud.rest import ApiException
from shutil import copyfile
words_api = WordsApi(client_id = '####-####-####-####-####', client_secret = '##################')
request_template = open('Sample.docx', 'rb')
request_data = open(open(os.path.join(self.local_test_folder, 'TestMailMergeData.xml')).read(), 'rb')
request_options_current_user = asposewordscloud.UserInformation(name='SdkTestUser')
request_options = asposewordscloud.FieldOptions(current_user=request_options_current_user)
mail_merge_request = asposewordscloud.models.requests.ExecuteMailMergeOnlineRequest(template=request_template, data=request_data, options=request_options)
words_api.execute_mail_merge_online(mail_merge_request)
Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.aspose.words.cloud.*;
import com.aspose.words.cloud.api.*;
import com.aspose.words.cloud.model.*;
import com.aspose.words.cloud.model.requests.*;
import com.aspose.words.cloud.model.responses.*;
import java.nio.file.Files;
import java.nio.file.Paths;
ApiClient apiClient = new ApiClient(/*clientId*/ "####-####-####-####-####", /*clientSecret*/ "##################", null);
WordsApi wordsApi = new WordsApi(apiClient);
byte[] requestTemplate = Files.readAllBytes(Paths.get("Sample.docx").toAbsolutePath());
byte[] requestData = Files.readAllBytes(Paths.get(new String(Files.readAllBytes(Paths.get(TestInitializer.LocalTestFolder, "TestMailMergeData.xml")), "utf8")).toAbsolutePath());
UserInformation requestOptionsCurrentUser = new UserInformation();
requestOptionsCurrentUser.setName("SdkTestUser");
FieldOptions requestOptions = new FieldOptions();
requestOptions.setCurrentUser(requestOptionsCurrentUser);
ExecuteMailMergeOnlineRequest mailMergeRequest = new ExecuteMailMergeOnlineRequest(requestTemplate, requestData, requestOptions, null, null, null);
wordsApi.executeMailMergeOnline(mailMergeRequest);
Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as fs from "fs";
const clientId = "####-####-####-####-####";
const secret = "##################";
const wordsApi = new WordsApi(clientId, secret);
const requestTemplate = fs.createReadStream("Sample.docx");
const requestData = fs.createReadStream(fs.readFileSync(BaseTest.localBaseTestDataFolder + "TestMailMergeData.xml", 'utf8'));
const requestOptionsCurrentUser = new model.UserInformation({
name: "SdkTestUser"
})
const requestOptions = new model.FieldOptions({
currentUser: requestOptionsCurrentUser
})
const mailMergeRequest = new model.ExecuteMailMergeOnlineRequest({
template: requestTemplate,
data: requestData,
options: requestOptions
});
wordsApi.executeMailMergeOnline(mailMergeRequest)
.then((mailMergeRequestResult) => {
// tslint:disable-next-line:no-console
console.log("Result of mailMergeRequest: ", mailMergeRequestResult);
});
C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Aspose.Words.Cloud.Sdk;
using Aspose.Words.Cloud.Sdk.Model;
using Aspose.Words.Cloud.Sdk.Model.Requests;
var config = new Configuration { ClientId = "####-####-####-####-####", ClientSecret = "##################" };
var wordsApi = new WordsApi(config);
using var requestTemplate = File.OpenRead("Sample.docx");
using var requestData = File.OpenRead(File.ReadAllText(LocalTestDataFolder + "TestMailMergeData.xml"));
var requestOptionsCurrentUser = new UserInformation()
{
Name = "SdkTestUser"
};
var requestOptions = new FieldOptions()
{
CurrentUser = requestOptionsCurrentUser
};
var mailMergeRequest = new ExecuteMailMergeOnlineRequest(requestTemplate, requestData, options: requestOptions);
await wordsApi.ExecuteMailMergeOnline(mailMergeRequest);
PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php
use Aspose\Words\WordsApi;
use Aspose\Words\Model\Requests\{ExecuteMailMergeOnlineRequest};
use Aspose\Words\Model\{FieldOptions, UserInformation};
$clientId = '####-####-####-####-####';
$secret = '##################';
$wordsApi = new WordsApi($clientId, $secret);
$requestTemplate = "Sample.docx";
$requestData = file_get_contents(realpath(__DIR__ . '/../../..') . "/TestData/" . "TestMailMergeData.xml");
$requestOptionsCurrentUser = new UserInformation(array(
"name" => "SdkTestUser",));
$requestOptions = new FieldOptions(array(
"current_user" => $requestOptionsCurrentUser,));
$mailMergeRequest = new ExecuteMailMergeOnlineRequest(
$requestTemplate, $requestData, $requestOptions, NULL, NULL, NULL);
$wordsApi->executeMailMergeOnline($mailMergeRequest);
C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "aspose_words_cloud.h"
using namespace aspose::words::cloud;
auto config = std::make_shared<ApiConfiguration>(/*clientId*/ L"####-####-####-####-####", /*clientSecret*/ L"##################");
auto wordsApi = std::make_shared<WordsApi>(config);
auto requestTemplate = std::shared_ptr<std::istream>(new std::ifstream(std::filesystem::path(L"Sample.docx"), std::istream::binary));
auto requestData = std::shared_ptr<std::istream>(new std::ifstream(std::filesystem::path(getFileTextUtf16(localTestDataFolder + L"/" + L"TestMailMergeData.xml")), std::istream::binary));
auto requestOptionsCurrentUser = std::make_shared<aspose::words::cloud::models::UserInformation>();
requestOptionsCurrentUser->setName(std::make_shared<std::wstring>(L"SdkTestUser"));
auto requestOptions = std::make_shared<aspose::words::cloud::models::FieldOptions>();
requestOptions->setCurrentUser(requestOptionsCurrentUser);
std::shared_ptr<requests::ExecuteMailMergeOnlineRequest> mailMergeRequest(
new requests::ExecuteMailMergeOnlineRequest(
requestTemplate, requestData, requestOptions));
wordsApi->executeMailMergeOnline(mailMergeRequest);
Go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{
"ClientId" : " ####-####-####-####-####" ,
"ClientSecret" : " ##################" ,
"BaseUrl" : " https://api.aspose.cloud"
}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import (
"os"
"github.com/aspose-words-cloud/aspose-words-cloud-go/dev/api/models")
config, _ := models.NewConfiguration("config.json")
wordsApi, ctx, _ := api.CreateWordsApi(config)
requestTemplate, _ := os.Open("Sample.docx")
requestData, _ := os.Open(ReadFile(t, "TestMailMergeData.xml"))
requestOptionsCurrentUser := models.UserInformation{
Name: ToStringPointer("SdkTestUser"),
}
requestOptions := models.FieldOptions{
CurrentUser: &requestOptionsCurrentUser,
}
mailMergeRequestOptions := map[string]interface{}{"options": &requestOptions,}
mailMergeRequest := &models.ExecuteMailMergeOnlineRequest{
Template: requestTemplate,
Data: requestData,
Optionals: mailMergeRequestOptions,
}
_, _ = wordsApi.ExecuteMailMergeOnline(ctx, mailMergeRequest)
Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'aspose_words_cloud'
AsposeWordsCloud.configure do |config|
config.client_data['ClientId'] = '####-####-####-####-####'
config.client_data['ClientSecret'] = '##################'
end
@words_api = WordsAPI.new
request_template = File.open('Sample.docx')
request_data = File.open(File.read(File.join(local_test_folder, 'TestMailMergeData.xml')))
request_options_current_user = UserInformation.new({:Name => 'SdkTestUser'})
request_options = FieldOptions.new({:CurrentUser => request_options_current_user})
mail_merge_request = ExecuteMailMergeOnlineRequest.new(template: request_template, data: request_data, options: request_options)
@words_api.execute_mail_merge_online(mail_merge_request)
Swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AsposeWordsCloud
let config = Configuration(clientId: "####-####-####-####-####", clientSecret: "##################");
let api = try WordsAPI(configuration: config);
let requestTemplate = InputStream(url: URL(string: "Sample.docx"))!;
let requestData = InputStream(url: URL(string: try String(contentsOf: self.getLocalTestDataFolder().appendingPathComponent("TestMailMergeData.xml", isDirectory: false))))!;
let requestOptionsCurrentUser = UserInformation()
.setName(name: "SdkTestUser");
let requestOptions = FieldOptions()
.setCurrentUser(currentUser: requestOptionsCurrentUser);
let mailMergeRequest = ExecuteMailMergeOnlineRequest(template: requestTemplate, data: requestData, options: requestOptions);
_ = try api.executeMailMergeOnline(request: mailMergeRequest);
Dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:io';
import 'package:aspose_words_cloud/aspose_words_cloud.dart';
final clientId = "####-####-####-####-####";
final clientSecret = "##################";
final config = Configuration(clientId, clientSecret);
final wordsApi = WordsApi(config);
final requestTemplate = (await File('Sample.docx').readAsBytes()).buffer.asByteData();
final requestData = (await File(await context.loadTextFile('TestMailMergeData.xml')).readAsBytes()).buffer.asByteData();
final requestOptionsCurrentUser = UserInformation();
requestOptionsCurrentUser.name = 'SdkTestUser';
final requestOptions = FieldOptions();
requestOptions.currentUser = requestOptionsCurrentUser;
final mailMergeRequest = ExecuteMailMergeOnlineRequest(requestTemplate, requestData, options: requestOptions);
await wordsApi.executeMailMergeOnline(mailMergeRequest);
See Also
GitHub repository — explore Aspose.Words Cloud SDK Family. These software libraries take care of all low-level document-processing details.