Convert .docx via REST API

Available in Start planBeta

The DOCX document conversion API supports conversion from and to Tiptap’s JSON format.

Review the postman collection

You can also experiment with the Document Conversion API by heading over to our Postman Collection.

Import DOCX

POST /v2/convert/import

The /v2/convert/import endpoint converts docx files into Tiptap’s JSON format. Users can POST documents to this endpoint and use various parameters to customize how different document elements are handled during the conversion process.

Example (cURL)

curl -X POST "https://api.tiptap.dev/v2/convert/import" \
    -H "Authorization: Bearer YOUR_TOKEN" \
    -H "X-App-Id: YOUR_APP_ID" \
    -F "file=@/path/to/your/file.docx" \
    -F "imageUploadCallbackUrl=https://your-image-upload-endpoint.com" \
    -F "promisemirrorNodes={\"nodeKey\":\"nodeValue\"}" \
    -F "prosemirrorMarks={\"markKey\":\"markValue\"}"

Subscription required

This endpoint requires a valid Tiptap subscription. For more details review our pricing page.

Required headers

NameDescription
AuthorizationThe JWT token to authenticate the request. Example: Bearer your-jwt-token
X-App-IdThe Convert App-ID from the Collaboration settings page: https://cloud.tiptap.dev/convert-settings

Body

NameTypeDescription
fileFileThe file to convert
imageUploadCallbackUrlstringThe callback endpoint to upload images that were encountered within the uploaded document, see more info
prosemirrorNodesObject stringCustom node mapping for the conversion, see more info.
prosemirrorMarksObject stringCustom mark mapping for the conversion, see more info
verbosestring | numberA configuration property to help you control the level of diagnostic output during the import process. This is especially useful for debugging or for getting more insight into what happens during conversion. See more at Verbose output

Import verbose output

The DOCX import extension provides a verbose configuration property to help you control the level of diagnostic output during the import process. This is especially useful for debugging or for getting more insight into what happens during conversion.

The verbose property is a bitmask number that determines which types of log messages are emitted. The extension uses the following levels:

ValueLevelDescription
1logGeneral informational logs
2warnWarnings
4errorErrors

Verbose bitmask

You can combine levels by adding their values together. For example, verbose: 3 will enable both log (1) and warn (2) messages.

The verbose output will give you, along the data property, one more property called logs, which will contain info, warn, and error properties, each of them being an array with all of the information related to that specific verbosity.

{
  "data": {
    "content": {
        // Tiptap JSON
    }
  },
  "logs": {
    "info": [],
    "warn": [
      {
        "message": "Image file not found in media files",
        "fileName": "image1.gif",
        "availableMediaFiles": []
      }
    ],
    "error": [
      {
        "message": "Image upload failed: General error",
        "fileName": "image1.gif",
        "url": "https://your-image-upload-endpoint.com",
        "error": "Unable to connect. Is the computer able to access the url?",
        "context": "uploadImage general error"
      }
    ]
  }
}

Custom node and mark mapping

You can override the default node/mark types used during import by specifying them in the body of your request within prosemirrorNodes and prosemirrorMarks respectively. You would need to provide these if your editor uses custom nodes/marks and you want the imported JSON to use those.

For example, if your schema uses a custom node type called textBlock instead of the default paragraph, you can include "{\"paragraph\":\"textBlock\"}" in the request body.

You can similarly adjust headings, lists, marks like bold or italic, and more.

Default nodes

NameDescription
paragraphDefines which prosemirror type is used for paragraph conversion
headingDefines which prosemirror type is used for heading conversion
blockquoteDefines which prosemirror type is used for blockquote conversion
codeblockDefines which prosemirror type is used for codeblock conversion
bulletlistDefines which prosemirror type is used for bulletList conversion
orderedlistDefines which prosemirror type is used for orderedList conversion
listitemDefines which prosemirror type is used for listItem conversion
hardbreakDefines which prosemirror type is used for hardbreak conversion
horizontalruleDefines which prosemirror type is used for horizontalRule conversion
tableDefines which prosemirror type is used for table conversion
tablecellDefines which prosemirror type is used for tableCell conversion
tableheaderDefines which prosemirror type is used for tableHeader conversion
tablerowDefines which prosemirror type is used for tableRow conversion
imageDefines which prosemirror mark is used for image conversion

Default marks

NameDescription
boldDefines which prosemirror mark is used for bold conversion
italicDefines which prosemirror mark is used for italic conversion
underlineDefines which prosemirror mark is used for underline conversion
strikethroughDefines which prosemirror mark is used for strikethrough conversion
linkDefines which prosemirror mark is used for link conversion
codeDefines which prosemirror mark is used for code conversion

Export DOCX

POST /v2/convert/export

The /v2/convert/export endpoint converts Tiptap documents into DOCX format. Users can POST documents to this endpoint and use various parameters to customize how different document elements are handled during the conversion process.

Export customization support

The /v2/convert/export endpoint does not support custom node conversions as functions cannot be serialized, but it does support custom style overrides. If you wish to convert your documents on the server on your own premises to have this option available, you can follow the server side export guide.

Example (cURL)

