The Mail Merge is the easiest way to generate a set of documents that are identical except for certain information i.e. name and address of the recipient. Many organizations communicate with their customers/members by means of letters, newsletters, and promotional pieces using mail merge, so in this article, we are going to discuss the details on how to Mail Merge Word documents using C# REST API.
Mail Merge API
Aspose.Words Cloud offers the capabilities to create a new Word document, open an existing document or convert it to PDF, XPS, SVG, EPUB, and various other formats. As our API is developed as per REST architecture, so you do not need to worry about language or platform limitations. Now in order to use the API in C# .NET application, please install Aspose.Words Cloud SDK for .NET using the following command:
After the installation, we need to register a free account over Aspose.Cloud dashboard using GitHub or Google account or simply Sign Up and obtain your Client Credentials.
Populate Mail Merge template in C#
Please follow the steps given below to populate the Mail Merge template using a data file.
Mail Merge Word using cURL Command
The cURL commands are also a convenient way of accessing REST APIs. Since Aspose.Words Cloud is developed on top of REST API architecture, so we can easily access the APIs via the cURL commands. Now, as a pre-requisite, we need to generate a JWT access token based on Client ID and Client Secret details.
curl -v "https://api.aspose.cloud/connect/token" \ -X POST \ -d "grant_type=client_credentials&client_id=c235e685-1aab-4cda-a95b-54afd63eb87f&client_secret=b8da4ee37494f2ef8da3c727f3a0acb9" \ -H "Content-Type: application/x-www-form-urlencoded" \ -H "Accept: application/json"
For further details, please visit How to Obtain JWT token using a Client ID and Client Secret key.
Once we have the JWT access token, we can use the following cURL command to populate the Mail Merge template. We load the data from a text file.
- The ExecuteMailMerge API performs the main operation
- SampleMailMergeTemplate.docx is the input mail merge template available on the cloud storage
- We use the -F parameter is upload input data from SampleMailMergeTemplateData.txt file
- The resultant file given against the destFileName parameter will store on cloud storage
curl -v "https://api.aspose.cloud/v4.0/words/SampleMailMergeTemplate.docx/MailMerge?withRegions=false&destFileName=TestPostDocumentExecuteMailMerge.docx" \ -X PUT \ -F data=@/Downloads/SampleMailMergeTemplateData.txt \ -H "Content-Type: multipart/form-data" \ -H "Accept: application/json" \ -H "Authorization: Bearer <jwt token>"
The sample files from the above example are available on the following links
In this article, we have discussed the details on how to perform Mail Merge in Word documents using a C# code snippet. At the same time, we have also learned mail merge steps using cURL commands. Please note that our SDK is built according to the MIT license, so its complete source code is available for download over the GitHub repository. We suggest you explore the Product documentation and learn about other exciting features supported by the API.
We also recommend visiting the following links to learn more about