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.pdfHandling 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 conversion (JSON to CSV)
#!/usr/bin/env bash
# Resilient conversion: retry on 429, surface 402/413/422
for attempt in 1 2 3; do
code=$(curl -sS -D headers.txt -o response.json -w "%{http_code}" \
-X POST https://api.fileswitch.co/api/v1/converter/json-to-csv \
-H "Authorization: Bearer fc_YOUR_API_KEY" \
-F "file=@data.json" \
-F "delimiter=;")
case "$code" in
429)
retry_after=$(grep -i '^Retry-After:' headers.txt | tail -1 | tr -dc '0-9')
sleep "${retry_after:-5}"
;;
402|413|422)
# insufficient credits / file too large / unsupported input
echo "Request rejected (HTTP $code) - not retrying"
exit 1
;;
esac
done
echo "Conversion failed after 3 attempts"