Hello,
I’m trying to remove unused merge fields using your simple merge API (no regions, not mustache), but even when I use all the cleanup parameters at once, the unused fields are never removed.
I think it may be because I am using <<next_record>>, as in a page of labels.
I also tried using mailMergeFieldNames with DELETE, but I get a 405 METHOD NOT ALLOWED error. The same call with GET gives me the expected result described in the docs, but obviously does not solve my problem.
I have attached my word template and some XML.
Here is the call I make to start the merge with cleanup params:
POST https://api.aspose.com/v1.1/words/labels.docx/executeMailMerge?appSID=xxxx&folder=myfolder&cleanup=ContainingFields,EmptyParagraphs,UnusedFields,UnusedRegions&signature=yyyy
Here is the call I make to try to remove the merge fields after the fact when cleanup doesn’t do anything
DELETE https://api.aspose.com/v1.1/words/labels.74caa718-12bb-4670-ba88-6c4cd212d679.docx/mailMergeFieldNames?appSID=xxxx&folder=myfolder&signature=yyyy
Thank you so much for any help you can provide,
Nathan
Hi Nathan,
Thanks for your inquiry.
I have tested the scenario and have managed to reproduce the same issue at my side. For the sake of correction, I have logged this problem in our issue tracking system as SAASWORDS-126. I have linked this forum thread to the same issue and you will be notified via this forum thread once this issue is resolved.
We apologize for your inconvenience.
The issues you have found earlier (filed as SAASWORDS-126) have been fixed in this update.
This message was posted using Notification2Forum from Downloads module by Aspose Notifier.
@NathanStults
Kindly note since API Version V4.0, there are several breaking changes introduced in Aspose.Words Cloud. Along with other changes, please note MailMerge APIs are simplified. Now Mail Merge fields and Mustache template APIs are combined. So a single API can be used for both types of templates.
In the new API, versions we have changed PUT to POST (and vice versa). From now on, all idempotent methods are PUT and non-idempotent ones are POST. So MailMerge API methods are changed to PUT now.
If you need to use the Aspose Words API to remove unused fields during a mail merge, make sure to include the correct parameters in the URL. Here’s the key code snippet that worked for me:
var mailMergeUrl = 'https://api.aspose.cloud/v4.0/words/' + encodeURIComponent(templateName) + '/mailMerge?withregions=false&cleanup=UnusedFields,UnusedStyles,ContainingFields,EmptyParagraphs';
This URL ensures that unused fields and styles are cleaned up during the mail merge process. Here’s how you can use it in your code:
function callAsposeAPI() {
try {
// Your other code here...
var templateName = 'YourTemplateName.docx';
var clientId = 'YourClientID';
var clientSecret = 'YourClientSecret';
var tokenUrl = 'https://api.aspose.cloud/connect/token';
var tokenOptions = {
'method': 'POST',
'contentType': 'application/x-www-form-urlencoded',
'payload': {
'grant_type': 'client_credentials',
'client_id': clientId,
'client_secret': clientSecret
}
};
var tokenResponse = UrlFetchApp.fetch(tokenUrl, tokenOptions);
var token = JSON.parse(tokenResponse.getContentText()).access_token;
Logger.log("Token obtained: " + token);
var mailMergeUrl = 'https://api.aspose.cloud/v4.0/words/' + encodeURIComponent(templateName) + '/mailMerge?withregions=false&cleanup=UnusedFields,UnusedStyles,ContainingFields,EmptyParagraphs';
var mailMergeOptions = {
'method': 'PUT',
'contentType': 'application/json',
'headers': {
'Authorization': 'Bearer ' + token
},
'payload': JSON.stringify({
'Data': yourData
})
};
var mailMergeResponse = UrlFetchApp.fetch(mailMergeUrl, mailMergeOptions);
Logger.log("Mail merge response code: " + mailMergeResponse.getResponseCode());
var mailMergeResult = JSON.parse(mailMergeResponse.getContentText());
Logger.log("Mail merge response content: " + JSON.stringify(mailMergeResult));
// Your download and file handling code here...
} catch (error) {
Logger.log("Error: " + error.toString());
}
}
Make sure to replace 'YourTemplateName.docx'
, 'YourClientID'
, 'YourClientSecret'
, and yourData
with your actual template name, client ID, client secret, and data. This setup ensures that the mail merge process will clean up any unused fields and styles as needed.