Skip to main content
POST
/
v1
/
documents
/
export
Export the current document as a styled .docx (default), .pdf, .html, .md, or .txt file with full fidelity.
curl --request POST \
  --url https://api.example.com/v1/documents/export \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "session_id": "<string>",
  "html": "<string>",
  "format": "docx",
  "options": {
    "paper_size": "Letter",
    "orientation": "portrait",
    "margins": "normal",
    "custom_margins_inches": {},
    "filename": "<string>",
    "embed_images": false,
    "watermark_text": "<string>",
    "watermark_opacity": 0.3
  },
  "filename": "<string>",
  "upload_id": "<string>"
}
'
import requests

url = "https://api.example.com/v1/documents/export"

payload = {
    "session_id": "<string>",
    "html": "<string>",
    "format": "docx",
    "options": {
        "paper_size": "Letter",
        "orientation": "portrait",
        "margins": "normal",
        "custom_margins_inches": {},
        "filename": "<string>",
        "embed_images": False,
        "watermark_text": "<string>",
        "watermark_opacity": 0.3
    },
    "filename": "<string>",
    "upload_id": "<string>"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: JSON.stringify({
    session_id: '<string>',
    html: '<string>',
    format: 'docx',
    options: {
      paper_size: 'Letter',
      orientation: 'portrait',
      margins: 'normal',
      custom_margins_inches: {},
      filename: '<string>',
      embed_images: false,
      watermark_text: '<string>',
      watermark_opacity: 0.3
    },
    filename: '<string>',
    upload_id: '<string>'
  })
};

fetch('https://api.example.com/v1/documents/export', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://api.example.com/v1/documents/export",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => json_encode([
    'session_id' => '<string>',
    'html' => '<string>',
    'format' => 'docx',
    'options' => [
        'paper_size' => 'Letter',
        'orientation' => 'portrait',
        'margins' => 'normal',
        'custom_margins_inches' => [
                
        ],
        'filename' => '<string>',
        'embed_images' => false,
        'watermark_text' => '<string>',
        'watermark_opacity' => 0.3
    ],
    'filename' => '<string>',
    'upload_id' => '<string>'
  ]),
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer <token>",
    "Content-Type: application/json"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.example.com/v1/documents/export"

	payload := strings.NewReader("{\n  \"session_id\": \"<string>\",\n  \"html\": \"<string>\",\n  \"format\": \"docx\",\n  \"options\": {\n    \"paper_size\": \"Letter\",\n    \"orientation\": \"portrait\",\n    \"margins\": \"normal\",\n    \"custom_margins_inches\": {},\n    \"filename\": \"<string>\",\n    \"embed_images\": false,\n    \"watermark_text\": \"<string>\",\n    \"watermark_opacity\": 0.3\n  },\n  \"filename\": \"<string>\",\n  \"upload_id\": \"<string>\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://api.example.com/v1/documents/export")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"session_id\": \"<string>\",\n  \"html\": \"<string>\",\n  \"format\": \"docx\",\n  \"options\": {\n    \"paper_size\": \"Letter\",\n    \"orientation\": \"portrait\",\n    \"margins\": \"normal\",\n    \"custom_margins_inches\": {},\n    \"filename\": \"<string>\",\n    \"embed_images\": false,\n    \"watermark_text\": \"<string>\",\n    \"watermark_opacity\": 0.3\n  },\n  \"filename\": \"<string>\",\n  \"upload_id\": \"<string>\"\n}")
  .asString();
require 'uri'
require 'net/http'

url = URI("https://api.example.com/v1/documents/export")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"session_id\": \"<string>\",\n  \"html\": \"<string>\",\n  \"format\": \"docx\",\n  \"options\": {\n    \"paper_size\": \"Letter\",\n    \"orientation\": \"portrait\",\n    \"margins\": \"normal\",\n    \"custom_margins_inches\": {},\n    \"filename\": \"<string>\",\n    \"embed_images\": false,\n    \"watermark_text\": \"<string>\",\n    \"watermark_opacity\": 0.3\n  },\n  \"filename\": \"<string>\",\n  \"upload_id\": \"<string>\"\n}"

response = http.request(request)
puts response.read_body
{
  "detail": [
    {
      "loc": [
        "<string>"
      ],
      "msg": "<string>",
      "type": "<string>"
    }
  ]
}

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Headers

authorization
string | null

Body

application/json

Unified request body for POST /v1/documents/export.

Backward-compat notes:

  • Top-level filename is retained for legacy clients that sent only { html } and relied on the filename being auto-extracted from the first

    . New clients should use options.filename — options.filename wins when both are set.

  • format defaults to "docx". Legacy callers passing format="doc" explicitly keep working during a short back-compat window.
session_id
string | null

Session ID to export from (the document is taken from the session). Required if html is omitted.

Maximum string length: 256
html
string | null

HTML content to export inline. Used instead of the session document if provided.

Maximum string length: 200000000
format
enum<string>
default:docx

Export format. One of docx (default), pdf, html, markdown, txt.

Available options:
docx,
pdf,
html,
markdown,
txt,
doc
options
ExportOptions · object

Customization (paper, margins, filename, watermark, etc.).

filename
string | null

DEPRECATED. Use options.filename. Top-level kept for legacy callers.

Maximum string length: 255
upload_id
string | null

ID returned by /v1/uploads (large-document upload flow, for payloads above ~25 MB). When set, the route fetches the HTML body from the uploaded payload instead of using the html field.

Maximum string length: 64

Response

Successful Response