Documentation menu

Content Types

Request Content Types

HTTP Requests must be sent with one of the following content types:

  • application/json
  • multipart/form-data
  • application/octet-stream

application/json

File data must be encoded with Base64 encoding, provided as a URL or uploaded File ID.

DOC to PDF example

[POST]
https://v2.convertapi.com/convert/doc/to/pdf
Authorization: Bearer your_api_token
{
    "Parameters": [
        {
            "Name": "File",
            "FileValue": {
                "Name": "my_file.doc",
                "Data": "--Base64 encoded file content--"
            }
        }
    ]
}

Merge PDF scheme example (multiple source files)

[POST]
https://v2.convertapi.com/convert/pdf/to/merge
Authorization: Bearer your_api_token
{
    "Parameters": [
        {
            "Name": "StoreFile",
            "Value": "true"
        },
        {
            "Name": "PdfVersion",
            "Value": "1.7"
        },
        {
            "Name": "Files",
            "FileValues": [
                {
                    "Name": "file.pdf",
                    "Data": "--Base64 encoded file content--"
                },
                {
                    "Url": "http://example.com/myfile.docx"
                },
                {
                    "Id": "0ba132ddd698aaeafcf19ec0015e10e0"
                }
            ]
        }
    ]
}

multipart/form-data

Each request parameter must be specified in a separate part. If there is an array type parameter, the index must be appended to a parameter name e.g. Files[0], Files[1], Files[2], etc.
DOC to PDF example

[POST] 
https://v2.convertapi.com/convert/doc/to/pdf HTTP/1.1
Authorization: Bearer your_api_token
Content-Type: multipart/form-data; boundary=----7MA4YWxkTrZu0gW

------7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="StoreFile"

true
------7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="File"; filename="my_file.doc"
Content-Type: 

--FILE DATA--
------7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="DocumentTitle"

Test title
------7MA4YWxkTrZu0gW--

application/octet-stream

The most bandwidth-efficient way to convert a file is to pass file content as a request body. This content type could also be used for stream processing. The request header must contain the Content-Disposition: attachment; filename="my_file.doc" field with the file name and correct file extension. Conversion parameters can be set through the URL query.

Query parameters

It is possible to convert a file that is accessible by URL or uploaded File ID using only the query parameters. When the whole request is a URL, pass your API Token as the Token query parameter (see Authentication).

DOCX to PDF example

[GET/POST]
https://v2.convertapi.com/convert/docx/to/pdf?Token=your_api_token&File=http://example.com/myfile.docx&StoreFile=true

If there is an array type parameter, the index must be appended to parameter name e.g. Files[0], Files[1], Files[2], etc.


Response Content Types

Response headers and body contain this information:

  • ConversionCost - the number of conversions deducted from your plan for this request.
  • FileName - name of the converted file.
  • FileExt - extension of the converted file.
  • FileSize - converted file size in bytes.
  • FileData - converted file content.
  • FileUrl - link to a converted file if StoreFile parameter was set to true.

application/json

Single file result example

[response]
{
    "ConversionCost": 2,
    "Files": [
        {
            "FileName": "my_file.pdf",
            "FileExt": "pdf",
            "FileSize": 523672,
            "FileData": "--Base64 encoded file content--"
        }
    ]
}

multipart/mixed

Each part contains converted file data or URL to the file.

Single file result example

[response]
ConversionCost: 3
Content-Type: multipart/mixed; boundary="43cf1475-ab15-4c6b-b5ee-e2cbcedfe92f"

--43cf1475-ab15-4c6b-b5ee-e2cbcedfe92f
Content-Type: application/octet-stream
Content-Disposition: attachment; filename*=utf-8''my_file.pdf; size=8475

--FILE CONTENT--
                
--43cf1475-ab15-4c6b-b5ee-e2cbcedfe92f--

application/octet-stream

The response body is a result of converted file content. The filename can be found in content-disposition header field. It can be used with converters that produce a single file result.