Skip to content
dhanu docs
Browse pages

API reference

Export a file

GET /api/pub/v1/files/{fileId}/export?format=, a page as HTML, a sheet as CSV or XLSX, a deck as PDF or PPTX.

GEThttps://api.dhanu.ai/api/pub/v1/files/{fileId}/export

Exports an artifact in a portable format. Which formats fit depends on the kind:

KindFormatsNotes
pagehtmlThe single self-contained HTML document, as it is served in the app.
sheetcsv, xlsxcsv exports the first tab; xlsx keeps every tab and its formulas.
deckpptx, pdfpdf needs a render first, see below.

A deck’s PDF is rendered by a background job, so the first pdf export of a deck answers export_not_rendered: call render a file, wait for the job, then export. Every other pairing is produced on the spot. A format the kind does not support answers unsupported_export_format.

Request

curl -OJ "https://api.dhanu.ai/api/pub/v1/files/$FILE_ID/export?format=xlsx" \
  -H "Authorization: Bearer $DHANU_API_KEY"
const workbook = await dhanu.files.export(fileId, "xlsx");
await fs.writeFile(workbook.filename ?? "export.xlsx", workbook.bytes);
workbook = dhanu.files.export(file_id, "xlsx")
with open(workbook.filename or "export.xlsx", "wb") as fh:
    fh.write(workbook.bytes)

Response

200 OK

The exported document, with the format’s Content-Type and a Content-Disposition filename.

Errors

CodeStatusMeaning
invalid_api_key401The bearer key is missing or unknown.
api_key_revoked401The key was revoked.
api_key_expired401The key passed its expiry date.
api_key_ip_not_allowed403The caller's IP is outside the key's allowlist.
developer_access_revoked403The key's creator lost developer access in the workspace.
api_key_project_scope403The key covers no active projects, or projectId is outside its scope.
not_found404No such resource in the key's workspace.
invalid_request_body422The body did not match the schema; error.issues names each field.
unsupported_export_format422That file kind cannot be exported in the requested format.
export_not_rendered409The deck's PDF has not been rendered yet.