Introduction

Welcome to the Konbert API documentation! The API provides an efficient HTTP interface for file conversion. Seamlessly convert files between various formats using our simple endpoints.

All requests are made to the following endpoint:

https://konbert.com/api/v1

Responses will always be in JSON format, unless otherwise specified.

Authentication

Head over to the account page to find your API key, you must log in or register if you don't have an account yet.

To authenticate your requests, use the Authorization header:

curl https://konbert.com/api/v1/files \
    -H "Authorization: Bearer ${API_KEY}"

Remember to replace $API_KEY with your own API key.

Converting files

Conversions are made by calling the following endpoint:

https://konbert.com/api/v1/convert

You can specify input data via three sources:

  • File upload: This option allows you to upload local files directly to the API. Suitable for large data sets or binary files, it supports various formats and ensures secure, efficient handling of your data.
  • URL: Input data can be provided via a URL. This method is ideal for processing data hosted online, allowing the API to fetch and convert data directly from a web server.
  • Inline data: For smaller data sets or quick tests, input data directly as a text string. This method is convenient for simple, text-based formats like JSON, CSV, or XML.

Curl example: Convert a CSV file to Arrow

curl -X POST https://konbert.com/api/v1/convert \
  -H "Authorization: Bearer ${API_KEY}" \
  -F "input[file]=@file.csv" \
  -F "input[format]=csv" \
  -F "input[options][delimiter]=," \
  -F "output[format]=arrow" \
  -F "sync=true"

Curl example: Convert a JSON URL to CSV

curl -X POST https://konbert.com/api/v1/convert \
  -H "Authorization: Bearer ${API_KEY}" \
  -F "input[http][url]='https://konbert.com/example.json'" \
  -F "input[format]=json" \
  -F "output[format]=csv" \
  -F "output[options][delimiter]=," \
  -F "sync=true"

Node.js example: Convert a JSON file to PostgreSQL


import fs from "fs";

const API_KEY = "<your_api_key>";
const API_ENDPOINT = "https://konbert.com/api/v1/convert";
const inputFilePath = "<input_file_path>";
const outputFilePath = "<output_file_path>";

const input = fs.createReadStream(inputFilePath);

const formData = new FormData();

formData.append("input[file]", input);
formData.append("input[format]", "json");
formData.append("input[options][flatten_objects]", "true");
formData.append("output[format]", "sql");
formData.append("output[options][create_table]", "true");
formData.append("output[options][syntax]", "postgres");
formData.append("output[options][table_name]", "mytable");
formData.append("sync", "true");

try {
  const response = await fetch(API_ENDPOINT, {
    method: "POST",
    headers: {
      Authorization: `Bearer ${API_KEY}`,
    },
    body: formData,
  });

  if (!response.ok) {
    throw new Error("Failed to convert file");
  }

  const arrayBuffer = await response.arrayBuffer();
  const buffer = Buffer.from(arrayBuffer);

  fs.writeFileSync(outputFilePath, buffer);
  console.log("File converted successfully");
} catch (error) {
  console.error("Error:", error);
}

PHP example: Convert an Avro file to CSV


<?php

$api_key = "YOUR_API_KEY";
$api_endpoint = "https://konbert.com/api/v1/convert";
$input_file_path = "input.avro";
$output_file_path = "output.csv";

$postfields = [
    "input[file]" => new CURLFile($input_file_path),
    "input[format]" => "avro",
    "output[format]" => "csv",
    "sync" => "true"
];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_endpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "Authorization: Bearer " . $api_key
]);

$response = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

if ($httpcode != 200) {
    echo "Error: Failed to convert file\n";
    echo "Response: $response\n";
    exit;
}

if(curl_errno($ch)){
    echo "Request Error:" . curl_error($ch);
    exit;
}

file_put_contents($output_file_path, $response);
echo "File converted successfully\n";

curl_close($ch);

Input formats

IDOptions
csv
delimiter: ",""\t"";""|"
has_headers: boolean
encoding: null"UTF-8""UTF-16LE""UTF-16BE""windows-1252""ISO-8859-1"
excel
format: "xlsx""xls""ods"
sheet_name: string
json
flatten_objects: boolean
ndjson
flatten_objects: boolean
mode:
jsonl
flatten_objects: boolean
mode:
xls
format:
sheet_name: string
xlsx
format:
sheet_name: string
ods
format:
sheet_name: string
tsv
delimiter:
has_headers: boolean
encoding: null"UTF-8""UTF-16LE""UTF-16BE""windows-1252""ISO-8859-1"
txt
delimiter: ",""\t"";""|"
has_headers: boolean
encoding: null"UTF-8""UTF-16LE""UTF-16BE""windows-1252""ISO-8859-1"

Output formats

IDOptions
csv
delimiter: ","";""\t""|"
json
mode: "normal""ndjson""pretty"
ndjson
mode:
jsonl
mode:
tsv
delimiter:
avro
only_schema: boolean
avro-schema
only_schema:
sql
syntax: "postgres""mysql""sqlite"
table_name: string
create_table: boolean
sqlite
syntax:
table_name: string
create_table: boolean
mysql
syntax:
table_name: string
create_table: boolean
postgres
syntax:
table_name: string
create_table: boolean
markdown
header: boolean
pdf
page_size: "A4""Letter""Legal"
orientation: "Portrait""Landscape"
margin:
txt
delimiter: ","";""\t""|"