API

GitHubEdit on GitHub

This page lists common Univer Server APIs. The default base URL is http://localhost:8000.

Note: type parameter values: 1 for Docs, 2 for Sheets.

Document Management

Create Document

POST/universer-api/snapshot/{type}/unit/-/create
Headers
content-type: application/json
Body Parameters
ParameterTypeExampleDescription
type*enum(int)-1 (docs), 2 (sheets) for path and body
name*string-Document name
creator*string-Creator id
curl http://localhost:8000/universer-api/snapshot/{type}/unit/-/create \  -X POST \  -H 'Content-Type: application/json' \  --data-raw '{"type":2,"name":"New Sheet By Univer","creator":"userID"}'
Response
application/json
ParameterTypeExampleDescription
errorobject--
codeenum(int)-1 (success)
messagestring-Error message
unitIDstring-Document id
{  "error": {    "code": 1,    "message": "success"  },  "unitID": "ETVf-B4lQqOSE_p09mcp9Q"}

List Documents

GET/universer-api/snapshot/{type}/units
Headers
Query Parameters
ParameterTypeExampleDescription
type*enum(int)-1 (doc), 2 (sheet) for path and body
nextCursorstring-Next page cursor
curl -X GET 'http://localhost:8000/universer-api/snapshot/1/units?nextCursor=100'
Response
application/json
ParameterTypeExampleDescription
errorobject--
codeenum(int)-1 (success)
messagestring-Error message
unitsarray[object]-Document list
unitIDstring-Document id
namestring-Document name
typeenum(int)-1 (doc), 2 (sheet)
nextCursorstring-Next page cursor; empty means last page
{  "error": {    "code": 1,    "message": ""  },  "units": [    {      "unitID": "1",      "name": "a",      "type": 1    }  ],  "nextCursor": "200"}

Delete Documents

DELETE/universer-api/snapshot/-/units
Headers
content-type: application/json
Query Parameters
ParameterTypeExampleDescription
unitIds*array[string]-Document id list
curl -X DELETE 'http://localhost:8000/universer-api/snapshot/-/units?unitIds=1&unitIds=2'
Response
application/json
ParameterTypeExampleDescription
errorobject--
codeenum(int)-1 (success)
messagestring-Error message
{  "error": {    "code": 1,    "message": ""  }}

Files and Import/Export

Upload File

POST/universer-api/stream/file/upload
Headers
content-type: multipart/form-data
Body Parameters
ParameterTypeExampleDescription
size*int-File size in bytes (query param). Must match actual size.
file*Form.file-File in HTML form
curl 'http://localhost:8000/universer-api/stream/file/upload?size=125466' \  --header 'cookie: _univer=XXXXXX' \  --form 'file=@"demo.xlsx"'
Response
application/json
ParameterTypeExampleDescription
FileIdstring-File id for import/export
{  "FileId": "xxxx"}

Import

POST/universer-api/exchange/{type}/import
Headers
content-type: application/json
Body Parameters
ParameterTypeExampleDescription
type*enum(int)-1 (doc), 2 (sheet)
outputType*enum(int)-1 (unit), 2 (json)
fileID*string-Uploaded file id
minSheetRowCount*int-Minimum rows; import validates row count
minSheetColumnCount*int-Minimum columns; import validates column count
curl -X POST 'http://localhost:8000/universer-api/exchange/2/import' \  -H 'Content-Type: application/json' \  --data-raw '{"fileID":"123","outputType":1,"minSheetRowCount":1000,"minSheetColumnCount":20}'
Response
application/json
ParameterTypeExampleDescription
errorobject--
codeenum(int)-1 (success)
messagestring-Error message
taskIDstring-Task id for polling
{  "error": {    "code": 1,    "message": ""  },  "taskID": "456"}

Export

POST/universer-api/exchange/{type}/export
Headers
content-type: application/json
Body Parameters
ParameterTypeExampleDescription
type*enum(int)-1 (doc), 2 (sheet)
unitID*string-Document id
sscSwitchboolean-Enable SSC (server-side calculation); default false
curl -X POST 'http://localhost:8000/universer-api/exchange/2/export' \  -H 'Content-Type: application/json' \  --data-raw '{"unitID":"xxxx","type":2}'
Response
application/json
ParameterTypeExampleDescription
errorobject--
codeenum(int)-1 (success)
messagestring-Error message
taskIDstring-Task id for polling
{  "error": {    "code": 1,    "message": ""  },  "taskID": "456"}

Get Task Result

GET/universer-api/exchange/task/{taskID}
Headers
Path Parameters
ParameterTypeExampleDescription
taskID*string-Task id
curl -X GET 'http://localhost:8000/universer-api/exchange/task/123'
Response
application/json
ParameterTypeExampleDescription
errorobject--
codeenum(int)-1 (success)
messagestring-Error message
statusenum(string)-"pending", "done", "failed"
exportobject--
fileIDstring-Exported file id
importobject--
unitIDstring-Imported unitID
jsonIDstring-JSON file id
{  "error": {    "code": 1,    "message": ""  },  "status": "done",  "export": {    "fileID": "456"  },  "import": {    "unitID": "789",    "jsonID": "012"  }}

Get File

GET/universer-api/file/{fileID}/sign-url
Headers
Path Parameters
ParameterTypeExampleDescription
fileID*string-Result file id
curl -X GET 'http://localhost:8000/universer-api/file/1234/sign-url'
Response
application/json
ParameterTypeExampleDescription
errorobject--
codeenum(int)-1 (success)
messagestring-Error message
urlstring-Download URL
{  "error": {    "code": 1,    "message": ""  },  "url": "https://example.com/path/to/file.xlsx"}

How is this guide?