Mail Merge Microsoft Word Document from JAVA using Aspose.Words REST API 403 error

I am having problem in clouds words api

in cleanup parameter

cleanup=UnusedRegions,UnusedFields

this is giving 403 error

http://api.aspose.com/v1.1/words/modern.doc/executeTemplate?cleanup=UnusedRegions%2CUnusedFields......

This message was posted using Email2Forum by Tahir Manzoor.

Hi Shridhar,

Thanks for your inquiry. I suggest you please read the following documentation link for your kind reference.

The cleanup parameter should be separated by “,”.

http://api.aspose.cloud/v1.1/words/modern.doc/executeTemplate?cleanup=**ContainingFields,UnusedFields**

Please make sure that you have generated the request URL correctly.

If you still face problem, please share your document along with XML data here for testing. I will investigate the issue and provide you more information.

hi thanks for quick replay. But I am still facing problem. I am posting my java code and xml data here.

private static void restMerge() throws Exception
{
String appSID = APP_SID;
String appKey = APP_KEY;
String fileName = “modern.doc”;
String outputPath = “C:\Users\Shridhar\Desktop\ResumeBulder\testMergeOutputLatest.doc”;

//Use the following line to use API version 1.1
//ContainingFields,UnusedRegions

String strURI = “http://api.aspose.com/v1.1/words/” + fileName +
“/executeTemplate?cleanup=ContainingFields,UnusedRegions&filename=myOutputFile.doc”;

//sign URI
String signedURI = Utils.Sign(strURI, appKey, appSID);


String strXML = FileUtils.readFileToString(new
File(“C:\Users\Shridhar\Desktop\ResumeBulder\resumeDataset.xml”));
InputStream responseStream = Utils.ProcessCommand(signedURI, “POST”, strXML, “xml”);
String strJSON = Utils.StreamToString(responseStream);
System.out.println("json: " + strJSON);
InputSource source = new InputSource(new StringReader(strJSON));

//Parse the input document
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
javax.xml.parsers.DocumentBuilder builder = factory.newDocumentBuilder();
org.w3c.dom.Document doc = builder.parse(source);
NodeList nodes = doc.getElementsByTagName(“FileName”);
String DocName = nodes.item( 0 ).getChildNodes().item(0).getNodeValue();
System.out.println("DocName: " + DocName);
//build URI
strURI = “http://api.aspose.com/v1.1/words/” + DocName + “?format=doc”;
//sign URI
signedURI = Utils.Sign(strURI, appKey, appSID);
//get response stream
responseStream = Utils.ProcessCommand(signedURI, “GET”);
Folder.SaveStreamToFile(outputPath, responseStream);
responseStream.close();
}
<?xml version="1.0" encoding="utf-8"?>



23
Nelson Street
Howick
Auckland

543 1234
03/01/2010
14.00

BBQ Chicken Pizza
6.00
1
6.00


1.5 Litre Coke
4.00
2
8.00




10
Parkville Avenue
Pakuranga
Auckland

548 7342
05/03/2010
6.00

Hawaiian Pizza
4.00
1
4.00


Fries
1.00
2
2.00

Shridhar

Hi Shridhar,


Thanks for sharing the detail. Could you please also send your App SID and Key to me by private message to analyze this issue?

Hi Shridhar,


Thanks for sharing the detail. I have tested the scenario and have found that you are using URL-encoding for comma (,) which is %2C. The cleanup parameter should be separated by “,”. Please use comma (,) instead of %2C.

Please let us know if you have any more queries.

Hi Shridhar,

Shridhar1:

… … …

//build URI

strURI = “http://api.aspose.com/v1.1/words/” + DocName + “?format=doc”;

Further to my last post, I have noticed that you are using ‘convert’ Resource to download the output document. If you do not want to convert the ‘myOutputFile.doc’, please do not use ‘convert’ Resource. I suggest you please use the code shared here to download a particular file from the Aspose cloud Storage.

Hi Shridhar,

Thanks for your inquiry via email.

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 SAWEB-39. We will update you via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Any update on this??

Hi Shridhar,

Thanks for your inquiry. I would like to share with you that issues are addressed and resolved based on first come first serve basis. Currently, your issues is pending for analysis and is in the queue. We will update you via this forum thread once there is any update available on your issue.

Thank you for your patience.

Hi Shridhar,

Thanks for your patience.

We have fixed the SAWEB-39 and have updated the Java SDK of Aspose Cloud. Please download the SDK from here and let us know how it goes on your side. Hope this helps you.

Thanks for fixing this. Its working fine now.

@apirisesmart

We would like to update you that in the latest API Version V4.0 we have combined Mail Merge and Mustache Template APIs. Now a single ExecuteMailMerge API Method is used to mail merge from cloud storage. Furthermore, we have introduced Storage API methods in Aspose.Words Cloud API, so no need to use Aspose.Storage Cloud API anymore.

WordsApi wordsApi = new WordsApi(new ApiClient());
ApiClient client = wordsApi.getApiClient();
// Get App Key and App SID from https://dashboard.aspose.cloud/
client.setAppKey("xxxxxxxxxxxxxxxxxxxxxxx").setAppSid("xxxx-xxxx-xxxx-xxxx-xxxxxxxxx");

try {
	
	    String localDocumentFile = "C:/Temp/TestFile XML.doc";
        String remoteFileName = "TestExecuteMailMerge.doc";
        String remoteDataFolder="Temp";
        
        String localDataFile = new String(Files.readAllBytes(Paths.get("C:/Temp/Customers.xml")), "utf8");
        
	//Upload file to storage
	UploadFileRequest uploadRequest = new UploadFileRequest(
                Files.readAllBytes(Paths.get(localDocumentFile).toAbsolutePath()),
                remoteDataFolder + "/" + remoteFileName,
                null
            );

        FilesUploadResult uploadResult = wordsApi.uploadFile(uploadRequest);
	
	    //MailMerge from stroage
        ExecuteMailMergeRequest request = new ExecuteMailMergeRequest(
            remoteFileName,
            localDataFile,
            remoteDataFolder,
            null,
            null,
            null,
            false,
            null,
            null,
            null,
            remoteDataFolder + "/" + remoteFileName
        );

        DocumentResponse result = wordsApi.executeMailMerge(request);
        
        System.out.println(result);	
	
} catch (Exception e) {
	System.out.println(e.getMessage());
}