1. Create classification

POST /documentClassification/createClassification

Initiates a new document classification process. This endpoint allows you to define a classification with a list of possible document types. Once created, you can use the returned classificationId to upload documents for type prediction.

Server URL

https://api.extracta.ai/api/v1

Headers

Name
Value

Content-Type

application/json

Authorization

Bearer <token>

Body

Name
Type
Required
Description

name

string

true

A name for the classification.

description

string

false

A description for the classification.

documentTypes

object

true

An array of objects, each specifying a document type.

πŸ’‘ Need help defining documentTypes?

Each item in the documentTypes array represents a document category used for classification (e.g., Invoice, Receipt). To learn how to properly define a document type β€” including required fields, keyword strategy, and optional data extraction linkage β€” refer to the Document Types page.

Body Example

{
  "classificationDetails": {
    "name": "Financial Document Classifier",
    "description": "Classifies uploaded documents into predefined financial document types.",
    "documentTypes": [
      {
        "name": "Invoice",
        "description": "Standard commercial invoice from vendors or suppliers.",
        "uniqueWords": ["invoice number", "bill to", "total amount"],
        "extractionId": "invoiceExtractionId"
      },
      {
        "name": "Purchase Order",
        "description": "Internal or external purchase order documents.",
        "uniqueWords": ["PO number", "item description", "quantity ordered"]
      },
      {
        "name": "Receipt",
        "description": "Retail or online transaction receipts.",
        "uniqueWords": ["receipt", "paid", "transaction id"]
      }
    ]
  }
}

Code Example

const axios = require('axios');

async function createClassification(token, classificationDetails) {
    const url = "https://api.extracta.ai/api/v1/documentClassification/createClassification";

    try {
        const response = await axios.post(url, {
            classificationDetails: classificationDetails
        }, {
            headers: {
                'Content-Type': 'application/json',
                'Authorization': `Bearer ${token}`
            }
        });

        return response.data;
    } catch (error) {
        throw error.response ? error.response.data : new Error('An unknown error occurred');
    }
}

async function main() {
    const token = 'apiKey';
    const classificationDetails = {
        name: "Financial Documents Classifier",
        description: "Classifies invoices, receipts, and purchase orders.",
        documentTypes: [
            {
                name: "Invoice",
                description: "Documents with billing and totals for payment.",
                uniqueWords: ["invoice number", "bill to", "total amount"],
                extractionId: "invoiceExtractionId"
            },
            {
                name: "Receipt",
                description: "Confirmation of payment or transaction.",
                uniqueWords: ["receipt", "paid", "transaction id"]
            },
            {
                name: "Purchase Order",
                description: "Authorizes a purchase transaction.",
                uniqueWords: ["PO number", "item", "quantity ordered"]
            }
        ]
    };

    try {
        const response = await createClassification(token, classificationDetails);
        console.log("New Classification Created:", response);
    } catch (error) {
        console.error("Failed to create classification:", error);
    }
}

main();

Responses

{
    "status": "created",
    "createdAt": 1712547789609,
    "classificationId": "classificationId"
}

Last updated

Was this helpful?