Compare Two Word Documents for Differences Throws ErrorInvalidInputData in cURL

Hi, I’m trying to compare two word documents following the instructions from Compare two documents|Documentation but the API response code is always “ErrorInvalidInputData” with message: “Can not deserialize string”.

The same message is given by cURL and Postman methods.

This is the cURL call:

curl -v "https://api.aspose.cloud/v4.0/words/online/put/compareDocument?destFileName=CompareDocumentOut.doc" \
     -X PUT \
     -H "Content-Type: multipart/form-data" \
     -H "Authorization: Bearer ####################" \
     -F Document="@compareTestDoc1.doc" \
     -F ComparingDocument="@compareTestDoc2.doc"

Of course, I’m adding my local files and auth token.

The response is something like:

“Error”: {
“Code”: “ErrorInvalidInputData”,
“Message”: “Can not deserialize string 'PK\b��MVKUV��=\u000b_rels/.rels��MKA\f���C��l+�Hw{�7���Lvwh�L���DхR=�͛�����慥�;X5-�69�����e����#Ik�L>Sob�Rͷ��N�4)s��!I �����hd\\��5�O�3�ٹd�V�o�����J���&”,
“Description”: “Operation Failed. The input data is not valid.”
},
“RequestId”: “Root=1-63ead03b-7f7ca04b31efc3c043a34e96”
}

@ecwebdox

Please note that the CompareDocumentOnline API expects the compareData parameter, so it throws the error. Please see the cURL command below to compare two Word documents for differences for reference.

curl -X PUT "https://api.aspose.cloud/v4.0/words/online/put/compareDocument" 
-H "accept: multipart/mixed" 
-H "Authorization: Bearer eyJhbG.....yREyNY2FlxA" 
-H "Content-Type: multipart/form-data" 
-F document="@C:/Temp/compareTestDoc1.doc" 
-F compareData="{ "Author": "string", "CompareOptions": { "IgnoreCaseChanges": true, "IgnoreTables": true, "IgnoreFields": true, "IgnoreFootnotes": true, "IgnoreComments": true, "IgnoreTextboxes": true, "IgnoreFormatting": true, "IgnoreHeadersAndFooters": true, "Target": "Current", "AcceptAllRevisionsBeforeComparison": true }, "ResultDocumentFormat": "doc"}" 
-F comparingDocument="C:/Temp/compareTestDoc2.doc"

Thanks @tilal.ahmad, how can I download the resulting document? I’m testing the API through Postman.

@ecwebdox

Please note the compareDocument API response is multipart, so you need to parse the response to save the output. You can save the output file from the response to a local file in C# as follows. However, for postman, please Google for details.

WordsApi wordsApi = new WordsApi(ClientId, ClientSecret);
string localName1 = "C:/Temp/compareTestDoc1.doc";
string localName2 = "C:/Temp/compareTestDoc2.doc";                                 

var requestDocument = File.OpenRead(localName1);
var requestCompareData = new CompareData()
{
    Author = "author",                
    DateTime = new System.DateTime(2015, 10, 26, 0, 0, 0)
};
var requestComparingDocument = File.OpenRead(localName2);
var request = new CompareDocumentOnlineRequest(
    document: requestDocument,
    compareData: requestCompareData,
    comparingDocument: requestComparingDocument
);
var actual = await wordsApi.CompareDocumentOnline(request);
var fileStream = System.IO.File.Create(@"C:/Temp/compout.doc");
actual.Document.First().Value.CopyTo(fileStream);
fileStream.Close();