/extract/segments/from-file

Base URL
https://api.babylon.app/v1


POST /extract/segments/from-file

Extracts one or segment entries from a file of type CSV, Excel or PDF.

Parameters

  • segmentLedger (optional) — The name of the Babylon segment.
  • accountAlias (optional) — The account alias.
  • fileName — The name of the file.
  • mimeType — The MIME type of the file, expected and supported types are application/pdf, text/csv, application/csv, application/vnd.ms-excel and application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
  • fileBase64 — The complete contents of the file encoded as a base64 string.
  • format (optional) — Use csv for CSV output, otherwise JSON.
  • columns (optional) — Comma-separated list to select and order fields in the response.

Example
Examples are hard to express, specifically for fileBase64 field value. So we have focused on examples to create the fileBase64 value.

Python

import base64
import json
import requests

API_URL = "https://api.babylon.app/v1/extract/segments/from-file"
FILE_PATH = "contract_note.pdf"

# 1. Read the file as raw bytes
with open(FILE_PATH, "rb") as f:
    file_bytes = f.read()

# 2. Encode as Base64 (no prefix)
file_base64 = base64.b64encode(file_bytes).decode("utf-8")

# 3. Build the JSON payload
payload = {
    "fileName": "contract_note.pdf",
    "mimeType": "application/pdf",
    "fileBase64": file_base64,
}

# 4. Send the POST request
response = requests.post(
    API_URL,
    headers={"Content-Type": "application/json"},
    data=json.dumps(payload),
)

print("Status code:", response.status_code)
print("Response body:", response.text)

React/Javascript

/**
 * Convert a File into a pure Base64 string.
 */
async function fileToBase64(file) {
  const arrayBuffer = await file.arrayBuffer();
  return Buffer.from(arrayBuffer).toString("base64");
}

/**
 * Build and send the JSON payload to the endpoint.
 */
async function handleSubmit(file) {
  if (!file) {
    throw new Error("No file provided");
  }

  // Convert file to Base64
  const fileBase64 = await fileToBase64(file);

  // Construct payload
  const payload = {
    fileName: file.name,
    mimeType: file.type, 
    fileBase64
  };

  // Example POST call
  const response = await fetch("https://api.babylon.app/v1/extract/segments/from-file", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify(payload)
  });

  return response.json();
}

There is no corresponding GET method.

← Back to API