How to call Aspose API from plugin on initiation

Hi Team,

i have a requirement where i have to call Aspose API from plugincode.js or index.html file .How to call Aspose API from plugin on initiation and perform certain operations.

Hello @sanjeevareddy.nagire

We don’t have examples in documentation, but you can run any http-requests via plugin.

//window.Asc.plugin.executeMethod ("GetFileHTML", null, function (res) {
  //console.log (res);

//const apiUrl = '';
//const data = {
  //sessionID: '',
//attchmentType: 'FRM',
//docContent: 'Content' // update docContent with res
//};

//const requestOptions = {
  //method: 'POST',
    //   headers: {
      //   'Content-Type': 'application/json',
       //},
        //body: JSON.stringify(data),
		
    //mode: 'no-cors' // add this line
    //};

    //fetch(apiUrl, requestOptions)
      //.then(response => {
        //if (!response.ok) {
           //   throw new Error('Network response was not ok');
            //}
          //  return response.json();
        //})
        //.then(data => {
          //outputElement.textContent = JSON.stringify(data, null, 2);
        //})
        //.catch(error => {
          //  console.error('Error:', error);
        //});
//});

Above code is providing me reult from Postman. But from plugin.js i am facing error as “(Unsupported Media Type)” . REST API doesn’t have any content-type as input but whether i pass Content-Type as application/json or any other type or i completely remove Content-Type’: 'application/json below statement, i am getting “Unsupported MimeType” error. can you pelase advise.

  //   'Content-Type': 'application/json',

Plugins support all methods of browser JS, considering this you can try sending http request via plugin with ajax, for instance:

var settings = {
   "url": "https://documentserver/coauthoring/CommandService.ashx",
   "method": "POST",
   "timeout": 0,
   "headers": {
   "Content-Type": "application/json"
   },
   "data": JSON.stringify({
      "c": "info",
      "key": "testdrop89131",
      "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjIjoiaW5mbyIsImtleSI6InRlc3Rkcm9wODkxMzEifQ.Guok90i0YUApOhhBVufsg0rOi19_wRIV-cMGG5D5qB4"
   }),
};
$.ajax(settings).done(function (response) {
console.log(response);
});

This example demonstrates how to send a request to Command service with info type. I believe with certain tweaks it’d be useful for your use case.


If you face any other issues, I’d recommend contacting sales@onlyoffice.com to discuss possibilities for dedicated support as it is quite complicated task you are trying to accomplish.