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"
}
Last updated
Was this helpful?