'Problem while trying to edit a Word document using a REST API in Node.js

I'm trying to edit a word document using a REST API in Node.js .

Here's the code :

// api initialization
let editApi = groupdocs_editor_cloud.EditApi.fromKeys(clientId, clientSecret);
let fileApi = groupdocs_editor_cloud.FileApi.fromKeys(clientId, clientSecret);

// input file      
let fileInfo = new groupdocs_editor_cloud.FileInfo();
fileInfo.filePath = "Sample.docx";

// define load options
let loadOptions = new groupdocs_editor_cloud.WordProcessingLoadOptions();
loadOptions.fileInfo = fileInfo;
loadOptions.outputPath = "output";

// create load request
let loadRequest = new groupdocs_editor_cloud.LoadRequest(loadOptions);
let loadResult = await editApi.load(loadRequest);

// download html document
let downloadRequest = new groupdocs_editor_cloud.DownloadFileRequest(loadResult.htmlPath);
let buf = await fileApi.downloadFile(downloadRequest);
let htmlString = buf.toString("utf-8");

// edit something...
htmlString = htmlString.replace("Title of the document", "Welcome");
htmlString = htmlString.replace("Subtitle #1", "Hello world");

// upload html back to storage
let uploadRequest = new groupdocs_editor_cloud.UploadFileRequest(loadResult.htmlPath, new Buffer.from(htmlString, "utf-8"));
await fileApi.uploadFile(uploadRequest);

// save html back to docx
let saveOptions = new groupdocs_editor_cloud.WordProcessingSaveOptions();
saveOptions.fileInfo = fileInfo;
saveOptions.outputPath = "output/edited.docx";
saveOptions.htmlPath = loadResult.htmlPath;
saveOptions.resourcesPath = loadResult.resourcesPath;

// create save request
let saveRequest = new groupdocs_editor_cloud.SaveRequest(saveOptions);
let saveResult = await editApi.save(saveRequest);
console.log("Document edited: " + saveResult.path);

I am getting the below error when trying to execute this code :

Error: Required parameter "requestObj.path" was null or undefined when calling downloadFile.
       at FileApi.<anonymous> (C:\Users\souha.hayouni\Documents\Test-auto-IMPRESS\impress_front_automation\node_modules\groupdocs-editor-cloud\lib\editor_api.js:226:23)
       at Generator.next (<anonymous>)
       at C:\Users\souha.hayouni\Documents\Test-auto-IMPRESS\impress_front_automation\node_modules\groupdocs-editor-cloud\lib\editor_api.js:30:71
       at new Promise (<anonymous>)
       at __awaiter (C:\Users\souha.hayouni\Documents\Test-auto-IMPRESS\impress_front_automation\node_modules\groupdocs-editor-cloud\lib\editor_api.js:26:12)
       at FileApi.downloadFile (C:\Users\souha.hayouni\Documents\Test-auto-IMPRESS\impress_front_automation\node_modules\groupdocs-editor-cloud\lib\editor_api.js:217:16)
       at modifyFile (C:\Users\souha.hayouni\Documents\Test-auto-IMPRESS\impress_front_automation\features\Impress_stories\Download_generated_reports\Download_generated_reports.js:738:20)
       at World.<anonymous> (C:\Users\souha.hayouni\Documents\Test-auto-IMPRESS\impress_front_automation\features\Impress_stories\Download_generated_reports\Download_generated_reports.js:525:9)
       at World.<anonymous> (C:\Users\souha.hayouni\Documents\Test-auto-IMPRESS\impress_front_automation\features\support\_index.js:20:29)
       at World.arity0 (eval at module.exports (C:\Users\souha.hayouni\Documents\Test-auto-IMPRESS\impress_front_automation\node_modules\util-arity\arity.js:22:24), <anonymous>:3:39)

Source Code : https://blog.groupdocs.cloud/2021/07/28/edit-word-documents-using-rest-api-in-node.js/#:~:text=Document%20Editor%20REST%20API%20and%20Node.,-js%20SDK&text=js%20SDK%20of%20GroupDocs.,%2C%20TXT%2C%20HTML%2C%20XML.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source