Web Document Builder API

For the interaction with the web document builder service the POST requests are used. The request parameters are entered in JSON format in the request body. The requests are sent to the https://documentserver/docbuilder address where documentserver is the name of the server with the ONLYOFFICE Document Server installed.

Parameters and their description:

ParameterDescriptionTypePresence
asyncDefines the type of the request to the document builder service: asynchronous or not.
Supported values:
  • true
  • false
When the asynchronous request type is used, the response is formed instantly. In this case to get the result it is necessary to send requests without parameter change until the document generation is finished. The default value is false.
booleanoptional
keyDefines the request identifier used to unambiguously identify the request. The key is formed on the document builder service side and is returned as the response to the first request. When the asynchronous request is used (the async parameter is set to true) the key is not present in the first request, but must be present in all the following requests which will be send before the generation is complete. When the synchronous request is used (the async parameter is set to false), this parameter is not required.stringrequired
tokenDefines the encrypted signature added to the Document Server config in the form of a token.stringrequired by configuration
urlDefines the absolute URL to the .docbuilder file.stringrequired

The .docbuilder file contains the script used to generate the output document file (text document, spreadsheet or presentation), specifies the output file format and name. Once the document generation is ready, the response with the absolute URL to the resulting file will be returned (see below).

Please note, that .docbuilder script file can contain several output files as a result. The URL to them all will be returned in the response to the request once the file generation is finished.

You can find more information about the .docbuilder file syntax here. Please read ONLYOFFICE Document Builder API documentation for the detailed information on what classes and methods are used to generate the documents with the help of .docbuilder files.

Sample of JSON object sent to document builder service for the first asynchronous request

  1. {
  2. "async": true,
  3. "url": "https://example.com/url-to-example-script.docbuilder"
  4. }

Where example.com is the name of the server where document storage service are installed. See the How it works section to find out more on Document Server service client-server interactions.

Response format

  1. {
  2. "key": "af86C7e71Ca8",
  3. "end": false
  4. }

Sample of JSON object sent to document builder service for the following asynchronous requests

  1. {
  2. "async": true,
  3. "key": "Khirz6zTPdfd7"
  4. }

Response format

  1. {
  2. "key": "Khirz6zTPdfd7",
  3. "urls": {
  4. "SampleText.docx": "https://documentserver/SampleText.docx",
  5. "SampleText2.docx": "https://documentserver/SampleText2.docx"
  6. },
  7. "end": true
  8. }

Sample of JSON object sent to document builder service for the synchronous request

  1. {
  2. "async": false,
  3. "url": "https://example.com/url-to-example-script.docbuilder"
  4. }

Where example.com is the name of the server where document storage service are installed. See the How it works section to find out more on Document Server service client-server interactions.

Response example

  1. {
  2. "key": "af86C7e71Ca8",
  3. "urls": {
  4. "SampleText.docx": "https://documentserver/SampleText.docx",
  5. "SampleText2.docx": "https://documentserver/SampleText2.docx"
  6. },
  7. "end": true
  8. }

Sample of JSON object contains the JSON Web Token sent to document builder service for the first asynchronous request

  1. {
  2. "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhc3luYyI6dHJ1ZSwidXJsIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS91cmwtdG8tZXhhbXBsZS1zY3JpcHQuZG9jYnVpbGRlciJ9.dzoTbRzSMa95Fpg34CjnF3ZUPdGA2CnBedFL_qOOxAs"
  3. }

Example of the response when an error occurred

  1. {
  2. "error": -8
  3. }

Possible error codes and their description

Error codeDescription
-1Unknown error.
-2Generation timeout error.
-3Document generation error.
-4Error while downloading the document file to be generated.
-6Error while accessing the document generation result database.
-8Invalid token.