curl --output example.docx -X POST https://api.tiptap.dev/v2/convert/export \
    -H "Authorization: Bearer <your-jwt-token>" \
    -H "X-App-Id: <your-app-id>" \
    -F 'doc={"type":"doc","content":[{"type":"paragraph","attrs":{"textAlign":"left"},"content":[{"type":"text","text":"Welcome to this demonstration of our editor'\''s ability to export a wide array of formatting options to DOCX, ensuring that your content retains its intended appearance in Word."}]}]}' \
    -F 'exportType=blob'

Subscription required

This endpoint requires a valid Tiptap subscription. For more details review our pricing page.

Required headers

NameDescription
AuthorizationThe JWT token to authenticate the request. Example: Bearer your-jwt-token
X-App-IdThe Convert App-ID from the Collaboration settings page: https://cloud.tiptap.dev/convert-settings

Body

NameTypeDescriptionDefault
docStringTiptap's JSONN/A
exportTypestringThe expected export typeblob
styleOverridesObjectStyle overrides{}
pageSizeObjectPage size configurationundefined
pageMarginsObjectPage margins configurationundefined
headersObjectPage header configurationundefined
footersObjectPage footer configurationundefined

Page Size Configuration

The pageSize object allows you to customize the dimensions of your exported DOCX document:

PropertyTypeDescriptionDefault
widthstringThe width of the page. Must be a positive number followed by a valid unit (cm, in, pt, pc, mm, px)."21.0cm"
heightstringThe height of the page. Must be a positive number followed by a valid unit (cm, in, pt, pc, mm, px)."29.7cm"

Example cURL with custom page size:

curl --output example.docx -X POST https://api.tiptap.dev/v2/convert/export \
    -H "Authorization: Bearer <your-jwt-token>" \
    -H "X-App-Id: <your-app-id>" \
    -F 'doc={"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"Document with custom page size"}]}]}' \
    -F 'exportType=blob' \
    -F 'pageSize={"width":"21.0cm","height":"29.7cm"}'

Page Margins Configuration

The pageMargins object allows you to customize the margins of your exported DOCX document:

PropertyTypeDescriptionDefault
topstringThe top margin of the page. Can be negative. Must be a number followed by a valid unit (cm, in, pt, pc, mm, px)."1.0cm"
bottomstringThe bottom margin of the page. Can be negative. Must be a number followed by a valid unit (cm, in, pt, pc, mm, px)."1.0cm"
leftstringThe left margin of the page. Must be a positive number followed by a valid unit (cm, in, pt, pc, mm, px)."1.0cm"
rightstringThe right margin of the page. Must be a positive number followed by a valid unit (cm, in, pt, pc, mm, px)."1.0cm"

Example cURL with custom page margins:

curl --output example.docx -X POST https://api.tiptap.dev/v2/convert/export \
    -H "Authorization: Bearer <your-jwt-token>" \
    -H "X-App-Id: <your-app-id>" \
    -F 'doc={"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"Document with custom margins"}]}]}' \
    -F 'exportType=blob' \
    -F 'pageMargins={"top":"2.0cm","bottom":"2.0cm","left":"1.5cm","right":"1.5cm"}'

Headers and footers

The headers and footers objects allows you to configure a set of headers and footers options for your exported DOCX.

Team License Requirement

In order to be able to use the headers and footers within the REST API you must have a Team license.

Headers Configuration

The headers object allows you to customize the headers of your exported DOCX document:

PropertyTypeDescription
evenAndOddHeadersbooleanWhether to use different headers for odd and even pages
defaultstringThe standard default header on every page, or header on odd pages when the evenAndOddHeaders option is activated.
firststringThe header on the first page when the 'Different First Page' option is activated.
evenstringThe header on even pages when the evenAndOddHeaders option is activated.

Limitations

Since API calls cannot properly serialize very complex objects or functions, the headers configuration is limited to plain strings that we then will convert for you, without any styling, to a standard DOCX heading.

Example cURL with custom headers:

curl --output example.docx -X POST https://api.tiptap.dev/v2/convert/export \
    -H "Authorization: Bearer <your-jwt-token>" \
    -H "X-App-Id: <your-app-id>" \
    -F 'doc={"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"Document with custom headers"}]}]}' \
    -F 'exportType=blob' \
    -F 'headers={"evenAndOddHeaders":true,"default":"Default Header","first":"First Page Header","even":"Even Page Header"}'

Footers Configuration

The footers object allows you to customize the footers of your exported DOCX document:

PropertyTypeDescription
evenAndOddFootersbooleanWhether to use different footers for odd and even pages
defaultstringThe standard default footer on every page, or footer on odd pages when the evenAndOddFooters option is activated.
firststringThe footer on the first page when the 'Different First Page' option is activated.
evenstringThe footer on even pages when the evenAndOddFooters option is activated.

Limitations

Since API calls cannot properly serialize very complex objects or functions, the footers configuration is limited to plain strings that we then will convert for you, without any styling, to a standard DOCX footer.

Example cURL with custom footers:

curl --output example.docx -X POST https://api.tiptap.dev/v2/convert/export \
    -H "Authorization: Bearer <your-jwt-token>" \
    -H "X-App-Id: <your-app-id>" \
    -F 'doc={"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"Document with custom footers"}]}]}' \
    -F 'exportType=blob' \
    -F 'footers={"evenAndOddFooters":true,"default":"Default Footer","first":"First Page Footer","even":"Even Page Footer"}'