<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: MegaConvert</title>
    <description>The latest articles on DEV Community by MegaConvert (@megaconvert).</description>
    <link>https://dev.to/megaconvert</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3907121%2Fa81be632-3133-42bb-a46c-a2e35fc9e11b.png</url>
      <title>DEV Community: MegaConvert</title>
      <link>https://dev.to/megaconvert</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/megaconvert"/>
    <language>en</language>
    <item>
      <title>How to Convert Files Programmatically with a REST API (Python, JavaScript, cURL)</title>
      <dc:creator>MegaConvert</dc:creator>
      <pubDate>Fri, 01 May 2026 07:22:45 +0000</pubDate>
      <link>https://dev.to/megaconvert/how-to-convert-files-programmatically-with-a-rest-api-python-javascript-curl-1al6</link>
      <guid>https://dev.to/megaconvert/how-to-convert-files-programmatically-with-a-rest-api-python-javascript-curl-1al6</guid>
      <description>&lt;p&gt;Tired of manually converting files? I built &lt;a href="https://megaconvert.io" rel="noopener noreferrer"&gt;MegaConvert&lt;/a&gt; — a file conversion API that handles&lt;br&gt;
  300+ format pairs: documents, images, video, audio, ebooks, fonts, and more.&lt;/p&gt;

&lt;p&gt;In this post I'll show you how to convert files programmatically in &lt;strong&gt;3 steps&lt;/strong&gt; using Python, JavaScript, or cURL.&lt;/p&gt;

&lt;p&gt;## How It Works&lt;/p&gt;

&lt;p&gt;Every conversion follows the same flow:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;POST&lt;/strong&gt; your file to &lt;code&gt;/convert&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Poll&lt;/strong&gt; &lt;code&gt;/status/{job_id}&lt;/code&gt; until it's done&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GET&lt;/strong&gt; &lt;code&gt;/download/{job_id}&lt;/code&gt; to grab the result&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Base URL: &lt;code&gt;https://megaconvert.io/api/v1&lt;/code&gt;&lt;br&gt;
  Auth: &lt;code&gt;X-API-Key&lt;/code&gt; header&lt;/p&gt;

&lt;p&gt;## cURL — Quick Test&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
bash
  # Step 1: Submit
  curl -X POST https://megaconvert.io/api/v1/convert \
    -H "X-API-Key: mc_your_key" \
    -F "file=@document.pdf" \
    -F "output_format=docx"

  # Response: {"job_id": "abc123", "status": "processing"}

  # Step 2: Check status
  curl https://megaconvert.io/api/v1/status/abc123 \
    -H "X-API-Key: mc_your_key"

  # Step 3: Download
  curl -O https://megaconvert.io/api/v1/download/abc123 \
    -H "X-API-Key: mc_your_key"

  Python Example

  import requests
  import time

  API_KEY = "mc_your_api_key_here"
  BASE = "https://megaconvert.io/api/v1"
  headers = {"X-API-Key": API_KEY}

  # Submit conversion
  with open("image.png", "rb") as f:
      r = requests.post(f"{BASE}/convert", headers=headers,
                        files={"file": f},
                        data={"output_format": "webp"})

  job_id = r.json()["job_id"]

  # Wait for completion
  while True:
      status = requests.get(f"{BASE}/status/{job_id}", headers=headers).json()["status"]
      if status == "completed":
          break
      time.sleep(2)

  # Download result
  result = requests.get(f"{BASE}/download/{job_id}", headers=headers)
  with open("image.webp", "wb") as f:
      f.write(result.content)

  JavaScript (Node.js)

  const fs = require('fs');
  const FormData = require('form-data');

  const API_KEY = 'mc_your_api_key_here';
  const BASE = 'https://megaconvert.io/api/v1';
  const headers = { 'X-API-Key': API_KEY };

  async function convertFile(inputPath, outputFormat) {
    const form = new FormData();
    form.append('file', fs.createReadStream(inputPath));
    form.append('output_format', outputFormat);

    // Submit
    const res = await fetch(`${BASE}/convert`, {
      method: 'POST',
      headers: { ...headers, ...form.getHeaders() },
      body: form
    });
    const { job_id } = await res.json();

    // Poll
    while (true) {
      const status = await fetch(`${BASE}/status/${job_id}`, { headers });
      const { status: s } = await status.json();
      if (s === 'completed') break;
      await new Promise(r =&amp;gt; setTimeout(r, 2000));
    }

    // Download
    const download = await fetch(`${BASE}/download/${job_id}`, { headers });
    const buffer = Buffer.from(await download.arrayBuffer());
    fs.writeFileSync(`output.${outputFormat}`, buffer);
  }

  convertFile('document.pdf', 'docx');

  Built-in Tools

  Beyond format conversion, the API has processing tools:

  ┌────────────────┬────────────────────────────┐
  │      Tool      │        What it does        │
  ├────────────────┼────────────────────────────┤
  │ compress-pdf   │ Reduce PDF file size       │
  ├────────────────┼────────────────────────────┤
  │ merge-pdf      │ Combine multiple PDFs      │
  ├────────────────┼────────────────────────────┤
  │ compress-image │ Optimize image size        │
  ├────────────────┼────────────────────────────┤
  │ resize-image   │ Change dimensions          │
  ├────────────────┼────────────────────────────┤
  │ compress-video │ Reduce video file size     │
  ├────────────────┼────────────────────────────┤
  │ trim-video     │ Cut video segments         │
  ├────────────────┼────────────────────────────┤
  │ video-to-gif   │ Convert video clips to GIF │
  ├────────────────┼────────────────────────────┤
  │ extract-audio  │ Pull audio from video      │
  └────────────────┴────────────────────────────┘

  # Compress a PDF
  with open("large.pdf", "rb") as f:
      r = requests.post(f"{BASE}/tool", headers=headers,
                        files={"file": f},
                        data={"tool": "compress-pdf"})

  Supported Formats

  300+ conversion pairs across:
  - Documents: PDF, DOCX, XLSX, PPTX, ODT, CSV, HTML, RTF, TXT
  - Images: JPG, PNG, WebP, HEIC, GIF, BMP, TIFF, SVG
  - Video: MP4, WebM, AVI, MOV, MKV
  - Audio: MP3, WAV, OGG, FLAC, AAC
  - Ebooks: EPUB, MOBI, AZW3
  - And more: fonts, subtitles, archives, vector/CAD

  Full list: https://megaconvert.io/docs/api

  Pricing

  API access comes with the 12-month plan at $79/year — that's 100 requests/day, which works out to $0.003 per conversion.
  Compare that to CloudConvert ($0.02+) or Zamzar ($0.08+).

  Links

  - API Docs: https://megaconvert.io/docs/api
  - GitHub (examples + docs): https://github.com/rpnet/megaconvert-api
  - Try it free: https://megaconvert.io — 3 free conversions/day, no account needed

  ---
  If you have questions or want to see a specific integration example, drop a comment below. 
https://megaconvert.io/docs/api
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>api</category>
      <category>python</category>
      <category>javascript</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
