Open file html in editor from API

Can I send an HTML file via API to open in the editor? If so, what would the structure be like?

I tried something similar to this, but it didn’t work.

<body>
  <iframe id="iframeEditor" src=""></iframe>
  <script>
   new DocsAPI.DocEditor("iframeEditor", {
    "document": {
     "fileType": "html",
     "key": key,
     "title": "Open html file",
     "url": "http://localhost/file.html"
    },
    "documentType": "html",
    "token": "...."
   });

   document.getElementById("iframeEditor").style.height = "800px";
  </script>
</body>

Hello, it is possible to set documentType property (ONLYOFFICE Api Documentation - Config) only to either “word”, “cell”, “slide” or “pdf” value. In your case you should set it to “word” value.

Hi DmitrieV, thanks for your response.
I’m trying this code, as per your guidance, informing the documentType as word.

The file was opened in the editor, but as if editing its code. I would like the html to be rendered, so I can edit and save it to docx.

See my Screenshot.

This my new code.

 <script>
  new DocsAPI.DocEditor("iframeEditor", {
   "document": {
    "fileType": "docx",
    "key": "",
    "title": "Example Document Title.docx",
    "url": "http://host/file.html"
   },
   "documentType": "word",
   "token": ""
  });

  document.getElementById("iframeEditor").style.height = "800px";
 </script>

Hello,
Please note that the file should contain html format markers according to specification, there are no tags can be seen such as <html>, <head>, <body>, etc. in your html document. You can refer to this html specification: HTML Standard

Hello DmitriiV, thank you very much, this was the problem. Now it’s working.

Hello Daniel,
You are welcome, great to know.

Hello, is it possible to send header and footer via API? I need to send html files to open in the editor but with a header and footer.

Hello,
There are the following API methods to add header (GetHeader - ONLYOFFICE Api Documentation) and footer (GetFooter - ONLYOFFICE Api Documentation) using API. If it is not what you need, please describe your scenario in more detail.

Do you mean that you’d like to open html files with and tags added within it and see the corresponding styling?

Hello DmitriiV, that’s exactly what I need.
(GetHeader - ONLYOFFICE Api Documentation)
However, looking at the documentation, it seems that I should use another type of API. Only through the “Document Builder”?

Can I do this by sending data through the Rest API?
As in the example sent in the first message on April 4th?

Hello, you’d have to send requests to Document Builder (Web Document Builder API - ONLYOFFICE Api Documentation) to use these API methods. Unfortunately, REST API option is not possible here

Tks DmitriiV, I’ll read the documentation.

1 Like