SDKs & Code Examples

Convert a file and download the result in the language of your choice.

Convert & download

The examples below show a full convert-and-download flow. Use the tabs on any code block to switch between languages. Every conversion endpoint accepts the same request pattern.

Convert & download (HTML to PDF)
# 1. Convert with options
curl -X POST https://api.fileswitch.co/api/v1/converter/html-to-pdf \
  -H "Authorization: Bearer fc_YOUR_API_KEY" \
  -F "file=@report.html" \
  -F "pageSize=A4" \
  -F "headerText=Quarterly Report" \
  -F "footerText=Confidential" > response.json

# 2. Download the converted file using the returned downloadUrl
URL=$(node -e "console.log(JSON.parse(require('fs').readFileSync('response.json')).data.downloadUrl)")
curl https://api.fileswitch.co$URL -H "Authorization: Bearer fc_YOUR_API_KEY" \
  --output report.pdf

Handling errors & rate limits

A resilient integration retries on HTTP 429, surfaces HTTP 402 (insufficient credits), and ignores HTTP 413 (file too large) and HTTP 422 (unsupported input):

Resilient conversionpython
import time, requests

headers = {"Authorization": "Bearer fc_YOUR_API_KEY"}

for attempt in range(3):
    res = requests.post(
        "https://api.fileswitch.co/api/v1/converter/json-to-csv",
        headers=headers,
        files={"file": open("data.json", "rb")},
        data={"delimiter": ";"},
    )
    if res.status_code == 429:
        retry_after = int(res.headers.get("Retry-After", 5))
        time.sleep(retry_after)
        continue
    res.raise_for_status()
    break

# 402 -> insufficient credits, 413 -> file too large, 422 -> unsupported input for this endpoint