Extracta.ai
DashboardJoin Discord
  • extracta.ai
    • Introduction
    • Overview
  • API Reference
    • 🔓Authentication
    • 📁Supported File Types
  • Data Extraction - API
    • đŸ’ģAPI Endpoints - Data Extraction
      • 1. Create extraction
      • 2. View extraction
      • 3. Update extraction
      • 4. Delete extraction
      • 5. Upload Files
      • 6. Get results
    • Extraction Details
      • 🌎Supported Languages
      • âš™ī¸Options
      • 📋Fields
    • Receiving Batch Results
      • Polling vs Webhook
      • How to use the Webhook
    • đŸ•šī¸Postman Integration
  • Document Classification - API
    • đŸ’ģAPI Endpoints - Document Classification
      • 1. Create classification
      • 2. View classification
      • 3. Update classification
      • 4. Delete data
        • 4.1 Delete classification
        • 4.2 Delete batch
        • 4.3 Delete files
      • 5. Upload Files
      • 6. Get results
    • Classification Details
      • 📄Document Types
  • Documents
    • Custom Document
    • Resume / CV
    • Contract
    • Business Card
    • Email
    • Invoice
    • Receipt
    • Bank Statement
  • Support
    • 💁Tutorials
    • đŸŸĸAPI Status
  • Contact
    • 📧Contact Us
    • ❓FAQ
Powered by GitBook
On this page
  • Server URL
  • Headers
  • Body
  • Body Example
  • Code Example
  • Responses

Was this helpful?

  1. Document Classification - API
  2. API Endpoints - Document Classification

3. Update classification

PATCH /documentClassification/updateClassification

Updates an existing document classification process by modifying specific parameters within the classification details. This endpoint is useful for adjusting document types, keywords, or metadata without recreating the entire classification setup.

Server URL

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

Headers

Name
Value

Content-Type

application/json

Authorization

Bearer <token>

Body

Name
Type
Required
Description

classificationId

string

true

Unique identifier for the classification.

name

string

true

A name for the classification.

description

string

true

A description for the classification.

documentTypes

list<object>

true

An array of objects, each specifying a document type.

Body Example

{
    "classificationId": "classificationId",
    "classificationDetails": {
        "name": "Financial Document Classifier - updated",
        "description": "Classifies uploaded documents into predefined financial document types. - updated",
        "documentTypes": [
            {
                "name": "Invoice",
                "description": "Standard commercial invoice from vendors or suppliers.",
                "uniqueWords": [
                    "invoice number",
                    "bill to",
                    "total amount"
                ],
                "extractionId": "-OPXR1F82I0cRYJPcHNo"
            }
        ]
    }
}

Code Example

const axios = require('axios');

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

    try {
        const response = await axios.patch(url, {
            classificationId,
            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 classificationId = 'classificationId';
    const classificationDetails = {
        "name": "Financial Document Classifier - updated",
        "description": "Classifies uploaded documents into predefined financial document types. - updated",
        "documentTypes": [
            {
                "name": "Invoice",
                "description": "Standard commercial invoice from vendors or suppliers.",
                "uniqueWords": [
                    "invoice number",
                    "bill to",
                    "total amount"
                ],
                "extractionId": "-OPXR1F82I0cRYJPcHNo"
            }
        ]
    };

    try {
        const response = await updateClassification(token, classificationId, classificationDetails);
        console.log("Classification Updated:", response);
    } catch (error) {
        console.error("Failed to update classification:", error);
    }
}

main();
import requests

def update_classification(token, classification_id, classification_details):
    url = "https://api.extracta.ai/api/v1/documentClassification/updateClassification"
    headers = {"Content-Type": "application/json", "Authorization": f"Bearer {token}"}
    payload = {
        "classificationId": classification_id,
        "classificationDetails": classification_details
    }

    try:
        response = requests.patch(url, json=payload, headers=headers)
        response.raise_for_status()
        return response.json()
    except requests.RequestException as e:
        print(f"Failed to update classification: {e}")
        return None

# Example usage
if __name__ == "__main__":
    token = "apiKey"
    classification_id = "classificationId"
    classification_details = {
        "name": "Financial Document Classifier - updated",
        "description": "Classifies uploaded documents into predefined financial document types. - updated",
        "documentTypes": [
            {
                "name": "Invoice",
                "description": "Standard commercial invoice from vendors or suppliers.",
                "uniqueWords": [
                    "invoice number",
                    "bill to",
                    "total amount"
                ],
                "extractionId": "-OPXR1F82I0cRYJPcHNo"
            }
        ]
    }

    response = update_classification(token, classification_id, classification_details)
    print("Classification Updated:", response)
<?php

function updateClassification($token, $classificationId, $classificationDetails) {
    $url = 'https://api.extracta.ai/api/v1/documentClassification/updateClassification';

    // Initialize cURL session
    $ch = curl_init($url);

    // Prepare the payload with classificationId and classificationDetails
    $payload = json_encode([
        'classificationId' => $classificationId,
        'classificationDetails' => $classificationDetails
    ]);

    // Set cURL options
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
    curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        'Content-Type: application/json',
        'Authorization: Bearer ' . $token,
    ]);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    try {
        // Execute cURL session
        $response = curl_exec($ch);

        // Check for cURL errors
        if (curl_errno($ch)) {
            throw new Exception('Curl error: ' . curl_error($ch));
        }

        return $response;
    } catch (Exception $e) {
        return 'Error: ' . $e->getMessage();
    } finally {
        curl_close($ch);
    }
}

// Example usage
$token = 'apiKey';
$classificationId = 'classificationId';
$classificationDetails = [
    "name" => "Updated Financial Classifier",
    "description" => "Updated description for the financial document classifier.",
    "documentTypes" => [
        [
            "name" => "Invoice",
            "description" => "Updated invoice description.",
            "uniqueWords" => ["invoice number", "billing address"],
            "extractionId" => "updatedExtract123"
        ],
        [
            "name" => "Receipt",
            "description" => "Retail receipts for in-store purchases.",
            "uniqueWords" => ["store id", "cashier", "receipt total"]
        ]
    ]
];

try {
    $response = updateClassification($token, $classificationId, $classificationDetails);
    echo $response;
} catch (Exception $e) {
    echo "Failed to update classification: " . $e->getMessage();
}

?>

Responses

{
    "status": "updated",
    "updatedAt": 1746720927500,
    "classificationId": "-OPkce8E1CuEQeHDZetx"
}
{
    "status": "error",
    "message": "Classification does not exist",
    "classificationId": "-OPkce8E1CuEQeHDZetxs"
}
{
    "status": "error",
    "message": "Error updating classification"
}
Previous2. View classificationNext4. Delete data

Last updated 16 hours ago

Was this helpful?

đŸ’ģ